-1
package project;

import java.util.ArrayList;
import java.util.Scanner;

public class project {

public static void main(String[] args) {
    // TODO Auto-generated method stub


    //Setting up scanner
    Scanner input = new Scanner(System.in);
    //Variable to allow user to quit input
    String quit = "done";


    //Constants
    double salesTax = 0.11;

    double spagPrice = 7;
    double ramenPrice = 4;
    double pepperPrice = 9;
    double steakPrice = 12;
    double tunaPrice = 6;

    //Constants for loop
    double listTime = 1;
    double listMax = 10;

    //Variable for loop
    double itemEntry = 0;
    //Keeps running total of item prices    
    double priceAdd = 0;

    //Initializes array lists
    ArrayList<String> itemList = new ArrayList<String>();
    ArrayList<Integer> priceList = new ArrayList<Integer>();
    ArrayList<Integer> buyList = new ArrayList<Integer>();
    ArrayList<String> buyitemList = new ArrayList<String>();


    //Adds food names to the correct array
    itemList.add("Spaghetti Tacos");
    itemList.add("Ramen Pizza");
    itemList.add("Stuffed Bell Pepper");
    itemList.add("Mushroom Steak");
    itemList.add("Tuna Suprise");

    //Adds prices to the price array
    priceList.add(7);
    priceList.add(4);
    priceList.add(9);
    priceList.add(12);
    priceList.add(6);



    System.out.println("Please enter a number to indicate your desired item. 
Type 'done' when you are done or enter up to 10 items.");

    System.out.println(" " + "1" + " " + " " + " " +  "2" + " " + " " + " " + 
"3" + " " + " " + " " + "4" + " " + " " + " " + "5");
    System.out.println(itemList);
    System.out.println("Prices: " + priceList);

    orderEntry (quit, listTime, listMax, priceAdd, buyitemList);


    /** while (quit != "done" || listTime <= listMax)
     {

         System.out.println("Please enter item " + listTime + " :");
         itemEntry = input.nextInt();

         if (itemEntry == 1){
             priceAdd = spagPrice;
             buyitemList.add("Spaghetti Tacos");

         }
         else if (itemEntry == 2){
             priceAdd = ramenPrice;
             buyitemList.add("Ramen Pizza");
         }
         else if (itemEntry == 3){
             priceAdd = pepperPrice;
             buyitemList.add("Stuffed Bell Pepper");
         }
         else if (itemEntry == 4){
             priceAdd = steakPrice;
             buyitemList.add("Mushroom Steak");
         }
         else if (itemEntry == 5){
             priceAdd = tunaPrice;
             buyitemList.add("Tuna Suprise");
         }
         else {
             priceAdd = 0;

         }


         buyList.add((int) priceAdd);

         listTime += listTime;



     }
     */


    double amntTacos = 0;
    double amntPizza = 0;
    double amntPepper = 0;
    double amntSteak = 0;
    double amntTuna = 0;

    double tacoPrice = 0;
    double pizzaPrice = 0;
    double belPrice = 0;
    double mushPrice = 0;
    double suprisePrice = 0;

    public orderEntry(speTacos)
      {
        this.orderEntry = amntTacos;
      }

    public orderEntry(ramPizza)
      {
        this.orderEntry = amntPizza;
      }

    public orderEntry(belPepper)
      {
        this.orderEntry = amntPepper;
      }

    public orderEntry(musSteak)
      {
        this.orderEntry = amntSteak;
      }
    public orderEntry(tunSup)
      {
        this.orderEntry = amntTuna;
      }

    tacoPrice = spagPrice * amntTacos;

    pizzaPrice = ramenPrice * amntPizza;

    belPrice = pepperPrice * amntPepper;

    mushPrice = steakPrice * amntSteak;

    suprisePrice = tunaPrice * amntTuna;






















     System.out.println("---------------------");
     System.out.println("---------------------");

     double subTotal = 0; 
     double taxAmount = 0;
     double totalPrice = 0;

     //for (int i : buyList) {
    // subTotal = subTotal + i; 
     //}

     subTotal = tacoPrice + pizzaPrice + belPrice + mushPrice + suprisePrice;

     taxAmount = subTotal * salesTax;

     totalPrice = subTotal + taxAmount;


     System.out.println("You have chosen the following items: " + 
buyitemList);
     System.out.println("---------------------");
     System.out.println("Your Subtotal is: $" + subTotal);
     System.out.println("Your Tax amount is: $" + taxAmount);
     System.out.println("Your Final Total is: $" + totalPrice);




package project;
import java.util.ArrayList;
import java.util.Scanner;
public class orderEntry (String quit, double itemEntry, double spagPrice, 
double 
ramenPrice, double pepperPrice, double steakPrice, double tunaPrice, double 
listTime, double listMax, Scanner input, double priceAdd, ArrayList buyList) 
{

Scanner input = new Scanner(System.in);

double speTacos = 0;
double ramPizza = 0;
double belPepper = 0;
double musSteak = 0;
double tunSup = 0;

while (quit != "done" || listTime <= listMax)
 {

     System.out.println("Please enter item " + listTime + " :");
     itemEntry = input.nextInt();

     if (itemEntry == 1){
         priceAdd = spagPrice;
         speTacos = speTacos + 1;

     }
     else if (itemEntry == 2){
         priceAdd = ramenPrice;
         ramPizza = ramPizza + 1;
     }
     else if (itemEntry == 3){
         priceAdd = pepperPrice;
         belPepper = belPepper + 1;
     }
     else if (itemEntry == 4){
         priceAdd = steakPrice;
         musSteak = musSteak + 1;
     }
     else if (itemEntry == 5){
         priceAdd = tunaPrice;
         tunSup = tunSup + 1;
     }
     else {
         priceAdd = 0;

     }


     buyList.add((int) priceAdd);

     listTime += listTime;

 }


public void getSpagetti(){
    return speTacos;
}

public void getRamen(){
    return ramPizza;
}

public void getPepper(){
    return belPepper;
}

public void getSteak(){
    return musSteak;
}

public void getTuna(){
    return tunSup;
}



}

OK, trying this now. Still not quite right....

The instructions were:

A class named orderEntry should also be created with the appropriate constructor, accessor and mutator methods. As the user is entering the items they wish to order, these items should be placed into a separate array as they are ordered. Once the user is done entering items, the program should use the array to output all items that were ordered to the screen, with their prices.

1 Answers1

0

This is not a solution i would recommend, but for the sake of learning how to use methods: just put it in another class and call the method from there. Give the methods the parameters needed.

public class whileMethod(String quit, double listTime, double listMax, Scanner input, double priceAdd, ArrayList<String> buyItemList, ) {

while (quit != "done" || listTime <= listMax)
     {

         System.out.println("Please enter item " + listTime + " :");
         itemEntry = input.nextInt();

         if (itemEntry == 1){
             priceAdd = spagPrice;
             buyitemList.add("Spaghetti Tacos");

         }
         else if (itemEntry == 2){
             priceAdd = ramenPrice;
             buyitemList.add("Ramen Pizza");
         }
         else if (itemEntry == 3){
             priceAdd = pepperPrice;
             buyitemList.add("Stuffed Bell Pepper");
         }
         else if (itemEntry == 4){
             priceAdd = steakPrice;
             buyitemList.add("Mushroom Steak");
         }
         else if (itemEntry == 5){
             priceAdd = tunaPrice;
             buyitemList.add("Tuna Suprise");
         }
         else {
             priceAdd = 0;

         }


         buyList.add((int) priceAdd);

         listTime += listTime;



     }

From here u can call the method in the class:

whileMethod(and all the attributtes needed)

ITGuru
  • 115
  • 1
  • 12
  • System.out.println("Please enter a number to indicate your desired item. Type 'done' when you are done or enter up to 10 items."); System.out.println(" " + "1" + " " + " " + " " + "2" + " " + " " + " " + "3" + " " + " " + " " + "4" + " " + " " + " " + "5"); System.out.println(itemList); orderEntry (String quit, listTime, listMax, priceAdd, buyitemList); System.out.println("---------------------"); System.out.println("---------------------"); double subTotal = 0; double taxAmount = 0; Like this? – dovakiin5574 Aug 06 '18 at 13:35