Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Tasks Note: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/22 lecture. After we cover 2/22 lecture,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Assignment Tasks Note: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/22 lecture. After we cover 2/22 lecture, you can complete the leftover tasks in the entire assignment. Part1: 1.1 Problem Descriptions Complete the missing code of a Java program which receives the user inputs of name and the year of birth and reports the person's age and classification (minor, adult, or senior). The following code you need to complete is described as following (the missing code items are denoted by TODO comment: public class AgeClassifier { private String name; //the name private int birthYear; //the year /* the constructor method */ public AgeClassifier (String sName, int year ) { name = sName; birthYear = year; } /* this method return the age */ public int getAge() { //TODO: add missing code to calculate and return the age of the person /* this method return the age */ public int getAge() { //TODO: add missing code to calculate and return the age of the person } /* this method return the age classification*/ public String getAgeClassification(int age) { //TODO: add missing code to classify //the input age into three types: minor, adult, and senior } public static void main(String args []) { Scanner user_inputs = new Scanner(System.in); System.out.print("Enter the name: "); String name = user_inputs.nextLine(); System.out.print("Enter the year of birth: "); int year = user_inputs.nextInt(); 1/TODO: add missing code below to print the name, age //and the age classification of that person } } Check the following section for the detailed specifications of your program. 1.2 Class Design Specification } Check the following section for the detailed specifications of your program. 1.2 Class Design Specification 1. The name of the class is called Age Classifier (also means the file name is Age Classifier.java) 2. The class has one integer variable birthYear to store the year of birth and one String variable name to store the name of the person 3. The class has four methods: a. AgeClassifier(String sName, int year): This constructor method has two input arguments to initialize the values of name and birthYear. This method is already completed. b.getAge(): This method calculate and return the age of the person. C. getAgeClassification(int age): This method receives an input (age) and return a String that denotes the age classification. There are three categories: "Minor" if the age is less than or equals to 19 "Adult" if the age is between 20 and 65 - "Senior" if the age is greater than 65 d. main(): This method will create at least one instance of the Age Classifier class with two inputs from the user by using Scanner class. Then you should use System.out.println to print the name, age, and the age classification of the user. Below is the sample outputs of the program . Enter the name: Test Person Enter the year of birth: 1996 Name. Test Person een 20 arid 65 Il the age is - "Senior" if the age is greater than 65 d. main(): This method will create at least one instance of the Age Classifier class with two inputs from the user by using Scanner class. Then you should use System.out.println to print the name, age, and the age classification of the user. Below is the sample outputs of the program Enter the name: Test Person Enter the year of birth: 1996 Name: Test Person Age: 24 years old Age classification: Adult Enter the name: Test Person 1 Enter the year of birth: 2005 Name: Test Person 1 Age: 15 years old Age classification: Minor 1.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beginning of your Java class file, specify the following items: o Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application 1.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beginning of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation o Part2: 2.1 Problem Descriptions Complete the missing code of a Java GUI program which is the GUI extension of above Part1. This program let user enter the name and birth year. There is a button named "Report" that report the age and classification of the user. The following code you need to complete is described as following the missing code items are denoted by TODO comments: Part2: 2.1 Problem Descriptions Complete the missing code of a Java GUI program which is the GUI extension of above Part1. This program let user enter the name and birth year. There is a button named "Report" that report the age and classification of the user. The following code you need to complete is described as following (the missing code items are denoted by TODO comments: import java.awt. FlowLayout; import javax.swing.JButton; import javax.swing. JFrame; import javax.swing. JLabel; import javax.swing. JTextArea; import javax.swing.JTextField; ublic class PersonGUI extends JFrame ements ActionListener { private JLabel lblName; //the name label private JTextField txtName; //the name text box private JLabel lblYear; //the year label private JTextField txtYear; //the year text box private JButton btnReport; //the Report button private JTextArea IblAgeReport; //reporting name, age and classification label /* the constructor method */ public PersonGUI () { setTitle("Person GUI program"); setDefaultCloseOperation (EXIT_ON_CLOSE); /* the constructor method */ public PersonGUI () { setTitle("Person GUI program"); setDefaultCloseOperation (EXIT_ON_CLOSE); setSize(250, 200); set Layout(new FlowLayout()); //initialize the GUI components lblName = new JLabel("Enter the name: "); txtName = new JTextField(10); lblYear = new JLabel("Enter the year: "); txtYear = new JTextField(10); btnReport = new JButton ("Report age and classification"); 1blageReport = new JTextArea(5,20); 161AgeReport.setEditable(false); //add those components to the form add(lblName); add(txtName); add(lblYear); add(txtYear); add(btnReport); add(lblAge Report); //make the form visible setVisible(true); //make the form visible setVisible(true); //TODO: register event handler of "Report" button } /* the main method */ public static void main (String args[]) { new PersonGUI(); } /* handle user click events */ @Override public void actionPerformed (ActionEvent e) { //Implement the event when user click on the Report button //Check if "Report" button was clicked if(e.getSource() == btnReport) { //TODO: clear the text in the lblAgeReport by calling setText method with empty string //TODO: call the append() method of lblAgeReport to show the Name // remember to put new line character at the end //TODO: create a String variable that get the year entered by user (txtYear) //TODO: use Integer.parseInt with above String variable to get the birth year (integer variable) //TODO: calculate the age and store as an integer variable I/TODO: use Integer.parseInt with above String variable to get the birth year (integer variable) //TODO: calculate the age and store as an integer variable //TODO: call the append() method of lblAgeReport to show the Age //TODO: if-else statement to check the age and report the age classification // by appending to the lblAgeReport } } } Check the following section for the detailed specifications of your program. 2.2 Class Design Specification 1. The name of the class is called Person GUI (also means the file name is PersonGUl.java) 2. The class has the following GUI components: lblName, txtName, Ib Year, txtYear, btnReport, IblAge Report 3. The class has three methods: a. PersonGUI(): This constructor method creates the required GUI components, add them to the forms, and register the button click events handler. This method is almost completed. b. action Performed(ActionEvent e): This method will handle the event when user clicks 3. The class has three methods: a. PersonGUI(): This constructor method creates the required GUI components, add them to the forms, and register the button click events handler. This method is almost completed. b. actionPerformed(ActionEvent e): This method will handle the event when user clicks on the "Report" button. You need to implement this method to fulfil the program. C. main(): This method simply create the instance of PersonGUI to show the form. This method has been completed. Below is the sample outputs of the program Person G... Person G... Enter the name: Enter the name: Test Person 1 Enter the year: Enter the year: 2005 Report age and classification Report age and classification Name: Test Person 1 Age: 15 Classification: Minor Person G... Person G... X Enter the name: Test Person 3 Enter the name: Test Person 2 Enter the year: 1995 Enter the year: 1945 Report age and classification Report age and classification Name: Test Person 3 Name: Test Person 2 Age: 25 Classification: Adult Age: 75 Classification: Senior o Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation Submission You need to submit the following results: 1. Capture the outputs in Eclipse Console or pop-up windows for the above 2 parts using screenshot. Put the captured images in a PDF file called output.pdf. 2. Source code: Submit exported project Assignment2 folder (DO NOT compress it into .zip) containing the above Age Classifier.java and PersonGUl.java files to your /your_name/assignment2 folder in your class storage. Requirements Write your own code. Write the clean code. Your submitted code should be run successfully without any syntax errors. . Your code can correctly solve the problem in the lab description, and meanwhile do not add unnecessary lines of code that are not required in the lab description. Your code can output the correct results. . Assignment Tasks Note: Students can start to work now on partial tasks. Other tasks need the knowledge in 2/22 lecture. After we cover 2/22 lecture, you can complete the leftover tasks in the entire assignment. Part1: 1.1 Problem Descriptions Complete the missing code of a Java program which receives the user inputs of name and the year of birth and reports the person's age and classification (minor, adult, or senior). The following code you need to complete is described as following (the missing code items are denoted by TODO comment: public class AgeClassifier { private String name; //the name private int birthYear; //the year /* the constructor method */ public AgeClassifier (String sName, int year ) { name = sName; birthYear = year; } /* this method return the age */ public int getAge() { //TODO: add missing code to calculate and return the age of the person /* this method return the age */ public int getAge() { //TODO: add missing code to calculate and return the age of the person } /* this method return the age classification*/ public String getAgeClassification(int age) { //TODO: add missing code to classify //the input age into three types: minor, adult, and senior } public static void main(String args []) { Scanner user_inputs = new Scanner(System.in); System.out.print("Enter the name: "); String name = user_inputs.nextLine(); System.out.print("Enter the year of birth: "); int year = user_inputs.nextInt(); 1/TODO: add missing code below to print the name, age //and the age classification of that person } } Check the following section for the detailed specifications of your program. 1.2 Class Design Specification } Check the following section for the detailed specifications of your program. 1.2 Class Design Specification 1. The name of the class is called Age Classifier (also means the file name is Age Classifier.java) 2. The class has one integer variable birthYear to store the year of birth and one String variable name to store the name of the person 3. The class has four methods: a. AgeClassifier(String sName, int year): This constructor method has two input arguments to initialize the values of name and birthYear. This method is already completed. b.getAge(): This method calculate and return the age of the person. C. getAgeClassification(int age): This method receives an input (age) and return a String that denotes the age classification. There are three categories: "Minor" if the age is less than or equals to 19 "Adult" if the age is between 20 and 65 - "Senior" if the age is greater than 65 d. main(): This method will create at least one instance of the Age Classifier class with two inputs from the user by using Scanner class. Then you should use System.out.println to print the name, age, and the age classification of the user. Below is the sample outputs of the program . Enter the name: Test Person Enter the year of birth: 1996 Name. Test Person een 20 arid 65 Il the age is - "Senior" if the age is greater than 65 d. main(): This method will create at least one instance of the Age Classifier class with two inputs from the user by using Scanner class. Then you should use System.out.println to print the name, age, and the age classification of the user. Below is the sample outputs of the program Enter the name: Test Person Enter the year of birth: 1996 Name: Test Person Age: 24 years old Age classification: Adult Enter the name: Test Person 1 Enter the year of birth: 2005 Name: Test Person 1 Age: 15 years old Age classification: Minor 1.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beginning of your Java class file, specify the following items: o Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application 1.3 Program Design and Good Coding Style Requirements Your source code must be properly indented and contain adequately comments for class, methods, variables, etc. In the beginning of your Java class file, specify the following items: Your name, the assignment number for this program, the date you create the file The problem description that defines your application Enumerate (list) the goals of your application Enumerate (list) the inputs of your application Enumerate (list) the outputs of your application Before each method in your class, specify the following items: Specify the purpose of the corresponding method Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation o Part2: 2.1 Problem Descriptions Complete the missing code of a Java GUI program which is the GUI extension of above Part1. This program let user enter the name and birth year. There is a button named "Report" that report the age and classification of the user. The following code you need to complete is described as following the missing code items are denoted by TODO comments: Part2: 2.1 Problem Descriptions Complete the missing code of a Java GUI program which is the GUI extension of above Part1. This program let user enter the name and birth year. There is a button named "Report" that report the age and classification of the user. The following code you need to complete is described as following (the missing code items are denoted by TODO comments: import java.awt. FlowLayout; import javax.swing.JButton; import javax.swing. JFrame; import javax.swing. JLabel; import javax.swing. JTextArea; import javax.swing.JTextField; ublic class PersonGUI extends JFrame ements ActionListener { private JLabel lblName; //the name label private JTextField txtName; //the name text box private JLabel lblYear; //the year label private JTextField txtYear; //the year text box private JButton btnReport; //the Report button private JTextArea IblAgeReport; //reporting name, age and classification label /* the constructor method */ public PersonGUI () { setTitle("Person GUI program"); setDefaultCloseOperation (EXIT_ON_CLOSE); /* the constructor method */ public PersonGUI () { setTitle("Person GUI program"); setDefaultCloseOperation (EXIT_ON_CLOSE); setSize(250, 200); set Layout(new FlowLayout()); //initialize the GUI components lblName = new JLabel("Enter the name: "); txtName = new JTextField(10); lblYear = new JLabel("Enter the year: "); txtYear = new JTextField(10); btnReport = new JButton ("Report age and classification"); 1blageReport = new JTextArea(5,20); 161AgeReport.setEditable(false); //add those components to the form add(lblName); add(txtName); add(lblYear); add(txtYear); add(btnReport); add(lblAge Report); //make the form visible setVisible(true); //make the form visible setVisible(true); //TODO: register event handler of "Report" button } /* the main method */ public static void main (String args[]) { new PersonGUI(); } /* handle user click events */ @Override public void actionPerformed (ActionEvent e) { //Implement the event when user click on the Report button //Check if "Report" button was clicked if(e.getSource() == btnReport) { //TODO: clear the text in the lblAgeReport by calling setText method with empty string //TODO: call the append() method of lblAgeReport to show the Name // remember to put new line character at the end //TODO: create a String variable that get the year entered by user (txtYear) //TODO: use Integer.parseInt with above String variable to get the birth year (integer variable) //TODO: calculate the age and store as an integer variable I/TODO: use Integer.parseInt with above String variable to get the birth year (integer variable) //TODO: calculate the age and store as an integer variable //TODO: call the append() method of lblAgeReport to show the Age //TODO: if-else statement to check the age and report the age classification // by appending to the lblAgeReport } } } Check the following section for the detailed specifications of your program. 2.2 Class Design Specification 1. The name of the class is called Person GUI (also means the file name is PersonGUl.java) 2. The class has the following GUI components: lblName, txtName, Ib Year, txtYear, btnReport, IblAge Report 3. The class has three methods: a. PersonGUI(): This constructor method creates the required GUI components, add them to the forms, and register the button click events handler. This method is almost completed. b. action Performed(ActionEvent e): This method will handle the event when user clicks 3. The class has three methods: a. PersonGUI(): This constructor method creates the required GUI components, add them to the forms, and register the button click events handler. This method is almost completed. b. actionPerformed(ActionEvent e): This method will handle the event when user clicks on the "Report" button. You need to implement this method to fulfil the program. C. main(): This method simply create the instance of PersonGUI to show the form. This method has been completed. Below is the sample outputs of the program Person G... Person G... Enter the name: Enter the name: Test Person 1 Enter the year: Enter the year: 2005 Report age and classification Report age and classification Name: Test Person 1 Age: 15 Classification: Minor Person G... Person G... X Enter the name: Test Person 3 Enter the name: Test Person 2 Enter the year: 1995 Enter the year: 1945 Report age and classification Report age and classification Name: Test Person 3 Name: Test Person 2 Age: 25 Classification: Adult Age: 75 Classification: Senior o Enumerate the possible inputs and outputs of the corresponding method o Write down the pseudocode to implement the corresponding method Others comments if need for variables, inside method implementation Submission You need to submit the following results: 1. Capture the outputs in Eclipse Console or pop-up windows for the above 2 parts using screenshot. Put the captured images in a PDF file called output.pdf. 2. Source code: Submit exported project Assignment2 folder (DO NOT compress it into .zip) containing the above Age Classifier.java and PersonGUl.java files to your /your_name/assignment2 folder in your class storage. Requirements Write your own code. Write the clean code. Your submitted code should be run successfully without any syntax errors. . Your code can correctly solve the problem in the lab description, and meanwhile do not add unnecessary lines of code that are not required in the lab description. Your code can output the correct results

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

Step: 3

blur-text-image

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions