Page 1 of 7 ICT167 Principles of Computer Science TM, 2020 Assignment 1 (worth 20% of unit assessment) Due Date: Midnight, Saturday (Teaching Week 7) All Students: Submit the Assignment via LMS by the...

1 answer below »
Assignment is uploaded as a pdf document


Page 1 of 7 ICT167 Principles of Computer Science TM, 2020 Assignment 1 (worth 20% of unit assessment) Due Date: Midnight, Saturday (Teaching Week 7) All Students: Submit the Assignment via LMS by the due date. Late penalty: 10% per day penalty for delayed submissions unless prior extension of deadline is obtained from the unit coordinator. You should keep a copy of your work. Your submission must include a completed assignment cover sheet. An electronic copy of the assignment cover sheet is available at the unit LMS site. This assignment consists of one question. All parts of the question should be attempted. Read and understand the information at: http://our.murdoch.edu.au/Educational- technologies/What-you-need-to-know/ References and Pre-requisites: • You will need to familiar yourself with materials covered in Topics 1 to 6 for this assignment. • Lab Practices 1 to 5 have been attempted, even if not submitted. • Textbook Chapters 1 to 7 If you are unsure of anything about the assignment question, you need to get clarification early. Read this document very carefully and start to discuss with your lecturer. OBJECTIVES: • Construct algorithms to solve problems using a combination of sequence, selection and iteration constructs. • Apply the Object-Oriented design paradigm to construct solutions in a modular way. • Implement such a design using the JAVA programming language. • Demonstrate the basic understanding of using array. • Searching in the array of class objects. Worth: This assignment is worth 20% of the total assessment for the unit. This is an individual assignment and must be completed by you alone. Any unauthorised collaboration/collusion may be subject to investigation and result in penalties if found to be in breach of University policy. Page 2 of 7 Question This question reinforces concepts from Lab Practices 1 - 5. Best practice of Class and Method design should be demonstrated. This will require a good understanding of class design concepts and method design concepts: code re-use, high cohesion and low coupling. Before attempting this question, complete the pre-requisites listed on the first page of this document. Assignment 1 uses O-O design implemented in Java. You will need to use a user-defined class, as an array of such class objects will be required. User-defined Class: You will design and implement your own class. The class will store data that has been read as user input from the keyboard (see Getting Input below), and provide necessary operations. As the data stored relates to monetary change, the class should be named Change. The class requires at least 2 instance variables for the name of a person and the coin change amount to be given to that person. You may also wish to use 4 instance variables to represent amounts for each of the 4 coin denominations (see Client Class below). There should be no need for more than these instance variables. However, if you wish to use more instance variables, you must provide legitimate justification for their usage in the internal and external documentation. Your class will need to have at least a default constructor, and a constructor with two parameters: one parameter being a name and the other a coin amount. Your class should also provide appropriate get and set methods for client usage. Other methods may be provided as needed. However, make sure they are necessary for good class design; you must provide legitimate justification for their usage in the internal and external documentation. In particular, your class should NOT include Input and Output methods. The only way to get data out of a class object to the client program is to use an appropriate get method. The class methods must not write data out. Data should be entered into a class object via a constructor or an appropriate set method. When designing your Change class, use an UML diagram to help understand what the class design needs. Getting Input: Input for the client program will come from keyboard (entered by the user). The input should consist of: the name of a person, and a coin value (as an integer). The program should validate the input coin value to ensure that it is in the range 5 to 95, and is evenly divisible by 5. Names are one-word strings. You should ask the user to enter the required information using a loop with a question after each loop iteration to check if the user wants to end the input of data. It is recommended for the user to input at least 8 such data – this can be conveyed to the user using a message before entering the loop. NOTE: for the purpose of testing the program by your tutor, you should provide a method in the client class that hardcodes data into at least 8 Change objects and stores these objects into the array provided by your program. In this case, your tutor would not need to manually key in the data to test the program when assessing your work. Thus, you should provide a call to this method (commented out) in the main function; this can be uncommented by your tutor as needed. Page 3 of 7 Example of inputs as follows: Recommendation: Please enter at least 8 records to test the program. Please enter the name of the person: Jane Please enter the coin value for the person (range 5 to 95, multiple of 5): 30 Do you have more person to enter (Y/N): Y Please enter the name of the person: John Please enter the coin value for the person (range 5 to 95, multiple of 5): 50 Do you have more person to enter (Y/N): Y Please enter the name of the person: Fred Please enter the coin value for the person (range 5 to 95, multiple of 5): 94 Incorrect coin value. Must be in the range 5 to 95, and multiple of 5. Please enter the name of the person: Wilma Please enter the coin value for the person (range 5 to 95, multiple of 5): 100 Incorrect coin value. Must be in the range 5 to 95, and multiple of 5. Please enter the name of the person: Jane Please enter the coin value for the person (range 5 to 95, multiple of 5): 35 Do you have more person to enter (Y/N): Y … (assuming this is repeated at least 8 times) Do you have more person to enter (Y/N): N … (go out of the loop) Page 4 of 7 Client Class: The client program should read the input data from the user (or the method with hardcoded inputs) and use the Change class to store the data entered. This data should be stored in a Change class object. You will need a data structure to store the Change class objects according to the number of persons entered. Thus, you are to utilize an array of Change objects. It should be noted that it is possible to have the same name repeated numerous times when the input is entered, but the coin values for such repetitions could be different. When the name is the same, it would mean the same individual, and your program should add up the coin amounts to obtain a total amount for that individual; this should be performed before computing the change to be given. Note that in this scenario, the total amount for an individual may end up being over 100, 200, 300, or more cents. Make sure you have hardcoded cases of the above for your tutor to test for these situations. Processing would involve determining repeated names and accumulating the total for those repeated names. You must ensure that there are no objects with repeated names in the array. Then methods would need to be called to calculate the required output corresponding to the coin amounts stored in the array of objects. Output change values must consist of the following denominations: 50, 20, 10 and 5 cents. The program should aim to give as much of the higher valued coins as possible. A poor solution for an input of 30 cents is to give six 5 cent coins. The better solution is to give a 20 cent coin and a 10 cent coin. Once the above has been completed, your program should then display a menu screen as illustrated below. The program will continue to show the menu and execute the menu options until "Exit" is selected by entering the value 5 at the menu prompt. 1. Enter a name and display change to be given for each denomination 2. Find the name with the smallest amount and display change to be given for each denomination 3. Find the name with the largest amount and display change to be given for each denomination 4. Calculate and display the total number of coins for each denomination, and the sum of these totals 5. Exit When the user enters the value 1 at the menu prompt, your program will ask for a name. As an example, if the user enters the name Jane (as in the example input above), the program will output: Customer: Jane 65 cents Change: 50 cents: 1 10 cents: 1 5 cents: 1 N.B. change values of 0 are not shown for screen output. Page 5 of 7 If the user enters a non-existent name (eg: Donald) at menu option 1, which would therefore not be in the array of objects, your program will print: Name: Donald Not found After processing the output for menu option 1, the menu is re-displayed. When the user enters 2 at
Answered Same DayMay 26, 2021ICT167Murdoch University

Answer To: Page 1 of 7 ICT167 Principles of Computer Science TM, 2020 Assignment 1 (worth 20% of unit...

Shivani answered on May 30 2021
140 Votes
import java.util.*;
class Client
{
    public static void main(String[] args)
    {
        int MIN_DATA = 8;
        char user_res = 'Y';
        String p_name;
        int p_change, ctr=0
, chk_exists=0, total_amount=-1;
        
        Change clients[] = new Change[20];
        
        Scanner sc= new Scanner(System.in);
        Scanner sc1= new Scanner(System.in);
        
        System.out.println("Recommendation: Please enter at least " + MIN_DATA + " records to test the program.");
        do
        {
            // User input for name
            System.out.println("\nPlease enter the name of the person:");
            p_name = sc.nextLine();
            
            // User input for coin change amount
            System.out.println("Please enter the coin value for the person (range 5 to 95, multiple of 5)");
            p_change = sc1.nextInt();
            
            // validating the change amount input
            if(p_change <5 || p_change >95 || !(p_change%5 == 0))
            {
                System.out.println("Incorrect coin value. Must be in the range of 5 to 95, and multiple of 5.");
                continue;
            }
            
            // checking if a user with the same name already exists
            chk_exists = 0;
            for(int chk_ctr=0;chk_ctr            {
                if(clients[chk_ctr].getName().equals(p_name))
                {
                    // updating the coin change amount value for the existing user
                    clients[chk_ctr].setChange(clients[chk_ctr].getChange()+p_change);
                    chk_exists=1;
                    break;
                }
            }
            
            // if the user does not already exists, adding a new user
            if(chk_exists == 0)
            {
                clients[ctr]=new Change();
                clients[ctr].setName(p_name);
                clients[ctr].setChange(p_change);
                ctr++;
            }
            
            System.out.println("Do you have more person to enter (Y/N)?");
            user_res =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here