These are four simple programming questions.
Microsoft Word - A2.docx DPIT111 Assignment 2 Week 4-5 Objectives Get familiar with UML class and object diagrams Distinguish pass-by-value and pass-by-reference Get familiar with class constructors Master how to implement classes and their relationships according to UML diagrams Get familiar with if statement and if-else statement Assignment 2 (12%) is marked on a scale from 0-12 marks. Important notices: This assignment is scheduled to be done in Week 4-5 (Monday 20 July - Saturday 1 August 19:00). Comments for your work can be checked on Moodle site. You may be asked questions about your code. Your marks will be deducted if you could not answer the questions presented by the assessor. 1. Students must submit all assessment tasks by the due date or penalties will be applied. No. of calendar days late Penalty 1 10% of the original mark. 2 20% of the original mark. 3 30% of the original mark. More than 3 A mark of zero will be awarded for the assessment. 2. Make sure that you include following personal information in every file, otherwise it will result in 0 points. /*------------------------------------------------------ My name: My subject code: My student number: My email address: Assignment number: -------------------------------------------------------*/ 3. Ensure each file in your submission is runnable, compiling error in your file will result in 0 points for the current question. If it is runnable, though it fails to realize all functionalities, you can get partial points for what you have done. Question 1 (4 mark): Implement a program with two classes according to the following UML diagram: REQUIREMENTS The constructor College(String, String, int, int) shall create two component objects of type StudentAccount , i.e., the first lab student and the second lab student, and initialize them using corresponding names and student numbers. The program shall create in the main() function an object of type College using its constructor with four parameters that contain names and student numbers of two students (the first lab student, the second lab student), your code should use the following given student information: 2019001 Frank White – for the 1st lab student 2019002 Jurgen Klopp – for the 2nd lab student The constructor StudentAccount(String, int) shall initialize the student’s name and student number, and store the name in the field name, store the student number in the field studentNumber. Then the main() method shall call printStudents() method to print information about the students in the following example format. Your code must work exactly as the specification and the output should be exactly the same as the output example. Example of the program output: The first lab student: Frank White 2019001 The second lab student: Jurgen Klopp 2019002 Question 2 (3 mark): Write a program to implement the class Coffee according to the following UML diagram and description so that it can display as the output example. REQUIREMENTS The program has three constructors: the first one is a default constructor, it initializes the 3 data fields (50.0, 1.5, 1.7) at default; the second initializes the 3 data fields with its three double arguments; the last one is the copy constructor. The method printNutritionInformation() takes no argument and returns nothing, it is to display the nutrition information of an object generated from the Coffee class. The displaying format is as follows: It contains … Cal energy, … g protein and … g fat per serving. The main() method is to build 3 objects from the Coffee class: the first object is built by the default constructor; the second object is built by the second constructor where parameters should be passed; the last object is built by the copy constructor where the source object is the second object. Then the nutrition information of the three objects is displayed. Your code must work exactly as the specification and the output should be exactly the same as the output example. Example of the program output: It contains 50.0 Cal energy, 1.5 g protein and 1.7 g fat per serving. It contains 72.0 Cal energy, 1.8 g protein and 1.6 g fat per serving. It contains 72.0 Cal energy, 1.8 g protein and 1.6 g fat per serving. Question 3 (2 mark) : Write a class to compute the property cost according to the following UML diagram and expressions. The area of a property is obtained from the command line arguments. REQUIREMENTS The method calcTotalCharges(double) is to calculate the total charges based on its argument which represents area and expressions required in this method are as follows: actualArea = area * RATE propertyCharge = actualArea * UNITPRICE propertyCost = propertyCharge + propertyCharge * GST The main() method should ask user to input a double number area and accordingly call the method calcTotalCharges(). Your code must work exactly as the specification and the output should be exactly the same as the output example. Two examples of the program output (the texts in bold indicate the user input): Example 1: Enter the area: 155.67 Property cost: 263.70 Example 2: Enter the area: 12.17 Property cost: 20.62 Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS Your code should ask user to input an integer number, then decide its sign and parity based on this input. Your code should use if-else statement. Your code must work exactly as the specification and the output should be exactly the same as the output example. 5 example of the program output (the texts in bold indicate the user input): Example 1: Property Please input a number: 6 6 is a positive, even number. Example 2: Please input a number: -27 -27 is a negative, odd number. Example 3: Property Please input a number: 25 25 is a positive, odd number. Example 4: Property Please input a number: -16 -16 is a negative, even number. Example 5: Property Please input a number: 0 0 is a zero, even number. Submission requirements: 1. Put the solutions to Question 1 in a text file (.txt) and upload this file to Part 1 of the submission link; put the solution to Question 2 in a text file (.txt) and upload this file to Part 2 of the submission link; put solutions to Question 3 in a text file (.txt) and upload this file to Part 3 of the submission link; put solutions to Question 4 in a text file (.txt) and upload this file to Part 4. The submission link is called Assignment 2 Submission under Week 4 Section on the subject Moodle site. 2. Submission via email is not acceptable without permission. 3. Enquiries about the marks can only be made within a maximum of 1 week after the assignment results are published. After 1 week the marks cannot be changed. Mark deductions: late submission, compilation errors, incorrect result, program is not up to spec, poor comments, poor indentation, meaningless identifiers, required numeric constants are not defined, the program uses approaches which has not been covered in the lectures. The deductions here are merely a guide. Marks may also be deducted for other mistakes and poor practices. END OF THE ASSIGNMENT