Witam wszystkich
Mam maly problem nie wiem co dokladnie zrobic, chodzi mi o zakonczenie aplikacji. Ma wyswietlic sume wszystkich rzeczy ktore kupilem oraz wyswietlic rzeczy ktore kupilem.
I nie wiem czy zrobic to za pomoca IF czy jest jakas inna mozliwosc. Tak w zasadzie to ma byc applet ale tym zajme sie pozniej teraz chcialbym aby wszystko dzialalo.
import java.util.Scanner;
class Assignment2
{
public static void main(String [] args)
{
int product;
double sum,add;
double counter;
Scanner myinput = new Scanner(System.in);
product = 0;
counter = 0;
do
{
System.out.println("Press number for : ");
System.out.println("1. Coffee 2.00 euro ");
System.out.println("2. Tea 2.00 euro ");
System.out.println("3. Soup 2.00 euro ");
System.out.println("4. Water 1.50 euro ");
System.out.println("5. Finish to pay");
System.out.print("Option :");
product = myinput.nextInt();
System.out.println("");
switch(product)
{
case 1: System.out.println("You have chosen Coffee ");
product =0;
add = 2;
counter= counter + add;
System.out.println(" ");
break;
case 2: System.out.println("You have chosen Tea ");
product =0;
add = 2;
counter= counter + add;
System.out.println(" ");
break;
case 3: System.out.println("You have chosen Soup ");
product = 0;
add = 2;
counter= counter + add;
System.out.println(" ");
break;
case 4: System.out.println("You have chosen Water ");
product = 0;
add = 1.50;
counter= counter + add;
System.out.println(" ");
break;
case 5: System.out.println("You have chousen Finish to pay" );
break;
case 6: System.out.println("Please re-enter your number");
}
while (product >= 6)
{
product = 0;
counter -= product;
System.out.println("Invalid choice, option 1-5 only!");
System.out.print("Option :");
product = myinput.nextInt();
System.out.println(" ");
}
}
while (product != 5);
{
System.out.println("");
System.out.println("You have bought: ");
System.out.println("You have bought: " +counter );
System.out.println("");
}
}
}
Dzieki z gory.
Pozdrawiam.