In: Computer Science
The first step in writing a software application is to determine the requirements. There is no value in writing a program that does not address the needs of the client. Requirements can be gathered in many ways, but ultimately, the requirements serve to document what the application should and should not do. After the requirements are written, the application design can be prepared, followed by the actual coding. For this project, you will gain some practice in the design phase of software development by designing a program that will meet a given set of requirements.
In this assignment you will develop a console program that simulates a restaurant menu. The project instructions are as follows:
Program Requirements:
Restaurant.java
import java.util.Scanner;
public class Restaurant {
public static void displayMenu(String[] items, double
[] prices) {
for(int i=0; i<items.length;
i++)
System.out.printf("%d. %-15s : %.2f\n", i+1, items[i],
prices[i]);
}
public static void main(String[] args) {
String[] items = {"Dhokla",
"Bhelpuri", "Tikki", "Dahi bhalla", "Chowmin", "Burger",
"Lachha Tokri", "Manchurian", "Choupsuey",
"Spring Roll"};
double [] prices = {1, 2, 3.0, 4.5,
1.2, 2.2 ,3.8, 10.2, 0.5, 5.6};
//Array to store indices of items
ordered by the customer
//If order[i] = 1, means ith item
has been ordered
int[] order = new
int[10];
//Array to store quantities of
items ordered by customer
//quantity[i] = 4 means 4 quantity
of ith item has been ordered
int[] quantity = new int[10];
String choice = "no";
Scanner scan = new
Scanner(System.in);
do {
//Display
menu
displayMenu(items, prices);
//Ask for
choice
System.out.println("Enter which item you want to include in your
order (1-10):");
int k =
scan.nextInt();
order[k-1] =
1;
//Ask for
quantity
System.out.println("Enter the quantity: ");
int q =
scan.nextInt();
quantity[k-1] =
q;
//More
items?
System.out.println("Do you want to add more item in your order?
yes/no");
choice =
scan.next();
}while(!choice.contentEquals("no"));
//Calculating total price
double sum = 0;
for(int i=0; i<order.length;
i++) {
//If ith item
has been ordered
if(order[i]!=0)
{
sum += quantity[i]*prices[i];
}
}
System.out.println("Total payment
due:" + sum);
System.out.println("Your payment:
");
double payment =
scan.nextDouble();
if(payment>sum)
System.out.println("Change: " + (payment-sum));
System.out.println("Thank you for
visiting.\nHave a nice day.");
}
}