Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete the following programming with clear explanations. Thanks! Homework 1 Programming with Java: What This Assignment Is About? Classes (methods and attributes) Objects Arrays

Please complete the following programming with clear explanations. Thanks!

Homework 1 Programming with Java:

What This Assignment Is About? Classes (methods and attributes)

Objects

Arrays of Primitive Values

Arrays of Objects

Recursion

for and if Statements

Selection Sort Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.)

Use upper case for constants. Use title case (first letter is upper case) for classes.

Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

Use tabs or spaces to indent code within blocks (code surrounded by braces).

This includes classes, methods, and code associated with if, switch and loop statements. Be consistent with the number of spaces or tabs that you use to indent.

Use white space to make your program more readable. For each file (class) in your assignment, provide a heading (in comments) which includes: A description of what this program is doing.

Part 2 Classes, Objects, and Arrays In this assignment, we will be making a program that create an examination seating with a number of rows and columns specified by a user. Use the file HomeworkTwo.java (As follows).

public class HomeworkTwo { public static void main(String[] args) { Classroom classroom; Student data; int row, col, rowNum, columnNum; String info; Scanner scan = new Scanner(System.in); System.out.println ("How many rows do you want?"); rowNum = scan.nextInt(); System.out.println ("How many columns do you want?"); columnNum = scan.nextInt(); classroom = new Classroom(rowNum, columnNum); System.out.println ("Capture a student information (name/lastname) or enter \"Q\" to quit."); info = scan.next(); while (!info.equalsIgnoreCase( "Q")) { data = new Student(studentInfo); System.out.println("Capture the row number where the student wants to sit: "); row = scan.nextInt(); System.out.println("Capture the column number where the student wants to sit: "); col = scan.nextInt(); if (classroom.isValid(row, col) == false) { System.out.println(" row or column number is not valid."); System.out.println("A student " + data.getFirstName() + " " + data.getLastName() + " is not assigned to a seat."); } else { if (classroom.setStudentAt(row, col, data) == true) { System.out.println("/n The seat at row " + row + " and column " + col + " is assigned to " + data.toString()); System.out.println(classroom); } else { System.out.println("/n The seat at row " + row + " and column " + col + " is taken."); } } // Read the next studentInfo System.out.println ("Capture a student information (name/lastname) or enter \"Q\" to quit."); info = scan.next(); } scan.close(); } }

Save HomeworkTwo.java and all files requested below in the same folder. Step 1 First, create a file named Student.java and define a class Student. It should have two instance variables, lastName (String) and firstName (String). The class must include the following methods: public Student ( ) Constructs a Student object by assigning the default string " bar " to lastName and foo to firstName. public Student (String info) Constructs a Student object using the string info. Use the split method of the String class to extract first name and last name, then assign them to each instance variable of the Student class. An example of the input string is: John/Doe public String getLastName ( ) It should return the instance variable lastName. public String getFirstName ( ) It should return the instance variable firstName. public String toString ( ) It should return a string containing the initial character of the first name, a period, the initial character of the last name, and a period.An example of such string for the student John Doe is: J.D.

Step 2 Second, create a class called Classroom. This class should be defined in a file named Classroom.java. The class contains a 2-dimensional array (called seats) of Student objects. The class must include the following methods: Public Classroom (int rowNum, int columnNum) It instantiates a two-dimensional array of the size "rowNum" by "columnNum". Then it initializes each student element of this array using the constructor of the class Student without any parameter. So, each student will have default values for its instance variables. private Student getStudentAt (int row, int col) It returns the student object at the indexes row and col (specified by the parameters) from the 2D array "seats". public boolean setStudentAt (int row, int col, Student data) The method assign the Student object referenced as "data" to the seat at "row" and "col". If the seat has a default student, i.e., a student with the last name "bar" and the first name "foo", then we can assign the new student "data" to that seat and the method returns true. Otherwise, this seat is considered to be taken by someone else, the method does not assign the student and returns false. public boolean isValid (int row, int col) The method checks if the parameters row and col are valid. If at least one of the parameters "row" or "col" is less than 0 or larger than the last index of the array then it returns false. Otherwise it returns true. public String toString ( ) Returns a String containing the information of the array seats. It should use the toString method of the class Student and return the following format: The current seating: D.J. foo.bar. E.T. foo.bar. foo.bar. S.W. T.C. A.T. foo.bar. * the where used to indicate that the 4 lineas are one string. But, should not be included in the returned value. After compiling Student.java, Classroom.java, and HomeworkTwo.java files then execute HomeworkTwo.class.

Sample Output:

Make sure that your program works at least with this scenario. C:\MyJava\applications>java HomeworkTwo How many rows do you want?

3

How many columns do you want?

3

Capture a student information (name/lastname) or enter "Q" to quit. Mickey/Mouse Capture the row number where the student wants to sit:

1

Capture the column number where the student wants to sit:

2

The seat at row 1 and column 2 is assigned to M.M. The current seating:

foo.bar. foo.bar. foo.bar.

foo.bar. foo.bar. M.M.

foo.bar. foo.bar. foo.bar. Capture a student information (name/lastname) or enter "Q" to quit.

Daisy/Duck

Capture the row number where the student wants to sit: 2

Capture the column number where the student wants to sit:

0 The seat at row 2 and column 0 is assigned to D.D. The current seating:

foo.bar. foo.bar. foo.bar.

foo.bar. foo.bar. M.M.

D.D. foo.bar. foo.bar. Capture a student information (name/lastname) or enter "Q" to quit.

Clarabelle/Cow

Capture the row number where the student wants to sit:

2 Capture the column number where the student wants to sit:

1 The seat at row 2 and column 1 is assigned to C.C. The current seating:

foo.bar. foo.bar. foo.bar.

foo.bar. foo.bar. M.M.

D.D. C.C. foo.bar. Capture a student information (name/lastname) or enter "Q" to quit.

Max/Goof

Capture the row number where the student wants to sit:

0

Capture the column number where the student wants to sit:

0

The seat at row 0 and column 0 is assigned to M.G. The current seating:

M.G. foo.bar. foo.bar.

foo.bar. foo.bar. M.M.

D.D. C.C. foo.bar. Capture a student information (name/lastname) or enter "Q" to quit.

Horace/Horsecollar

Capture the row number where the student wants to sit:

5

Capture the column number where the student wants to sit:

1

row or column number is not valid.

A student Horace Horsecollar is not assigned a seat. Capture a student information (name/lastname) or enter "Q" to quit.

Sylvester/Shyster

Capture the row number where the student wants to sit:

2

Capture the column number where the student wants to sit:

0

The seat at row 2 and column 0 is taken. Capture a student information (name/lastname) or enter "Q" to quit.

Snow/White

Capture the row number where the student wants to sit:

-1

Capture the column number where the student wants to sit:

0 row or column number is not valid.

A student Snow White is not assigned a seat. Capture a student information (name/lastname) or enter "Q" to quit.

Jiminy/Criket

Capture the row number where the student wants to sit:

0

Capture the column number where the student wants to sit:

2 The seat at row 0 and column 2 is assigned to J.C.

The current seating:

M.G. foo.bar. J.C.

foo.bar. foo.bar. M.M.

D.D. C.C. foo.bar.

Capture a student information (name/lastname) or enter "Q" to quit.

Q

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions