Results 1 to 4 of 4
  1. #1
    dDarko is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default need help. problems storing and displaying multiple user input

    i am having problems storing multiple orders so i can display them i summary
    i'm really lost on this one




    Java Code:
    import java.util.Scanner;
    import java.text.DecimalFormat;
    public class PizzaMain {
    
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		
    		String input;
    		char entry;
    		double pizzaprice;
    		double cokeprice;
    		double Pizza;
    		double Coke;
    		double salestax;
    		
    		
    		pizzaprice = 9.99;
    		cokeprice = 1.99;
    		salestax = .075;
    		
    		pizzaorder pizzaorder1 = new pizzaorder();
    	
    		
    		DecimalFormat DollarFormat = new DecimalFormat("$0.00");
    		Scanner keyboard = new Scanner(System.in);
    		
    		
    		System.out.println("Enter O to place a order");
    		System.out.println("Enter S for order summary");
    		System.out.println("Enter Q to quit");
    		input = keyboard.next();
    		entry = input.charAt(0);
    		
    		
    		while (input.equalsIgnoreCase("q") != true)
    		
    	switch(entry)
    	{	
    	case 'o':
    	case 'O':
    		System.out.println("\n________ORDER________");
    		System.out.print("\nPlease enter the number of Pizzas: ");
    		pizzaorder1.order = keyboard.nextInt();
    		
    		Pizza = pizzaprice * pizzaorder1.order;
    		
    		System.out.print("\nPlease enter the number of Cokes: ");
    		pizzaorder1.getorder1 = keyboard.nextInt();
    		
    		Coke = cokeprice * pizzaorder1.getorder1;
    		
    		pizzaorder1.Orderamount = Pizza + Coke;
    		
    		pizzaorder1.Taxtotal = pizzaorder1.Orderamount * salestax;
    		
    		pizzaorder1.Amountdue = pizzaorder1.Taxtotal + pizzaorder1.Orderamount;
    		
    		System.out.print("your total is : "+ DollarFormat.format(pizzaorder1.Amountdue));
    		System.out.print("\nPlease enter the amount paid: ");
    		pizzaorder1.Amountpaid = keyboard.nextDouble();
    		
    		pizzaorder1.Changedue = pizzaorder1.Amountpaid - pizzaorder1.Amountdue;
    		
    		
    		System.out.print((pizzaorder1.order)+ " Pizzas @ 9.99:   "  + DollarFormat.format(Pizza)); 
    		System.out.print("\n");
    		System.out.print((pizzaorder1.getorder1)+"  Cokes @ 1.99:   "  + DollarFormat.format(Coke)); 
    		System.out.print("\n   Order Amount:   " + DollarFormat.format(pizzaorder1.getOrderamount()));
    		System.out.print("\n      Sales Tax:   " + DollarFormat.format(pizzaorder1.getTaxtotal()));
    		System.out.print("\n     Amount Due:   " + DollarFormat.format(pizzaorder1.getAmountdue()));
    		System.out.print("\n    Amount Paid:   " + DollarFormat.format(pizzaorder1.getAmountpaid()));
    		System.out.print("\n     Change Due:   " + DollarFormat.format(pizzaorder1.getChangedue()));
    		
    		System.out.println("\nEnter O to place a order");
    		System.out.println("Enter S for order summary");
    		System.out.println("Enter Q to quit");
    		input = keyboard.next();
    		entry = input.charAt(0);
    
    
    // this is where i am having the problem display each order
    
    		
    		break;
    	case 's':
    	case 'S':
    		System.out.println("\n________Summary________ ");		
    
    		
    		System.out.println("\n");
    		System.out.println("\nOrders for the day: "); // print every order receipt; order amount, tax etc...
    		
    		Pizza = pizzaprice * pizzaorder1.order;
    		Coke = cokeprice * pizzaorder1.getorder1;
    		
    		System.out.print((pizzaorder1.order)+ " Pizzas @ 9.99:   "  + DollarFormat.format(Pizza)); 
    		System.out.print("\n");
    		System.out.print((pizzaorder1.getorder1)+"  Cokes @ 1.99:   "  + DollarFormat.format(Coke)); 
    		System.out.print("\n   Order Amount:   " + DollarFormat.format(pizzaorder1.getOrderamount()));
    		System.out.print("\n      Sales Tax:   " + DollarFormat.format(pizzaorder1.getTaxtotal()));
    		System.out.print("\n     Amount Due:   " + DollarFormat.format(pizzaorder1.getAmountdue()));
    		System.out.print("\n    Amount Paid:   " + DollarFormat.format(pizzaorder1.getAmountpaid()));
    		System.out.print("\n     Change Due:   " + DollarFormat.format(pizzaorder1.getChangedue()));
    		
    		System.out.println("\n  Number of pizzas sold: " + pizzaorder1.order); // total number of pizza's sold for the day
    		System.out.println("\n   Number of cokes sold: " + pizzaorder1.getorder1); // total number of cokes sold for the day
    		System.out.println("\nTotal sales for the day: " + DollarFormat.format(pizzaorder1.getAmountdue())); // total sales for the day
    		System.out.println("\n           Average sale: " + DollarFormat.format(pizzaorder1.getAmountdue())); // the average sale amount for the day
    		
    		
    		
    		System.out.println("\nEnter O to place a order");
    		System.out.println("Enter S for order summary");
    		System.out.println("Enter Q to quit");
    		input = keyboard.next();
    		entry = input.charAt(0);
    		
    		
    			
    		break;
    	case 'q':
    	case 'Q':
    		if (entry == 'q') 
    		System.exit(0);
    		if (entry == 'Q')
    		System.exit(0);
    		break;
    	
    	default:
    		System.out.println("Invalid choice. Please enter O,S, or Q.");
    		input = keyboard.next();
    		entry = input.charAt(0);
    		
    		
    	
    	
    		
    
    	}
    }		
    }
    and this is my order class
    Java Code:
    public class pizzaorder {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    	}
    	int numberOfPizzas;
    	 int order;
    	 int order1;
    	 int numberOfCokes;
    	 double pizzaprice;
    	 double cokeprice;
    	 double Pizza;
    	 double Coke;
    	 double Orderamount;
    	 double salestax;
    	 double Taxtotal;
    	 double Amountdue;
    	 double Amountpaid;
    	 double Changedue;
    	public int getorder1;
    
    
    	 
    	public pizzaorder()
    	{
    		
    		pizzaprice = 9.99;
    		cokeprice = 1.99;
    		Pizza = pizzaprice * order;
    	}
    
    
    	public int getNumberOfPizzas() {
    		return numberOfPizzas;
    	}
    
    
    	public void setNumberOfPizzas(int numberOfPizzas) {
    		this.numberOfPizzas = numberOfPizzas;
    	}
    
    
    	public int getOrder() {
    		return order;
    	}
    
    
    	public void setOrder(int order) {
    		this.order = order;
    	}
    	 public int getOrder1() {
    			return order1;
    		}
    
    
    		public void setOrder1(int order1) {
    			this.order1 = order1;
    		}
    
    
    	public int getNumberOfCokes() {
    		return numberOfCokes;
    	}
    
    
    	public void setNumberOfCokes(int numberOfCokes) {
    		this.numberOfCokes = numberOfCokes;
    	}
    
    	public double getPizza() {
    		return Pizza;
    	}
    
    
    	public void setPizza(double pizza) {
    		Pizza = pizza;
    	}
    
    
    	public double getCoke() {
    		return Coke;
    	}
    
    
    	public void setCoke(double coke) {
    		Coke = coke;
    	}
    
    
    	public double getOrderamount() {
    		return Orderamount;
    	}
    
    
    	public void setOrderamount(double orderamount) {
    		Orderamount = orderamount;
    	}
    
    
    	public double getSalestax() {
    		return salestax;
    	}
    
    
    	public void setSalestax(double salestax) {
    		this.salestax = salestax;
    	}
    
    
    	public double getTaxtotal() {
    		return Taxtotal;
    	}
    
    
    	public void setTaxtotal(double taxtotal) {
    		Taxtotal = taxtotal;
    	}
    
    
    	public double getAmountdue() {
    		return Amountdue;
    	}
    
    
    	public void setAmountdue(double amountdue) {
    		Amountdue = amountdue;
    	}
    
    
    	public double getAmountpaid() {
    		return Amountpaid;
    	}
    
    
    	public void setAmountpaid(double amountpaid) {
    		Amountpaid = amountpaid;
    	}
    
    
    	public double getChangedue() {
    		return Changedue;
    	}
    
    
    	public void setChangedue(double changedue) {
    		Changedue = changedue;
    	}
    
    
    	
    }

    thank you so much for any help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dDarko View Post
    i am having problems storing multiple orders so i can display them i summary
    You would go far in helping us help you by telling us exactly what is not working. The more you tell us, the easier it is for anyone to help you.

    i'm really lost on this one
    Hope we can help you find your way through this!

    BTW, welcome to the forum!

  3. #3
    dDarko is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    sorry i should have described the problem in more detail. well the code that i posted compiles and works except for when i try to place multiple orders and display the orders in the summary part of the code. i have tried using arrays, but i can't figure out how to use an array. my book isn't any help. basically i need too place and a couple of orders and then display both the orders that were placed in the summary and the total number of pizzas total number of cokes and average sales. my summary only displays the last order that was placed.

    Java Code:
    break;
    	case 's':
    	case 'S':
    		System.out.println("\n________Summary________ ");		
    
    		
    		System.out.println("\n");
    		System.out.println("\nOrders for the day: "); // print every order receipt; order amount, tax etc...
    		
    		Pizza = pizzaprice * pizzaorder1.order;
    		Coke = cokeprice * pizzaorder1.getorder1;
    		
    		System.out.print((pizzaorder1.order)+ " Pizzas @ 9.99:   "  + DollarFormat.format(Pizza)); 
    		System.out.print("\n");
    		System.out.print((pizzaorder1.getorder1)+"  Cokes @ 1.99:   "  + DollarFormat.format(Coke)); 
    		System.out.print("\n   Order Amount:   " + DollarFormat.format(pizzaorder1.getOrderamount()));
    		System.out.print("\n      Sales Tax:   " + DollarFormat.format(pizzaorder1.getTaxtotal()));
    		System.out.print("\n     Amount Due:   " + DollarFormat.format(pizzaorder1.getAmountdue()));
    		System.out.print("\n    Amount Paid:   " + DollarFormat.format(pizzaorder1.getAmountpaid()));
    		System.out.print("\n     Change Due:   " + DollarFormat.format(pizzaorder1.getChangedue()));
    		
    		System.out.println("\n  Number of pizzas sold: " + pizzaorder1.order); // total number of pizza's sold for the day
    		System.out.println("\n   Number of cokes sold: " + pizzaorder1.getorder1); // total number of cokes sold for the day
    		System.out.println("\nTotal sales for the day: " + DollarFormat.format(pizzaorder1.getAmountdue())); // total sales for the day
    		System.out.println("\n           Average sale: " + DollarFormat.format(pizzaorder1.getAmountdue())); // the average sale amount for the day

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    OK, just a quick look at your code reveals some problems. For instance:

    Java Code:
    class pizzaorder {
    
      int numberOfPizzas;
      int order; // ** what's order?
      int order1;  // ** how is this different from order?
      int numberOfCokes;
      double pizzaprice;
      double cokeprice;
      double Pizza;  // ** what the heck is this?
      double Coke;  // ** ditto?
      double Orderamount;  // ** should be calculated value
      double salestax;  // ** should be calculated value
      double Taxtotal;  // ** should be calculated value
      double Amountdue;  // ** should be calculated value
      double Amountpaid;
      double Changedue;  // ** should be calculated value
      public int getorder1;  // ** what is this?
    
      public pizzaorder() {
    
        pizzaprice = 9.99;
        cokeprice = 1.99;
        Pizza = pizzaprice * order; // ** WTF does this do???
      }
    Lots of variables that I don't know what they're doing. Also, the line marked "WTF" doesn't make any sense to me.

    Back to your main problem, I think that you can solve this easily with a summation variables, variables that keep track of the totals. To clarify what I mean, let's look at your problem on a small scale. Say I have a small class called PizzaTiny that just accepts number of pizzas and has getters for both number of pizzas and order amount:

    Java Code:
    public class PizzaTiny {
    
      int numberOfPizzas;
      double pizzaprice;
    
      public PizzaTiny() {
        pizzaprice = 9.99;
      }
    
      public int getNumberOfPizzas() {
        return numberOfPizzas;
      }
    
      public void setNumberOfPizzas(int numberOfPizzas) {
        this.numberOfPizzas = numberOfPizzas;
      }
    
      public double getOrderamount() {
        return numberOfPizzas * pizzaprice;
      }
    
    }
    And say I use this in another class called PizzaTinyMain.java. Again to keep this simple, I'll do this example without user interaction, but instead will place an order 5 times, each time ordering one more pizza (I'll order 1 to 5 pizzas). And say I want to sum the pizza numbers and order amounts. Then I'll give PizzaTinyMain two summation variables, totalNumberPizzas and totalOrderAmount, I'll set both to 0 initially, and I'll add to them each time an order is placed using the += operator. Then I can get the sum or totals simply by checking the values held by these summation variables:

    Java Code:
    public class PizzaTinyMain {
      public static void main(String[] args) {
        int totalNumberPizzas = 0;
        double totalOrderAmount = 0;
        
        for (int i = 0; i < 4; i++) {
          PizzaTiny pizzaTiny = new PizzaTiny();
          pizzaTiny.setNumberOfPizzas(i + 1);
          System.out.println("Number of Pizzas = " + pizzaTiny.getNumberOfPizzas());
          totalNumberPizzas += pizzaTiny.getNumberOfPizzas();
          
          double orderAmount = pizzaTiny.getOrderamount();
          System.out.println("Order Amount = " + orderAmount);
          totalOrderAmount += orderAmount;
          
          System.out.println();
        }
        
        System.out.println("Total Number of Pizzas = " + totalNumberPizzas);
        System.out.println("Total Order Amount = " + totalOrderAmount);
      }
    
    }

Similar Threads

  1. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  2. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 05:47 AM
  3. Multiple line user input
    By jointhelabel in forum New To Java
    Replies: 3
    Last Post: 10-26-2008, 03:41 AM
  4. who to take user input ,not by console...
    By Shyam Singh in forum New To Java
    Replies: 3
    Last Post: 06-13-2008, 11:09 PM
  5. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •