Question

Java Project In Brief... For this Java project, you will create a Java program for a...

Java Project

In Brief...

For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain:

I need a code that works, runs and the packages are working as well

The room number of the classroom.

The teacher and the subject assigned to the classroom.

A list of students assigned to the classroom including their student id and final grade.

Instructions

Application Structure

Projects should be organized into libraries or packages of classes that fall into general categories (please make this a working package that can run on any java app). This project can be divided into two packages:

school which contains JavaBeans that naturally fall into that category.

util which contain general purpose classes.

In your project directory create the listed subdirectories. They will be the packages used for the JavaBeans, interfaces, and utilities required:

util

school

The util Package Files

Your class files for your course supplied the KeyboardReader class. Copy the KeyboardReader.java into the util package.

In the util package, create the Displayable interface. The interface should declare one method as follows:

public abstract String display()

The following shows the directories and files you should have at this point:

Project Directoryutil package

KeyboardReader.java

Displayable.java

school package

The school Package Files

Object-Oriented programs become more maintainable, flexible, and saleable when programmers use inheritance, encapsulation, polymorphism, and abstraction. The following descriptions of the classes in the school package should leverage these principles.

Create the Person JavaBean

In the school package, create the Person JavaBean. Make it an abstract class. Declare the following instance variables:

String firstName

String lastName

Include the getter and setter methods for each variable. Use the camel case naming convention for JavaBean methods and variables. Include a method named getFullName() that returns both names concatenated into a String with a space between the first and last names.

Create the Teacher JavaBean class

Create the Teacher class in the school package. It inherits the Person abstract class and implements the Displayable interface. It defines only one variable as follows:

String subject

Include the getter and setter method for the variable. Use the camel case naming convention for JavaBeans. Provide a no argument constructor. Provide another constructor that uses the following parameters to initialize the variables:

String firstName

String lastName

String subject

Override the display() method. It should return a String containing the teacher's full name using the getFullName() method defined in Person and the subject taught as follows:

Roger Sakowski teaches English.

Create the Student JavaBean Class

Create the Student class in the school package. It inherits the Person abstract class and implements the Displayable interface. It defines two variables:

int studentId

int finalGrade

Include the getter and setter methods for the variables. Use the camel case naming convention for JavaBeans. Override the display()method. It should return a Stringcontaining the student's id, the student's full name using the getFullName() method defined in Person, and the student's final grade as follows:

Student ID: 1    John Doe Final Grade: 90

Create the Classroom JavaBean Class

Create the Classroom class in the school package. It implements the Displayable interface. It defines three instance variables:

int roomNumber

Displayable teacher (note that the Teacher instance is downcast to the Displayable interface)

ArrayList students (note that the Student instances in the list are downcast to the Displayable interface)

Provide a no argument constructor. Provide another constructor that uses the following parameters to initialize the variables:

int roomNumber

Displayable teacher

ArrayList students

The packages and files you have created so far should look like the following:

Project Directoryutil package

KeyboardReader.java

Displayable.java

school package

Person.java

Teacher.java

Student.java

Classroom.java

Programming Logic

The PrintReports class

A well designed program depends on source code that not only does the job, but does it in a highly maintainable and efficient way. There should never be blocks of duplicate code and methods should be simple and designed to one thing. The PrintReports class will contain most of the programming logic for this project. Organization of methods and their responsibilities are the focus of this section.

Create PrintReports

In your project directory create the PrintReports class.

Project Directory

PrintReports.java

util package

KeyboardReader.java

Displayable.java

school package

Person.java

Teacher.java

Student.java

Classroom.java

It will define the main() method.

Create support methods signatures

PrintReports should define the following methods using the listed method signatures:

public Displayable enterClassroom()

public Displayable enterTeacher()

public Displayable enterStudent()

void report(ArrayList)

You can leave them as skeleton code for now. We will cover the logic they should contain in turn.

Working with non-static methods

Note that the methods are not static. One way to escape the static requirement main() imposes is to use this approach:

public static void main(String[] args) {
        new PrintReports();
}

public PrintReports(){
        // Your code goes here
}

The public PrintReports() Constructor

In a do…while loop collect the data need to create a Classroom object using the enterClassroom() method. You should be able to create any number of Classroomobjects. Prompt the user so he or she can enter another Classroom or quit the loop. Store the Classroom objects in an ArrayList collection.

The public Displayable enterClassroom() Method

Using KeyboardReader, prompt the user for a room number. Save it as an int. The room number must be 100 or greater. If the user enters a lower number, he or she should be prompted again until an acceptable number is entered.

Call enterTeacher() to obtain an instance of a teacher and store it as a Displayable object.

In a do…while loop, call enterStudent() to obtain a Student as a Displayable object and store it in an ArrayList collection. Prompt the user so he or she can enter another student or quit the loop.

The public Displayable enterTeacher() Method

The method should prompt the user using KeyboardReader for their first and last name as well as the subject they teach. Create an instance of Teacher using that data and return the object as an instance of Displayable.

The public Displayable enterStudent() method

Prompt the user for the student id, first and last names, and their final grade. Using that data, create a Student instance. A student's id must be greater than 0. A student's final grade must be between 0 and 100. Return the Student object as a Displayable object.

The void report(ArrayList) Method

In a for loop, iterate through the ArrayList collection containing the downcast Classroom objects.

Call the display() method defined in Classroom. It should report the room number.

It should call the display() method in the teacher variable to report the teacher assigned to the classroom.

In a for loop it should iterate through the ArrayList collection of Student objects calling the display() method for each one.

The Report Example

The following is an example of output produced by the report() method. For brevity, it only demonstrates one classroom containing one student. Your program should allow you to create multiple classrooms and multiple students per classroom.

First You Need To Create A Classroom
Enter Room Number: 101

Now You Need To Enter A Teacher For The Classroom.
Enter Teacher First Name: Sam
Enter Teacher Last Name: Huston
Enter Subject Taught: English

Now You Need To Add Students For The Classroom
Enter Student First Name: Sally
Enter Student Last Name: Jones
Enter Student ID: 1
Enter Student Final Grade: 90

Enter Another Student? (Y/N): n (y should prompt for a new student)

Enter Another Classroom? (Y/N): n (y should prompt for a new classroom)

----------------------------------------------------------
Room Number: 101
Sam Huston teaches English
Student ID: 1   Sally Jones     Final Grade: 90
----------------------------------------------------------

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL THERE TO HELP YOU

ANSWER:

CODE:

/** KeyboardReader.java **/

package course.software.reports.util;

import java.util.Scanner;

public class KeyboardReader {
    private final Scanner scanner = new Scanner(System.in);

    public void printStatement(String statement) {
        System.out.println(statement);
    }
    public String readAnswer(String question) {
        System.out.print(question);
        String answer = scanner.nextLine();
        return answer;
    }
}

/** Displayable.java **/

package course.software.reports.util;

public interface Displayable {
    String display();
}

/** Person.java **/

package course.software.reports.school;

public abstract class Person {
    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFullName() {
        return this.firstName + " " + this.lastName;
    }
}

/** Teacher.java **/

package course.software.reports.school;

import course.software.reports.util.Displayable;

public class Teacher extends Person implements Displayable {

    private String subject;

    public Teacher() {
    }

    public Teacher(String firstName, String lastName, String subject) {
        this.setFirstName(firstName);
        this.setLastName(lastName);
        this.setSubject(subject);
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    @Override
    public String display() {
        return this.getFullName() + " teaches " + this.getSubject();
    }
}

/** Student.java **/

package course.software.reports.school;

import course.software.reports.util.Displayable;

public class Student extends Person implements Displayable {

    private int studentId;
    private int finalGrade;

    public Student() {
    }

    public Student(String firstName, String lastName, int studentId, int finalGrade) {
        this.setFirstName(firstName);
        this.setLastName(lastName);
        this.setStudentId(studentId);
        this.setFinalGrade(finalGrade);
    }

    public int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public int getFinalGrade() {
        return finalGrade;
    }

    public void setFinalGrade(int finalGrade) {
        this.finalGrade = finalGrade;
    }

    @Override
    public String display() {
        return "Student ID: " + this.getStudentId() + "    " + this.getFullName() + " Final Grade: " + this.getFinalGrade();
    }
}

/** Classroom.java **/

package course.software.reports.school;

import course.software.reports.util.Displayable;

import java.util.ArrayList;

public class Classroom implements Displayable {

    private int roomNumber;
    private Displayable teacher;
    private ArrayList<Displayable> students;

    public Classroom() {
    }

    public Classroom(int roomNumber, Displayable teacher, ArrayList<Displayable> students) {
        this.setRoomNumber(roomNumber);
        this.setTeacher(teacher);
        this.setStudents(students);
    }

    public int getRoomNumber() {
        return roomNumber;
    }

    public void setRoomNumber(int roomNumber) {
        this.roomNumber = roomNumber;
    }

    public Displayable getTeacher() {
        return teacher;
    }

    public void setTeacher(Displayable teacher) {
        this.teacher = teacher;
    }

    public ArrayList<Displayable> getStudents() {
        return students;
    }

    public void setStudents(ArrayList<Displayable> students) {
        this.students = students;
    }

    @Override
    public String display() {
        String output = "Room Number: " + this.getRoomNumber() + "\n";
        output += this.getTeacher().display() + "\n";

        ArrayList<Displayable> studentList = this.getStudents();
        for (int i=0; i<studentList.size(); i++) {
            output += studentList.get(i).display();
            if (i < (studentList.size()-1)) {
                output += "\n";
            }
        }
        return output;
    }
}

/** PrintReports.java **/

package course.software.reports;

import course.software.reports.school.Classroom;
import course.software.reports.school.Student;
import course.software.reports.school.Teacher;
import course.software.reports.util.Displayable;
import course.software.reports.util.KeyboardReader;

import java.util.ArrayList;

public class PrintReports {
    ArrayList<Displayable> classroomList = new ArrayList<>();

    public PrintReports() {
        KeyboardReader reader = new KeyboardReader();
        Displayable classroom;
        String addClassroom;

        reader.printStatement("First You Need To Create A Classroom");
        do {
            classroom = enterClassroom();
            if (classroom != null) {
                classroomList.add(classroom);
            }

            boolean validInput = true;
            do {
                addClassroom = reader.readAnswer("Enter Another Classroom? (Y/N): ");
                if ((!addClassroom.equalsIgnoreCase("Y")) && (!addClassroom.equalsIgnoreCase("N"))) {
                    validInput = false;
                }
            } while (!validInput);
        } while (addClassroom.equalsIgnoreCase("Y"));
        reader.printStatement("");
    }

    public Displayable enterClassroom() {
        KeyboardReader reader = new KeyboardReader();
        boolean validInput = true;
        int roomNumber = 0;
        Displayable teacher = null;
        ArrayList<Displayable> studentList = new ArrayList<>();

        do {
            String roomNo = reader.readAnswer("Enter Room Number: ");
            try {
                roomNumber = Integer.parseInt(roomNo);
                if (roomNumber < 100) {
                    validInput = false;
                }
            } catch (NumberFormatException ne) {
                validInput = false;
            }
        } while (!validInput);

        reader.printStatement("");
        reader.printStatement("Now You Need To Enter A Teacher For The Classroom.");
        teacher = enterTeacher();

        reader.printStatement("");
        reader.printStatement("Now You Need To Add Students For The Classroom");
        Displayable student;
        validInput = true;
        String addStudent;
        do {
            student = enterStudent();
            if (student != null) {
                studentList.add(student);
            }
            do {
                addStudent = reader.readAnswer("Enter Another Student? (Y/N): ");
                if ((!addStudent.equalsIgnoreCase("Y")) && (!addStudent.equalsIgnoreCase("N"))) {
                    validInput = false;
                }
            } while (!validInput);
        } while (addStudent.equalsIgnoreCase("Y"));

        reader.printStatement("");
        Classroom classroom = new Classroom(roomNumber, teacher, studentList);
        return classroom;
    }

    public Displayable enterTeacher() {
        KeyboardReader reader = new KeyboardReader();
        String firstName = reader.readAnswer("Enter Teacher First Name: ");
        String lastName = reader.readAnswer("Enter Teacher Last Name: ");
        String subject = reader.readAnswer("Enter Subject Taught: ");

        Teacher teacher = new Teacher(firstName,lastName,subject);
        return teacher;
    }

    public Displayable enterStudent() {
        KeyboardReader reader = new KeyboardReader();
        String firstName = reader.readAnswer("Enter Student First Name: ");
        String lastName = reader.readAnswer("Enter Student Last Name: ");

        int studentId = 0;
        boolean validInput = true;
        do {
            String id = reader.readAnswer("Enter Student ID: ");
            try {
                studentId = Integer.parseInt(id);
                if (studentId < 0) {
                    validInput = false;
                }
            } catch (NumberFormatException ne) {
                validInput = false;
            }
        } while (!validInput);

        int studentGrade = 0;
        validInput = true;
        do {
            String grade = reader.readAnswer("Enter Student Final Grade: ");
            try {
                studentGrade = Integer.parseInt(grade);
                if ((studentGrade < 0) || (studentGrade > 100)) {
                    validInput = false;
                }
            } catch (NumberFormatException ne) {
                validInput = false;
            }
        } while (!validInput);

        reader.printStatement("");
        Student student = new Student(firstName, lastName, studentId, studentGrade);
        return student;
    }

    public ArrayList<Displayable> getClassroomList() {
        return classroomList;
    }

    void report(ArrayList<Displayable> classroomList) {
        KeyboardReader reader = new KeyboardReader();
        for (int i=0; i<classroomList.size(); i++) {
            reader.printStatement("----------------------------------------------------------");
            Displayable classroom = classroomList.get(i);
            reader.printStatement(classroom.display());
            reader.printStatement("----------------------------------------------------------");
        }
    }

    public static void main (String[] args) {
        PrintReports printReports = new PrintReports();
        printReports.report(printReports.getClassroomList());
    }
}

RATE THUMBSUP

THANKS

Add a comment
Know the answer?
Add Answer to:
Java Project In Brief... For this Java project, you will create a Java program for a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • You will create a class to keep student's information: name, student ID, and grade. The program...

    You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • Language: C++ Write a program that will allow the instructor to enter the student's names, student...

    Language: C++ Write a program that will allow the instructor to enter the student's names, student ID, and their scores on the various exams and projects. A class has a number of students during a semester. Those students take 4 quizzes, one midterm, and one final project. All quizzes weights add up to 40% of the overall grade. The midterm exam is 25% while the final project 35%. The program will issue a report. The report will show individual grades...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • Subjects: Develop two JavaBeans. Students can work together as a team (of up to 3 members),...

    Subjects: Develop two JavaBeans. Students can work together as a team (of up to 3 members), and it is ok to have a smaller group. Please include names of your team members in your submission, and each team only needs to submit one copy on Canvas. Instructions: Create a Java Web Project in NetBeans. Within the project, create a package named as “beans” under the “Source Package”. Create two JavaBean classes for the “beans” package, one named as Course and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT