請求書を印刷する際に、数量を使って私がスターターメソッドで注文したものを印刷したいと考えています。どのように私はそれをやるのだろうか?全体の問題が非常に大きいので、私は自分のプログラムのインスタンスしか書いていません。請求時に購入した商品を印刷するにはどうすればよいですか?
ありがとうございます。
static void Bill()
{
System.out.println("\f");
System.out.println("*********************************************************");
System.out.println("*********************************************************");
System.out.println("**************************BILL***************************");
System.out.println(ob);
System.out.println("Your phone number - "+j);
int Z = (int)(Math.random()*10000000);
System.out.println("Bill number is "+Z);
System.out.println("The total bill amount is Rs."+sum);
System.out.println();
System.out.println("Hope you enjoyed. Visit us again soon!");
Food=0;
}
static void Starters()
{
System.out.println("You have selected Starters");
System.out.println();
System.out.println("1. Spring Rolls - Rs 350");
System.out.println("2. Onion Rings - Rs 350");
System.out.println("3. Fried Raviolli - Rs 400");
System.out.println("4. Gorgonzola - Rs 400");
System.out.println("5. Fresh Ricotta Crostini - Rs 475");
System.out.println("6. Potato Fritters - Rs 500");
System.out.println();
System.out.println("Enter your desired option");
starterOption=sc.nextInt();
System.out.println("Enter quantity");
quantity=sc.nextInt();
switch(starterOption)
{
case 1:
s1 = quantity * 350;
break;
case 2:
s2 = quantity * 350;
break;
case 3:
s3 = quantity * 400;
break;
case 4:
s4 = quantity * 400;
break;
case 5:
s5 = quantity * 475;
break;
case 6:
s6 = quantity * 500;
break;
default:
System.out.println("You haven't ordered anything");
break;
}
System.out.println("Do you want to order anything else? Y/N");
A = sc1.next();
if(A.equalsIgnoreCase("Y"))
{
System.out.println("Do you want to order from the same section? Y/N ");
F=sc.next();
if(F.equalsIgnoreCase("Y"))
{
sum=s1+s2+s3+s4+s5+s6;
Starters();
}
else
{
sum=s1+s2+s3+s4+s5+s6;
Food_Items();
}
}
else
{
sum=s1+s2+s3+s4+s5+s6;
Bill();
}
}
それは非常に長いコードです。 – msagala25
あなたはまた、合計価格だけでなく、顧客が注文したものを保存しておくべきです。また、javaのコレクションで読んで、あなたはあまりにも多くの変数を持っています。 https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html – Idos
私の質問に直接投票するのではなく、何かが間違っているか、このサイトのルールに違反しているかどうか教えてください。私はこのサイトを初めて利用しています! –