Results 1 to 2 of 2
  1. #1
    kor6666 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default Calculation help =(

    Java Code:
    static void dispOrders() {
    
    		System.out.println("");
    
    		System.out.print("How many orders (max 10) : ");
    
    		orders = scInput.nextInt();
    
    		System.out
    
    		.println("-----------------------------------------------");
    
    		if (orders < 11) {
    
    			for (int i = 0; i < orders; i++) {
    
    				if (String.valueOf(order).length() < 2) {
    
    					adorder = Integer.toString(order);
    
    					System.out.println("Order (" + adorder + ")");
    
    				} else if (String.valueOf(order).length() > 3) {
    
    					adorder = Integer.toString(order);
    
    					System.out.println("Order (" + adorder + ")");
    
    				} else {
    
    					adorder = Integer.toString(order);
    
    					System.out.println("Order (" + adorder + ")");
    
    				}
    
    				if (String.valueOf(order).length() < 2) {
    
    					curorder = "P000" + Integer.toString(order);
    
    					System.out.println("Order number: " + curorder);
    
    				} else if (String.valueOf(order).length() > 3) {
    
    					curorder = "P00" + Integer.toString(order);
    
    					System.out.println("Order number: " + curorder);
    
    				} else {
    
    					curorder = "P0" + Integer.toString(order);
    
    					System.out.println("Order number: " + curorder);
    
    				}
    
    				System.out.print("Enter customer name: ");
    
    				 customerName = scInput.next();
    
    				System.out
    
    				.print("Enter number of carrots(@$0.40cts): ");
    
    				carrots = scInput.nextInt();
    
    				while (carrots > 1000 || carrots < 0) {
    
    					System.out.print("Thats an invalid number!");
    
    					System.out
    
    					.print("Enter number of carrots(@$0.40cts): ");
    
    					carrots = scInput.nextInt();
    
    				}
    
    				totalcarrots += carrots;
    
    				System.out.print("Enter number of onions(@$0.45cts): ");
    
    				onions = scInput.nextInt();
    
    				while (onions > 1000 || onions < 0) {
    
    					System.out.println("Thats an invalid number!");
    
    					System.out
    
    					.print("Enter number of onions(@$0.45cts): ");
    
    					onions = scInput.nextInt();
    
    				}
    
    				totalonions += onions;
    
    				System.out.print("Enter number of potatos(@$0.35cts): ");
    
    				potatos = scInput.nextInt();
    
    				while (potatos > 1000 || potatos < 0) {
    
    					System.out.println("Thats an invalid number!");
    
    					System.out
    
    					.print("Enter number of potatos(@$0.35cts): ");
    
    					potatos = scInput.nextInt();
    
    				}
    
    				totalpotatos += potatos;
    
    				System.out
    
    				.print("Enter number of tomatos(@$0.50): ");
    
    				tomatos = scInput.nextInt();
    
    				while (tomatos > 1000 || tomatos < 0) {
    
    					System.out.println("Thats an invalid number!");
    
    					System.out
    
    					.print("Enter number of tomatos(@$0.50): ");
    
    					tomatos = scInput.nextInt();
    
    				}
    
    				totaltomatos += tomatos;
    
    				carrotsprice = fmt3.format(0.40 * carrots);
    
    				onionsprice = fmt3.format(0.45 * onions);
    
    				potatosprice = fmt3.format(0.35 * potatos);
    
    				tomatosprice = fmt3.format(0.50 * tomatos);
    
    				totalprice = fmt3.format((0.40 * carrots)
    
    				+ (0.45 * onions)
    
    				+ (0.35 * potatos) + (0.50 * tomatos));
    
    				String[] cost = { curorder, customerName, carrotsprice,
    
    				onionsprice,
    
    				potatosprice, tomatosprice, totalprice, adorder };
    				Integer[] veggies = { carrots,onions,potatos,tomatos };
    				veges.add(veggies);
    
    				prices.add(cost);
    
    				order += 1;
    
    				tcarrots += 0.40 * carrots;
    
    				tonions += 0.45 * onions;
    
    				tpotatos += 0.35 * potatos;
    
    				ttomatos += 0.50 * tomatos;
    
    				ttotal += (0.40 * carrots) + (0.45 * onions)
    
    				+ (0.35 * potatos)
    
    				+ (0.50 * tomatos);
    
    			}
    
    		}
    
    	}
    
    	static void editInfo() {
    		for (int i = 0 ; i < prices.size(); i++) {
    
    			System.out.println(prices.get(i)[7] + ") " + prices.get(i)[1] + " "
    
    			+ prices.get(i)[0]);
    
    		}
          		System.out.print(">");
    		
    		i = scInput.nextInt();
    		
    		System.out.println("Customer name: " + prices.get(i-1)[1]);
    
    		System.out.println("Order number : " + prices.get(i-1)[0]);
    	
    		System.out.println("Number of carrots: "+veges.get(i-1)[0]);
    		
    		System.out.print("Do you want to change?(y/n): ");
    		
    	    answer  = scInput.next();
    	    if(answer.equals("y")){
    		System.out.print("Enter the number of carrots: ");
    		veges.get(i-1)[0] = scInput.nextInt();
    		while (veges.get(i-1)[0] > 1000 || veges.get(i-1)[0] < 0) {
    
    			System.out.println("Thats an invalid number!");
    			System.out.print("Enter the number of carrots: ");
    			veges.get(i-1)[0] = scInput.nextInt();}
    		
    	    } else if(!(answer.equals("n"))){
    				
    					while(!(answer.equals("n") || answer.equals("y"))){
    						System.out.println("Choice is invalid");
    						System.out.print("Do you want to change?(y/n): ");
    						answer = scInput.next();
    						if(answer.equals("y")){
    							System.out.print("Enter the number of carrots: ");
    							veges.get(i-1)[0] = scInput.nextInt();
    							while (veges.get(i-1)[0] > 1000 || veges.get(i-1)[0] < 0) {
    
    								System.out.println("Thats an invalid number!");
    								System.out.print("Enter the number of carrots: ");
    								veges.get(i-1)[0] = scInput.nextInt();}
    						}
    					
    					}
    			   
    			}
    			System.out.println("Number of onions : "+veges.get(i-1)[1]);
    			
    			System.out.print("Do you want to change?(y/n): ");
    			answer2 = scInput.next();
    			if(answer2.equals("y")){
    				System.out.print("Enter the number of onions: ");
    				veges.get(i-1)[1] = scInput.nextInt();
    				while (veges.get(i-1)[1] > 1000 || veges.get(i-1)[1] < 0) {
    
    					System.out.println("Thats an invalid number!");
    					System.out.print("Enter the number of onions: ");
    					veges.get(i-1)[1] = scInput.nextInt();}
    			} else if(!(answer2.equals("n"))){
    				while(!(answer2.equals("n") || answer2.equals("y"))){
    					System.out.println("Choice is invalid");
    					System.out.print("Do you want to change?(y/n): ");
    					answer2 = scInput.next();
    					if(answer2.equals("y")){
    						System.out.print("Enter the number of onions: ");
    						veges.get(i-1)[1] = scInput.nextInt();
    						while (veges.get(i-1)[1] > 1000 || veges.get(i-1)[1] < 0) {
    
    							System.out.println("Thats an invalid number!");
    							System.out.print("Enter the number of onions: ");
    							veges.get(i-1)[1] = scInput.nextInt();}
    					}
    				}
    			}
    			System.out.println("Number of potatos : "+veges.get(i-1)[2]);
    			System.out.print("Do you want to change?(y/n): ");
    			answer3 = scInput.next();
    			if(answer3.equals("y")){
    				System.out.print("Enter the number of potatos: ");
    				veges.get(i-1)[2] = scInput.nextInt();
    				while (veges.get(i-1)[2] > 1000 || veges.get(i-1)[2] < 0) {
    
    					System.out.println("Thats an invalid number!");
    					System.out.print("Enter the number of potatos: ");
    					veges.get(i-1)[2] = scInput.nextInt();}
    			}else if(!(answer3.equals("n"))){ 
    			while(!(answer3.equals("n") || answer3.equals("y"))){
    				System.out.println("Choice is invalid");
    				System.out.print("Do you want to change?(y/n): ");
    				answer3 = scInput.next();
    				if(answer3.equals("y")){
    					System.out.print("Enter the number of potatos: ");
    					veges.get(i-1)[2] = scInput.nextInt();
    					while (veges.get(i-1)[2] > 1000 || veges.get(i-1)[2] < 0) {
    						System.out.println("Thats an invalid number!");
    						System.out.print("Enter the number of potatos: ");
    						veges.get(i-1)[2] = scInput.nextInt();}
    					}}
    			}
    			System.out.println("Number of tomatos : "+veges.get(i-1)[3]);
    			System.out.print("Do you want to change?(y/n): ");
    			answer4 = scInput.next();
    			if(answer4.equals("y")){
    				System.out.print("Enter the number of tomatos: ");
    				veges.get(i-1)[3] = scInput.nextInt();
    				while (veges.get(i-1)[3] > 1000 || veges.get(i-1)[3] < 0) {
    
    					System.out.println("Thats an invalid number!");
    					System.out.print("Enter the number of tomatos: ");
    					veges.get(i-1)[3] = scInput.nextInt();}
    				
    				}else if(!(answer4.equals("n"))){
    			while(!(answer4.equals("n") || answer4.equals("y"))){
    					System.out.println("Choice is invalid");
    					System.out.print("Do you want to change?(y/n): ");
    					answer4 = scInput.next();
    					if(answer4.equals("y")){
    						System.out.print("Enter the number of tomatos: ");
    						veges.get(i-1)[3] = scInput.nextInt();
    						while (veges.get(i-1)[3] > 1000 || veges.get(i-1)[3] < 0) {
    
    							System.out.println("Thats an invalid number!");
    							System.out.print("Enter the number of tomatos: ");
    							veges.get(i-1)[3] = scInput.nextInt();
    							}
    						
    						carrotsprice = fmt3.format(0.40 * veges.get(i-1)[0]);
    
    						onionsprice = fmt3.format(0.45 * veges.get(i-1)[1]);
    
    						potatosprice = fmt3.format(0.35 * veges.get(i-1)[2]);
    
    						tomatosprice = fmt3.format(0.50 * veges.get(i-1)[3]);
    
    						totalprice = fmt3.format((0.40 * veges.get(i-1)[0])
    
    								+ (0.45 * veges.get(i-1)[1])
    
    								+ (0.35 * veges.get(i-1)[2]) + (0.50 * veges.get(i-1)[3]));
    			
    						String[] cost = { curorder, customerName, carrotsprice,
    
    								onionsprice,
    
    								potatosprice, tomatosprice, totalprice, adorder };
    								Integer[] veggies = { carrots,onions,potatos,tomatos };
    								veges.add(veggies);
    
    								prices.add(cost);
    
    								order += 1;
    
    								tcarrots += 0.40 * veges.get(i-1)[0];
    
    								tonions += 0.45 * veges.get(i-1)[1];
    
    								tpotatos += 0.35 * veges.get(i-1)[2];
    
    								ttomatos += 0.50 * veges.get(i-1)[3];
    
    								ttotal += (0.40 * veges.get(i-1)[0]) + (0.45 * veges.get(i-1)[1])
    
    								+ (0.35 * veges.get(i-1)[2])
    
    								+ (0.50 * veges.get(i-1)[3]);
    I want to show my prices for each orders after i edit, but what is shows is my prices before editing. How do i show my prices for the orders after editing?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,570
    Rep Power
    25

    Default Re: Calculation help =(

    Can you post the program's current output and add some comments showing what the output should be?

    show my prices for the orders after editing
    Where does the program do the editing? I don't see any comments that say where it is done.
    What is the problem moving the print out to after the editing is done?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Getting value from pre-Mod calculation
    By jjb1989 in forum New To Java
    Replies: 1
    Last Post: 11-10-2012, 10:01 PM
  2. Problem with calculation
    By ibrafiqb in forum New To Java
    Replies: 3
    Last Post: 11-24-2010, 05:02 PM
  3. Jtextfield value get and calculation
    By globo in forum New To Java
    Replies: 11
    Last Post: 10-25-2010, 04:51 AM
  4. Calculation with char
    By chuckbalzer in forum New To Java
    Replies: 7
    Last Post: 09-20-2010, 05:29 PM
  5. Problem with Calculation ....
    By danny000 in forum New To Java
    Replies: 1
    Last Post: 04-15-2008, 02:42 PM

Posting Permissions

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