Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Assignment #: 4 Name: Your name StudentID: Lecture: Description: Assignment 4 class displays a menu of choices to a user and performs the chosen

/* Assignment #: 4
Name: Your name
StudentID:
Lecture:
Description: Assignment 4 class displays a menu of choices to a user
and performs the chosen task. It will keep asking a user to
enter the next choice until the choice of 'Q' (Quit) is entered.
*/
import java.util.*;
public class Assignment4
{
public static void main (String[] args)
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
//String inputInfo= "";
String depName, university, firstName, lastName, academicLevel, numOfMembersStr;
int numOfMembers;
String line = new String();
// instantiate a Department object
Department depar1 = new Department();
printMenu();
//Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1)
{
case 'A': //Add Department
System.out.print("Please enter the Department information: ");
System.out.print("Enter its name: ");
depName = scan.nextLine();
depar1.setDeptName(depName);
System.out.print("Enter its number of members: ");
numOfMembersStr = scan.nextLine();
numOfMembers = Integer.parseInt(numOfMembersStr);
depar1.setNumberOfMembers(numOfMembers);
System.out.print("Enter its university: ");
university = scan.nextLine();
depar1.setUniversity(university);
System.out.print("Enter its faculty's first name: ");
firstName = scan.nextLine();
System.out.print("Enter its faculty's last name: ");
lastName = scan.nextLine();
System.out.print("Enter its faculty's academic level: ");
academicLevel = scan.nextLine();
depar1.setCurrentFaculty(firstName, lastName, academicLevel);
break;
case 'D': //Display Department
System.out.print(depar1.toString());
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action ");
break;
}
}
else
{
System.out.print("Unknown action ");
}
} while (input1 != 'Q' || line.length() != 1);
scan.close();
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction " +
"------\t\t------ " +
"A\t\tAdd Department " +
"D\t\tDisplay Department " +
"Q\t\tQuit " +
"?\t\tDisplay Help ");
}
}
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
D CHE CSE205 Assignment #4 Due date/Time: Friday, Jan 22, 2021 at 11:59pm Arizona time Important: This is an individual assignment, please do not collaborate. Make sure that you write every line of your own code.Give your code to some code wten by one else will become a fine academic integrity and will result in a report sent to the Dean's office. Students are expected to abide by the FSE Honor Code apengineering and Forrach angement, we will we powerful plagirim defection software embedded on gradescope.com to compare and check all student whwission! Equipment defects and technical difficulties cannor become excuses for late submission. We will NOT accept any submission through emails. No te atient will be accepted What this Assignment Is About: Review on writing classes. Aggregation relationship between classes Review on creating Objects, Accessors/Mutator (Modifiers) Visibility Modifiers (Access specifier) - public, private, etc. Encapsulation concept Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number time), and a class description need to be included at the top of each ite/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method to explain code that are hard to follow should be written You can look at the programs in the text book to see how comments are added to programs File Provided Assignment java (Given. This is the driver program, don't change it. Rigth click on the file, then pick Save target as' to download) Department java (You need to write the code from scratch according to the UML) Facultyjava (You need to write the code from scratch according to the UML.) 1. Assignment Description Do & 21 1. Assignment Description De E- wy - " - Bird . The Faculty class The Faculty class contains the information of a Faculty. It has following attributes: Description Attribute name Attribute type tistName string The fist name info of the Faculty Last Name String The last name info of the Faculty The academic level of the Faculty such as senior, Junior, tenure, lecturer, etc. academicLevel string a/230-27279045 cluster 201canvas-usercontent.com c MO CE TE MAT Login CSE 205 The following constructor should be provided to initialize each attribute. This constructor initializes the value of string attributes to "?". public Faculty The following accessor methods should be provided to get the attributes: public String getFirstName() public String getLastName() public String getAcademic Level The following modifier (mutator) methods should be provided to set the attributes: public void setFirst Name (String someFirstName) public void setLastName (String some LastName) public void setAcademicLevel (String someAcademicLevel) The following method must be defined: public String toString() toString method should return a string of the following format: Water, Mary (Senior) where Water" is the last name of a faculty, "Mary" is the first name, and Senior is the academic level. So, you need to insert","and parentheses between these variables Note that you can choose a meaningful parameter variable name for each method. Do NOT add " " at the very end for the toString method. The Department class The Department class describes a department at a university. It has the following attributes Description Attribute type Attribute name string The name of the Department. name The number of employees in the Department int number Members 2014-usercontent.com C205 MAT niversity string The university the Department belongs to current Faculty Faculty The current Faculty of the Department The following constructor should be provided to initialize each attribute. This constructor initializes the value of string attributes to *7* and the value of integer attribute to O, and an object of Faculty using the constructor of the Faculty class ubito Departments The following accessor methods should be provided to get the attributes public String getDeptName() public int getNumberOfMembers) public String getUniversity publie Faculty getCurrent Faculty The following modifier(mutator) methods should be provided to change the attributes: public void set Department Name (String someone) public void setNumberor Menbera (int Bone Number) public void setUniversity (String some University) public void setCurrent Faculty (String fiestlane, String lastName, Sering some level) The following method must be defined public String tostring) The toString method constructs a string of the following format Department Name: Computer Science Number of Members A541 University Arizona State University Facwlry Water Amy Senior See the following for one comple: Department Name: Computer Science Leias-usercontent.com CSE206 DO See the following for one example: Department Namet Computer Science Number of Members 54 University: Arizona State University Yaculty: Water, Amy (Senior) Assignment (Note that this part is already done in the Assignment java file that is given to you. This explains each functionality of this class) In this assignment, download Assignment/java tile, and use it for your assignment. You do not need to modify Assignment.javalile. You only need to write Department for and Faculty java bien The following is the description of Assignment class The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input und screen output. The main mented should cunt by (oploying the following this exact format: Choice Action AWAdd Department Display Department Oui PWDisplay Helpin Next, the following prompt should be displayed: What action would you like to perform Read in the user input and execute the appropriate command. After the execution of each command, to display the prompt. Commands should be accepted in both were and uppercase Add Department Your program should display the following prompt Please enter the Department information Enter the Department name: Read in the user input and set the Department name accordingly. Then it will ask the user to enter is number of employees, CEO's name and its Faculty information, the includes an inda Information Read in the user input and set the data properly for the Department object. Note that there is only one Department object in this assignment. Thus when "Adi Department option is selected more than once the new ewidersrite the old one HR C ITVE 7238-27279045.cluster201.car-user-content.com CHE CSE 205 Your program should display the following prompe Please enter the Department information: Enter the Department name: Read in the user input and set the Department name accordingly. Then it will ask the user to enter its number of employees. CEO's name and its Faculty information, this includes fum. Namai information Rent in the user input and set the data properly for the Department object, Note that there is only one Department object in this assignment. Thus when "Add Department option is selected more than once, the new te will overwrite the old one. Display Department Your program should display the Department information in the following format: Department Name Computer Science Number of Members:452w University Arizona State University Faculty: WWater, Mary(Senior) Make sure to use the toString method of the Faculty class to display this information. The touring method is used together with System.ootprint method (System.out.println should NOT to be used within the toString method.) Quit Your program should stop executing and output nothing. Display Help Your program should redisplay the choice action menu Invalid Command If an invalid command is entered, display the following line Unknown action 2. Test Cases Input The following files are the test cases that will be used as input for your program (Right-click and use "Save As"): s Login ASU CSE... https://.... http... A Computer Science 54 Arizona State University Amy Water Senior D A English 43 University of Arizona Meg Walker Tenure LO x http https://... T http.. 1 http... i Login NCSE Choice Action A D 0 2 Add Department Display Department Quit Display Help What action would you like to perform? Please enter the Department information Enter its name: Enter its number of members Enter itu university Enter its faculty's first name Enter its faculty's last name: Enter its faculty's academic Level: What action would you like to perform? Department Name Number Of Members University Faculty: Computer Science 54 Arizona State University Water, Amy (Senior) What action would you like to perform? Please enter the Department information Enterito na Enter its number of members Enter its university Enter its faculty's first name Enter its faculty's last name: Enter Ite faculty's academic level: What action would you like to perform? Department Name: English Number of Members: 43 University University of Arizona Faculty: Walker, Meg (Tenure) what action would you like to perform? D CHE CSE205 Assignment #4 Due date/Time: Friday, Jan 22, 2021 at 11:59pm Arizona time Important: This is an individual assignment, please do not collaborate. Make sure that you write every line of your own code.Give your code to some code wten by one else will become a fine academic integrity and will result in a report sent to the Dean's office. Students are expected to abide by the FSE Honor Code apengineering and Forrach angement, we will we powerful plagirim defection software embedded on gradescope.com to compare and check all student whwission! Equipment defects and technical difficulties cannor become excuses for late submission. We will NOT accept any submission through emails. No te atient will be accepted What this Assignment Is About: Review on writing classes. Aggregation relationship between classes Review on creating Objects, Accessors/Mutator (Modifiers) Visibility Modifiers (Access specifier) - public, private, etc. Encapsulation concept Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number time), and a class description need to be included at the top of each ite/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method to explain code that are hard to follow should be written You can look at the programs in the text book to see how comments are added to programs File Provided Assignment java (Given. This is the driver program, don't change it. Rigth click on the file, then pick Save target as' to download) Department java (You need to write the code from scratch according to the UML) Facultyjava (You need to write the code from scratch according to the UML.) 1. Assignment Description Do & 21 1. Assignment Description De E- wy - " - Bird . The Faculty class The Faculty class contains the information of a Faculty. It has following attributes: Description Attribute name Attribute type tistName string The fist name info of the Faculty Last Name String The last name info of the Faculty The academic level of the Faculty such as senior, Junior, tenure, lecturer, etc. academicLevel string a/230-27279045 cluster 201canvas-usercontent.com c MO CE TE MAT Login CSE 205 The following constructor should be provided to initialize each attribute. This constructor initializes the value of string attributes to "?". public Faculty The following accessor methods should be provided to get the attributes: public String getFirstName() public String getLastName() public String getAcademic Level The following modifier (mutator) methods should be provided to set the attributes: public void setFirst Name (String someFirstName) public void setLastName (String some LastName) public void setAcademicLevel (String someAcademicLevel) The following method must be defined: public String toString() toString method should return a string of the following format: Water, Mary (Senior) where Water" is the last name of a faculty, "Mary" is the first name, and Senior is the academic level. So, you need to insert","and parentheses between these variables Note that you can choose a meaningful parameter variable name for each method. Do NOT add " " at the very end for the toString method. The Department class The Department class describes a department at a university. It has the following attributes Description Attribute type Attribute name string The name of the Department. name The number of employees in the Department int number Members 2014-usercontent.com C205 MAT niversity string The university the Department belongs to current Faculty Faculty The current Faculty of the Department The following constructor should be provided to initialize each attribute. This constructor initializes the value of string attributes to *7* and the value of integer attribute to O, and an object of Faculty using the constructor of the Faculty class ubito Departments The following accessor methods should be provided to get the attributes public String getDeptName() public int getNumberOfMembers) public String getUniversity publie Faculty getCurrent Faculty The following modifier(mutator) methods should be provided to change the attributes: public void set Department Name (String someone) public void setNumberor Menbera (int Bone Number) public void setUniversity (String some University) public void setCurrent Faculty (String fiestlane, String lastName, Sering some level) The following method must be defined public String tostring) The toString method constructs a string of the following format Department Name: Computer Science Number of Members A541 University Arizona State University Facwlry Water Amy Senior See the following for one comple: Department Name: Computer Science Leias-usercontent.com CSE206 DO See the following for one example: Department Namet Computer Science Number of Members 54 University: Arizona State University Yaculty: Water, Amy (Senior) Assignment (Note that this part is already done in the Assignment java file that is given to you. This explains each functionality of this class) In this assignment, download Assignment/java tile, and use it for your assignment. You do not need to modify Assignment.javalile. You only need to write Department for and Faculty java bien The following is the description of Assignment class The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input und screen output. The main mented should cunt by (oploying the following this exact format: Choice Action AWAdd Department Display Department Oui PWDisplay Helpin Next, the following prompt should be displayed: What action would you like to perform Read in the user input and execute the appropriate command. After the execution of each command, to display the prompt. Commands should be accepted in both were and uppercase Add Department Your program should display the following prompt Please enter the Department information Enter the Department name: Read in the user input and set the Department name accordingly. Then it will ask the user to enter is number of employees, CEO's name and its Faculty information, the includes an inda Information Read in the user input and set the data properly for the Department object. Note that there is only one Department object in this assignment. Thus when "Adi Department option is selected more than once the new ewidersrite the old one HR C ITVE 7238-27279045.cluster201.car-user-content.com CHE CSE 205 Your program should display the following prompe Please enter the Department information: Enter the Department name: Read in the user input and set the Department name accordingly. Then it will ask the user to enter its number of employees. CEO's name and its Faculty information, this includes fum. Namai information Rent in the user input and set the data properly for the Department object, Note that there is only one Department object in this assignment. Thus when "Add Department option is selected more than once, the new te will overwrite the old one. Display Department Your program should display the Department information in the following format: Department Name Computer Science Number of Members:452w University Arizona State University Faculty: WWater, Mary(Senior) Make sure to use the toString method of the Faculty class to display this information. The touring method is used together with System.ootprint method (System.out.println should NOT to be used within the toString method.) Quit Your program should stop executing and output nothing. Display Help Your program should redisplay the choice action menu Invalid Command If an invalid command is entered, display the following line Unknown action 2. Test Cases Input The following files are the test cases that will be used as input for your program (Right-click and use "Save As"): s Login ASU CSE... https://.... http... A Computer Science 54 Arizona State University Amy Water Senior D A English 43 University of Arizona Meg Walker Tenure LO x http https://... T http.. 1 http... i Login NCSE Choice Action A D 0 2 Add Department Display Department Quit Display Help What action would you like to perform? Please enter the Department information Enter its name: Enter its number of members Enter itu university Enter its faculty's first name Enter its faculty's last name: Enter its faculty's academic Level: What action would you like to perform? Department Name Number Of Members University Faculty: Computer Science 54 Arizona State University Water, Amy (Senior) What action would you like to perform? Please enter the Department information Enterito na Enter its number of members Enter its university Enter its faculty's first name Enter its faculty's last name: Enter Ite faculty's academic level: What action would you like to perform? Department Name: English Number of Members: 43 University University of Arizona Faculty: Walker, Meg (Tenure) what action would you like to perform

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

More Books

Students also viewed these Databases questions