20245 Java Assignment -1, 2019

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4462760071454301"

Term 3, COIT20245, 2019 Introduction to Programming COIT 20245 Assessment item 1—Java Console Program

The answer to this question is after the question

This assessment item relates to the course learning outcomes as in the Unit Profile.
For this assignment, you are required to develop a Java Console Program to demonstrate you can use Java constructs including input/output via a command line, Java primitive and built-in data types, Java defined objects, selection and looping statements, methods, and various other Java commands. Your program must produce the correct results.
You are only allowed to use techniques that have been covered in the first six weeks of the course, you must use the Scanner object for input and no advanced data structures like arrays will be used. Instructions for this appear in the implementation section of this specification.
What to submit for this assignment
The Java source code:
o RockyCatering.java
A report including a flow chart (UML activity diagram) to depict your validation loop for reading the number of guests, how long it took to create, any problems encountered, and screenshots of the output produced. (Use Alt-PrtScrn to capture just the console window and you can paste it into your Word document). You should test every possibility in the program.
Important: For this assignment, you are required to paste your source code as an appendix into your report, do not worry about the formatting loss.
o ReportAss1.docx
You will submit your files by the due date using the “Assignment 1 Submission” link on the Moodle unit website in the Assessment Block or in the relevant week.

Assignment specification
Rocky Catering Service program.
Rocky Catering Service is a company that delivers a buffet menu for customers in the Rockhampton area. For simplicity, the details of the meals are omitted here.
The management of Rocky Catering Service is requesting a program that allows staff to input a customer’s name and the number of guests to be catered for, compute the cost of the meal and produce some statistics.
The minimum number of guests to be catered for will be ten guests.
The standard charge per guest will be $29.50 per head, to encourage more guests to be booked there will be a discount for larger groups the pricing scheme is as follows:
Ten to twenty guests will be $29.50 per head.
Twenty-one to forty guests will be the cost of twenty guests (at $29.50 per head) $590.00 plus $24.50 per head after that.
Over forty guests will be the cost of forty guests $1,080.00 plus $19.50 per head after that.
You are to write a Java Console Application (RockyCatering.java) which will allow employees to enter the details of N booking names and the number of guests for each booking. N should be equal to the highest digit in your student ID, use N=3 if your highest digit is less than three. For each booking the program will prompt for and accept the booking name and the number of guests for the booking, it will then display the charge (see sample output below for formatting details).
When all the bookings have been entered you need to report the maximum and minimum number of guests per booking and the relevant booking name, the average number of guests per booking and the total charges which have been collected.
The required Java Console Application should allow the user to:

  1. For each of the N bookings: enter the Booking name, and then enter the Number of guests. The program will output the charge for the booking. All dollar values will be formatted to two decimal places (see implementation below with help for doing this).
  2. You must ensure the booking name is not blank so you must implement a validation loop so a booking name is entered. The number of guests must be greater than or equal to ten and you will also need to implement a validation loop so a valid number of guests are entered.
    The program will number each booking in the input prompt.
  3. When N bookings have been entered, you will output a heading for the statistics “Statistical information for Rocky Catering Service”, the minimum and maximum number of guests in the booking groups and the booking name with these minimums and maximums, and then what the average number of guests per booking is (formatted to two decimal places) (see sample output below). Note: If more than one booking has an equal maximum or minimum guests you just need to only output one booking name.
  4. Display a welcome message at the beginning “Welcome to the Rocky Catering Service Management System” and an end message e.g. “Thank you for using the Rocky Catering
    COIT20245, 2019 Term Three – Page 3 of 5
    Service Management System” and the final line “Program written by ” (see sample output below).
    The numeric literal values N, number of guests for the different discount levels and meal costs must be represented as constants.
    A large number of students have never written a program before so this is a fairly simple assignment which can be written in the main method of your class. Follow the steps outlined here and build your program up in a step by step fashion and always compile your program at each stage so you are always working on error-free code.
    Start by creating your RockyCatering class which will contain just the main method, COMPILE! (Fix any errors and repeat)
    Implement the welcome message, COMPILE and RUN!
    Declare your Scanner object(s), COMPILE!
    Note: In order to combat the problem of the Scanner objects reading both textual and numeric data a good way to counter this is to declare two Scanner objects, one for reading text and another for reading numbers, or you can clear the buffer after the int read using nextLine()
    Create a loop to loop N Times, COMPILE! (use N = 3 for development)
    Declare variables to hold the booking name and the number of guests (String and int), COMPILE!
    Within the loop: prompt and read the booking name, COMPILE and RUN!
    Add the prompt and read for the number of guests, COMPILE and RUN!
    Calculate the meal charges using the pricing structure above, COMPILE, RUN and TEST until this is correct.
    Output the description of the transaction (see sample output below)
    Output all dollar values and average to two decimal places:
    USE: System.out.printf(“%.2f”, charge);
    Add the validation loops for reading the data (you can do this last if you like)
    Use if statements to determine if the number of guests is maximum or minimum, (you will have to think about this). Output the minimum and maximums after the loop, COMPILE and RUN until you have this correct. You may want to set your original max and min variables to very small and very large numbers using Integer.MIN_VALUE and Integer.MAX_VALUE.
    You will need to add up the number of guests as you go so you can calculate the average.
    After the loop, you will output the statistics which you have gathered in the loop. You should have the maximum and minimum number of guests and the corresponding booking names and the total amount of charges collected.
    Calculate the average number of guests per booking.
    Output the statistics as indicated in the screen shot below.
    COIT20245, 2019 Term Three – Page 4 of 5
    Finally, print the end message.
    Your program should be well laid out, commented and uses appropriate and consistent names (camel notation) for all variables and objects.
    For this assignment, you will not worry about checking data types.
    Refer to a Java reference textbook and the unit and lecture material (available on the course WEB
    site) for further information about the Java programming topics required to complete this assignment.
    Check the marking guide (last page) to ensure you have completed every task. You need to match the output as shown below.

    Marking Scheme Marks allocated Total number of marks – 20 Variables, constants and types Constant N is used correctly and is largest digit of student ID 0.5 Constants are used for all numeric literals (no hard-coded values) 0.5 Variables have meaningful names and use camel notation 0.5 Variables are the correct type 0.5 Code in general Code is indented and aligned correctly 0.5 Code has header comment which includes student name, student ID, date, file name and purpose of the class 0.5 Code is fully commented including all variables 0.5 Input Numbers and strings are read correctly 0.5 Validation loop for booking name is correct 1 Validation loop for number of guests is correct 1 Processing if statements are correct 0.5 looping is correct i.e iterates N times 0.5 Output Output is formatted correctly (resembles sample output) 1.75 Correct charge per booking is correct 1.75 Minimum guests and booking name are correct 1 Maximum guests and booking name are correct 1 Average guests per booking is correct 1 Total charges is correct 0.5 Average and dollar values formatted to two decimal places 1 Welcome and exit message (with student ID) are displayed 0.5 General Correct files submitted including types and names 1 Only techniques covered during weeks 1-6 are used 1 Report Flow chart is correct 1 Screen shot(s) of testing and annotations 0.5 Report presentation and comments including how long it took and any problems encountered 0.5 Source code has been included as an appendix 0.5


Introduction To Programming

COIT20245, Term1, 2019
Assessment 1 – Java Console Program

Lecturer: xxxxxx

Tutor:  xxx  

Prepared by:

Name: xxxxx

Student Number: xxxxx

Due Date: xxxxxx

Table of Contents

Introduction. 3

System Flowchart. 3

Problem Encountered. 4

Duration:. 5

Appendix. 6


This report clearly presents the idea of making a java console program that accepts the input from the user to calculate maximum, minimum, and average values. This report includes all the methods that I have done to prepare a program that calculates the above value. It includes the flowchart, the UML diagram, and the problem faced during the programming. I have used all the materials or coded from the study materials provide up to week 6.

System Flowchart

System Flowchart

                Figure: Flowchart

Problem Encountered

I wrote input.nextline() to solve this error.

Output for calculation of Fares
Test CaseExpectation Of ResultActual Result
Validation Of CustomerCustomer should be more than 10 Customer booking should be 10 or more or within a certain range.
Booking NameBooking Name should be a valid stringBooking name consists of string.


It took 7 hours for me to code the entire program.



 *Program written by student: Nabin Jamkatel

 *Student Id : 12120752

 *Date: 6 January 2020

 * File Name: RockyCtaering.java

 * Purpose of the class: To show the use of Java console in this program we show the total number of bookings of the

   guests and calculate the maximum and minimum and average number of guests


import java.util.Scanner; //importing the scanner to use scanner in the program

public class RockyCatering { // declaring the class


     * @param args the command line arguments


    public static void main(String[] args) { // declaring main statement

        Scanner input; // scanner variable to take input from the user.

        final int N = 7; // initializing variable N as the largest digit in my student id(12120752) i.e.

                         // 7.

        int guestNumber = 0; // initialized he gust number as 0.

        String guestName1; // name of the guest will be stored in this varible.

        double guestCharge = 0.0; // initialized guest chrge.

        double aveg = 0; // to store the average value.

        double aveguest = 0; // initializing average guest.

        double guestCharge1 = 0; //

        int largest = Integer.MIN_VALUE; // to store the largest value.

        int smallest = Integer.MAX_VALUE; // to store the minimum vaue.

        final double CHARGE_TILL_20_GUESTS = 590.00; // charge of 20 guests.

        final double CHARGE_TILL_40_GUESTS = 1080.00; // charge of 40 guests.

        int guestDiff = 0; // declring the guest difference.

        System.out.println(“Welcome to Rocky Catering Service Management System \n \n”); // Printing welcome message

        for (int i = 1; i < N; i++) {

            input = new Scanner(System.in);

            do {

                System.out.printf(“Please Enter Booking Name %d ==> “, i);// prints please enter booking name to the

                // user.

                guestName1 = input.nextLine();

                if (guestName1.trim().isEmpty()) { // omits the space.

                    System.out.println(“Error booking name cannot be blank”);// if booking name is blank it prints

                                                                             // error

                                                                             // booking name cannot be blank.


            } while (guestName1.trim().isEmpty());

            do {

                System.out.printf(“Please Enter Number of guest for ” + guestName1 + “==>  “);

                guestNumber = input.nextInt();

                if (guestNumber < 10) {

                    System.out.println(“Error number of Guests must be Greater than or equal to 10”);


            } while (guestNumber < 10);

            if (guestNumber <= 20) {

                guestCharge = guestNumber * 29.50;

            } else if (guestNumber > 20 && guestNumber <= 40) { // Checks if the guest number entered is in

                                                                // between 20 and 40

                guestDiff = guestNumber – 20;

                guestCharge = CHARGE_TILL_20_GUESTS + guestDiff * 24.50;

            } else if (guestNumber > 40) {

                guestDiff = guestNumber – 40;

                guestCharge = CHARGE_TILL_40_GUESTS + guestDiff * 19.50;


            System.out.printf(“The tour charges for %s for %d guest is ==> $%.2f  \n \n”, guestName1, guestNumber,


            if (guestNumber >= largest) {

                largest = guestNumber;


            if (guestNumber <= smallest) {

                smallest = guestNumber;


            guestCharge1 = guestCharge1 + guestCharge;

            aveg = aveg + guestNumber;


        aveguest = aveg / N;

        System.out.println(“Statistical information for Rocky Catering Service \n”);

        System.out.printf(“Booking has the minimum number of   ” + smallest + “guests\n “); // displaying the guest name

                                                                                            // with minimum guest

        System.out.printf(“Booking has the maximum number of ” + largest + “guests\n”); // displaying the guest with

                                                                                        // largest number of booking

        System.out.printf(“The average number of guests per booking is:  ” + aveguest + ”  guests\n”);// Displaying the

                                                                                                      // average number

                                                                                                      // f guests

        System.out.printf(“The total charges collected is” + guestCharge1 + “\n\n\n”);

        System.out.println(“Thank you for using Rocky Catering service Management System\nProgram written by 12120752”);