java - I'm almost finished, but how to loop the entire program? -
my cash register program complete, can process sales , returns , adds or subtracts money in register.
my problem once i'm done adding values example, program closes , cant figure out how loop choice menu. tried using loop , while loop yelled @ me saying had invalid input (probably because have press f stop when you're checking out).
how can loop whole thing?
import java.util.scanner; import java.util.arraylist; public class assignment3_000848913 { public static void main(string[] args) { scanner in = new scanner(system.in); arraylist<integer> prices = new arraylist<integer>(); arraylist<integer> returnprices = new arraylist<integer>(); int totalregistermoney = 0; int choice = 0; system.out.print("what do?"); system.out.println(); system.out.print("press 1. process sale"); system.out.println(); system.out.print("press 2. process return"); system.out.println(); system.out.print("press 3. display money in register"); system.out.println(); system.out.print("press 4. exit"); system.out.println(); choice = in.nextint(); if(choice == 1) { //this loop reads in prices// system.out.print("press f when finished."); system.out.println(); { system.out.print("enter integer price of item: $"); int = in.nextint(); prices.add(i); system.out.println(); } while(in.hasnextint()); int totalprice = processsale(prices); totalregistermoney = totalregistermoney + totalprice; system.out.print("your total comes $"); system.out.println(totalprice); } if(choice == 2) { system.out.print("press f when finished."); system.out.println(); { system.out.print("enter price of returned item: $"); int j = in.nextint(); returnprices.add(j); system.out.println(); } while(in.hasnextint()); int returntotal = processreturn(returnprices); if(returntotal > totalregistermoney) { system.out.print("sorry, there's not money in register."); system.out.println(); } else { totalregistermoney = totalregistermoney - returntotal; } system.out.print("you've completed return."); system.out.println(); } if(choice == 3) { viewbalance(totalregistermoney); } } //end of main
if getting error when did do..while, doing ok.
the problem after writing 'f' exit option 1 , loop returns , tries convert 'f'
choice = in.nextint();
this causes error bucause 'f' not number. need put
in.next();
after
while(in.hasnextint());
this happen on option 2 in code
Comments
Post a Comment