You are on page 1of 10

COIT 20245

Assessment item 3—JAVA Program and Specification


Project

2
Project Description
This Java project is developed for YummyTummy Sandwiches for ordering the sandwich
types and displays the bill for each order. Along with the average bill and the number of
times each item was ordered, this project also shows the total income, order with least bill,
order with highest bill, and average bill amount. The customer must input the code for each
sandwich type and quantity for each code. When all the items have been input, a list of the
ordered sandwich types and the bill's total will be shown.

The greeting message will appear when the application launches. The menu item list will then
be shown. The user will be asked for the code for sandwich type and quantity after selecting a
menu item. The aggregated invoice will be shown once all items have been submitted. The
summary report of orders will be shown once all of the orders have been entered.

Screen shots of output with descriptions


1. The List of sandwich types are displayed

2
2. The user can order by entering the code of sandwich type and quantity required. -1
can be entered to stop ordering. Then the bill is displayed with tax.

3. After the N number of orders are done, the consolidated report showing the total
amount from N orders, minimum and maximum of N orders and average of N orders
are displayed

4. Validation of input is also done for the code of the sandwich type and quantity fields.

2
Create a marking scheme
S.No. Specifications Marks
1. Meaningful variables 2
2. Code Header 2
3. Code Indentation 2
4. Usage of Array, ArrayList 2
5. Read N entries 2
6. Formatting of results 2
7. Validation of Inputs 2
8. Defining appropriate methods 2
9. Cumulative results printed 2
10. Menu Interface 2

Appendix of source code


import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.ArrayList;
public class Project {

public static void main(String[] args) {


final int MAX_ORDER=7; // Maximum Order based on Student ID
int mini=100,maxi=999,rang=maxi-mini+1; // Variables for random order code
int count=0;
double total=0,maxiBill=0,miniBill=9999; // Variables for consolidated report
int itemcode,itemcount;
FoodMenu foodmenu=new FoodMenu(); // Object creation for FoodMenu class
FoodOrder[] foodorder=new FoodOrder[MAX_ORDER]; // Object creation for
FoodOrder class
Scanner item=new Scanner(System.in); // Declaring scanner object
// Displaying welcome message
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.println("------------->YummyTummy Sandwiches<--------------");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");

2
// Loop for getting N number of orders
while(count<MAX_ORDER)
{
System.out.println();
foodorder[count]=new FoodOrder("ORDER"+Integer.toString((int)(Math.random() *
rang) + mini)); // Creating Order Code
foodmenu.showTypes(); // Displaying menu
System.out.println("Start Order the food items(enter -1 to quit ordering)");
// Loop for getting the items of an order
while(true)
{
System.out.print("Type Item Code>> ");
itemcode=item.nextInt(); // Getting code
if(itemcode==-1) // Input validation
break;
System.out.print("Type Quantity>> ");
itemcount=item.nextInt(); // Getting Quantity
if(itemcode>0 && itemcode<=foodmenu.getTypes().length && itemcount>0) //
Input Validation
{
foodorder[count].addOrders(itemcode, itemcount, foodmenu.getTypes()); //
Adding the code and quantity to the order class
foodorder[count].setBill(foodmenu.getSandwichPrice(itemcode)*itemcount); //
Getting the price of the sandwich and adding it to the order bill
foodmenu.setSandwichQuantity(itemcode,itemcount); // Setting the number of
counts for each sandwich type
}
else if(itemcount<0) // Displying error messages
System.out.println("Error:Enter valid quantity");
else // Displying error messages
System.out.println("Error:Invalid Code");

2
}
foodorder[count].showBill(); // displying the bill of an order
total=total+foodorder[count].getFinalBill(); // Calculating total of all orders
if(foodorder[count].getFinalBill()>maxiBill) // finding the maximum bill
maxiBill=foodorder[count].getFinalBill();
if(foodorder[count].getFinalBill()<miniBill) // finding the minimum bill
miniBill=foodorder[count].getFinalBill();
count++;
}
System.out.println("");
// Displaying the summary of all N orders
foodmenu.showOrders();
DecimalFormat f = new DecimalFormat("#0.00");
// Displaying total, max, min and average bill amount
System.out.println("The Total Income is $"+total);
System.out.println("The Maximum Bill is $"+maxiBill);
System.out.println("The Minimum Bill is $"+miniBill);
System.out.println("The Average Bill is $"+f.format(total/MAX_ORDER));
System.out.println("");
// Displaying exit message
System.out.println("Hope had nice dining!!!");
System.out.println("Program Written By 12172570");

}
//Food Order class which handles the order process
public class FoodOrder {
String code;
ArrayList<String> orders;

2
ArrayList<Integer> item_count;
double total=0.0;
double total_amount=0.0;
final double tax=0.17;
// Cosntructor whic initializes the order details
FoodOrder(String orderCode)
{
this.code=orderCode;
orders=new ArrayList<String>();
item_count=new ArrayList<Integer>();
}
// Method for adding the item and quantity to the order
void addOrders(int itemCode,int count,String[] menuItems)
{
for(int i=0;i<menuItems.length;i++)
if(i==itemCode-1)
{
orders.add(menuItems[i]);
item_count.add(count);
}
}
// Method for Adding the bill amount of the order
void setBill(int price)
{
total = total+price;
}
// Method for returning the total bill amount
double getBill()
{
return total;

2
}
// Method for returning the total bill amount with tax
double getFinalBill()
{
return total+(total*tax);
}
// Method which returns the order code
String getCode()
{
return code;
}
// Method for displaying the bill of the order
void showBill()
{
System.out.println();
System.out.println("Order Code: "+code);
System.out.println("-------------------------------------------");
System.out.printf("%-10s%-25s%-18s\n", "S.No.", "Item Name", "No. of Item");
for(int i=0;i<orders.size();i++)
System.out.printf("%-10s%-25s%-18s\
n",Integer.toString(i+1),orders.get(i),Integer.toString(item_count.get(i)));
DecimalFormat f = new DecimalFormat("#0.00");
System.out.println("TOTAL BILL: $"+total);
System.out.println("FINAL BILL WITH TAX: $"+f.format(getFinalBill()));
System.out.println("------------------------------------------- ");
System.out.println();
}
}
// class for handling the sandwich types and its price
public class FoodMenu {
String[] sandwich_list;

2
int[] prices_list;
int[] frequency_list;
// Cosntructor which initializes the list of sandwiches and list of prices
FoodMenu()
{
sandwich_list=new String[]{"Veg Sandwich","Chicken Sandwich","Egg
Sandwich","Ham Sandwich","Cheese Sandwich"};
prices_list=new int[]{15,32,25,35,30};
frequency_list=new int[]{0,0,0,0,0};
}
// Method which returns list of sandwich types
String[] getTypes()
{
return sandwich_list;
}
// Method which returns list of sandwich prices
int[] getPrices()
{
return prices_list;
}
// Method which returns price of sandwich given its code
int getSandwichPrice(int itemCode)
{
return prices_list[itemCode-1];
}
// Method which sets the quantity of sandwich given its code and quantity of each order
void setSandwichQuantity(int itemCode,int itemCount)
{
frequency_list[itemCode-1]+=itemCount;
}
// Method which displays the list of sandwich with its code, name and price

2
void showTypes()
{
System.out.println("\n---------------------------------------------------");
System.out.printf("%-10s%-25s%-18s\n", "Code", "Type", "Price");
System.out.println("\n---------------------------------------------------");
for(int i=0;i<sandwich_list.length;i++)
{
System.out.printf("%-10s%-25s%-18s\
n",Integer.toString(i+1),sandwich_list[i],Integer.toString(prices_list[i]));
}
System.out.println("---------------------------------------------------\n");
}
// Method which displays the order of sandwiches with its code, name and quantity
void showOrders()
{
System.out.println("\n---------------------------------------------------");
System.out.printf("%-10s%-25s%-18s\n", "Code", "Type", "Quantity");
System.out.println("\n---------------------------------------------------");
for(int i=0;i<sandwich_list.length;i++)
{
System.out.printf("%-10s%-25s%-18s\
n",Integer.toString(i+1),sandwich_list[i],Integer.toString(frequency_list[i]));
}
System.out.println("\n---------------------------------------------------");
}
}

You might also like