Arrays

The program below is a menu-driven program that has just 1 choice! Brainstorm! Try adding each of the following methods:

  • Raise all the prices
  • Take an order for several items
  • Check the price of an item
  • What is the cheapest item?
  • What is the most expensive?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Fast food
package fastfood;
import java.util.*;
public class FastFood {
  public static void main(String[] args) {
    Scanner keyboard=new Scanner(System.in); 
    double[] price={1.75,1.50,0.90,1.25,3.00,3.50,2.00,1.75};
    String[] food={"hotdog","fries","soda","cookie","pizza","burger",
        "taco","shake"};
    int selection=instructions();
    switch(selection) {
        case 1: printMenu(price,food); break;
        case 3: break;
        default: System.out.println("That is not a valid choice");
    }
  }//main
  public static int instructions() {
    Scanner keyboard=new Scanner(System.in);
    System.out.println("Automatted Fast Food");
    System.out.println("For the menu, press 1");
    System.out.println("To place an order, press 2");
    System.out.println("To place an order, press 3");
    int choice=keyboard.nextInt();
    return choice;
  }//instructions
  public static void printMenu(double[] cost, String[] items) {
    System.out.printf("%-10s  %-4s%n","Item","Cost");
    for(int i=0;i<cost.length;i++){
        System.out.printf("%-10s %5.2f%n",items[i],cost[i]);
    }//loop
  }//printMenu
}//class
CODE
Output:

NEXT: Classes: Creating classes