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("\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 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
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
// Student.java
public class Student {
private String lastName;
private String firstName;
public Student() {
this.firstName = "foo";
this.lastName = "bar";
}
public Student(String info) {
String arr[] =
info.split("/");
this.firstName = arr[0];
this.lastName = arr[1];
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String s="";
if(firstName.equals("foo")
&& lastName.equals("bar"))
{
s+=firstName+"."+lastName+".";
}
else
s=firstName.charAt(0)+"."+lastName.charAt(0)+".";
return s;
}
}
===============================
// Classroom.java
public class Classroom {
private Student seats[][] = null;
public Classroom(int rowNum, int
columnNum) {
this.seats = new
Student[rowNum][columnNum];
for(int i=0;i
for(int
j=0;j
seats[i][j]=new Student();
}
}
}
private Student getStudentAt (int row, int col)
{
return seats[row][col];
}
public boolean setStudentAt (int row, int col, Student
data)
{
if(seats[row][col].getFirstName().equals("foo") &&
seats[row][col].getLastName().equals("bar"))
{
seats[row][col]=data;
return
true;
}
else
{
return
false;
}
}
public boolean isValid (int row, int col)
{
if(row<0 ||
row>seats.length-1)
{
return
false;
}
else if(col<0 ||
col>seats[0].length-1)
{
return
false;
}
else
{
return
true;
}
}
public String toString()
{
String s="The current
seating:\n";
for(int
i=0;i
for(int
j=0;j
s+=seats[i][j].toString()+" ";
}
s+="\n";
}
return s;
}
}
================================
// HomeworkTwo.java
import java.util.Scanner;
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(info);
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();
}
}
===============================
output:
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 to 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 to 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
=====================Could you plz rate me well.Thank You
Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...
In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...
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...
Implement a class CSVReader that reads a CSV file, and provide methods: int numbOfRows() int numberOfFields(int row) String field(int row, int column) Please use the CSVReader and CSVReaderTester class to complete the code. I have my own CSV files and cannot copy them to here. So if possible, just use a random CSV file. CSVReader.java import java.util.ArrayList; import java.util.Scanner; import java.io.*; /** Class to read and process the contents of a standard CSV file */ public class CSVReader {...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class Chapter9a_FillInTheCode { public static void main(String[] args) { String [][] geo = {{"MD", "NY", "NJ", "MA", "CA", "MI", "OR"}, {"Detroit", "Newark", "Boston", "Seattle"}}; // ------> exercise 9a1 // this code prints the element at row at index 1 and column at index 2 // your code goes here System.out.println("Done exercise 9a1.\n"); // ------> exercise 9a2 // this code prints all the states in the...
FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...