Advertisement
illpastethat

CheapPizza.java

Jan 11th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.util.*;
  2.    import java.io.*;
  3.  
  4.     public class CheapPizza {
  5.        public static void main (String[] args) throws FileNotFoundException {
  6.          Scanner read = new Scanner(new File("C:\\Users\\1307320\\Desktop\\pizzas.txt"));
  7.          int x = 1;
  8.          double cost = 0;
  9.          double maxcost = 99;
  10.          String maxtopping = "";
  11.          String topping = "";
  12.          int size = 0;
  13.          int maxsize = 0;
  14.          search:
  15.          while (read.hasNext()) {
  16.             if (x == 1) {
  17.                topping = read.next();
  18.                x = x + 1;
  19.             }
  20.             else if (x == 2) {
  21.                size = read.nextInt();
  22.                x = x + 1;
  23.             }
  24.             else if (x == 3) {
  25.                cost = read.nextDouble();
  26.                x = 1;
  27.                if (cost < maxcost) {
  28.                   maxcost = cost;
  29.                   maxtopping = topping;
  30.                   maxsize = size;
  31.                }
  32.             }
  33.          }
  34.          System.out.println("The cheapest pizza: The " + maxsize + " inch " + maxtopping + " pizza will cost $" + maxcost);
  35.          //Output: The cheapest pizza: The 40 inch pineapple pizza will cost $33.0
  36.       }
  37.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement