Menu

Please Complete Following Programming Clear Explanations Thanks Homework 1 Programming Jav Q43894943

Please complete the following programming with clearexplanations. 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 isupper case) for classes.

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

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

This includes classes, methods, and code associated with if,switch and loop statements. Be consistent with the number of spacesor 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 (incomments) 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 anexamination seating with a number of rows and columns specified bya 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(“n 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 samefolder.

Step 1

First, create a file named Student.java and define a class Student.It should have two instance variables, lastName (String) andfirstName (String). The class must include the followingmethods:

public Student ( ) Constructs a Student object by assigning thedefault string ” bar ” to lastName and “foo” to firstName.

public Student (String info) Constructs a Student object using thestring info. Use the split method of the String class to extractfirst name and last name, then assign them to each instancevariable of the Student class. An example of the input stringis:

“John/Doe”

public String getLastName ( ) It should return the instancevariable lastName.

public String getFirstName ( )

It should return the instance variable firstName.
public String toString ( )

It should return a string containing the initial character of thefirst name, a period, the initial character of the last name, and aperiod.
An example of such string for the student John Doeis:

“J.D.”

Step 2

Second, create a class called Classroom. This class should bedefined in a file named Classroom.java. The class contains a2-dimensional array (called seats) of Student objects. The classmust include the following methods:

Public Classroom (int rowNum, int columnNum) It instantiates atwo-dimensional array of the size “rowNum” by “columnNum”. Then itinitializes each student element of this array using theconstructor of the class Student without any parameter. So, eachstudent 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 (specifiedby 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 theseat at “row” and “col”. If the seat has a default student, i.e., astudent with the last name “bar” and the first name “foo”, then wecan assign the new student “data” to that seat and the methodreturns true. Otherwise, this seat is considered to be taken bysomeone else, the method does not assign the student and returnsfalse.

public boolean isValid (int row, int col)
The method checks if the parameters row and col are valid. If atleast one of the parameters “row” or “col” is less than 0 or largerthan the last index of the array then it returns false. Otherwiseit 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 returnthe 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.javafiles then execute HomeworkTwo.class.    

Sample Output:

Make sure that your program works at least with thisscenario.

C:MyJavaapplications>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” toquit. Mickey/Mouse Capture the row number where the student wantsto 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” toquit.

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” toquit.

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” toquit.

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” toquit.

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” toquit.

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” toquit.

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” toquit.

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” toquit.

Q

Expert Answer


Answer to Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What Th…

OR