这是餐厅计费系统。要求用户输入表号,菜盘号和数量。每次用户添加菜品编号和数量时,我需要打印“您是否要添加更多?”。现在,一旦用户输入y,它就会提示您添加两次盘号和数量。
int dish,qun,sum=0,tnum;
char ch='y';
int num=0;
String menuItem[][]=
{
{"Banana","50"},
{"Rajma", "60"},
{"Momo","100"},
{"Rajma", "60"},
{"Rajma", "60"},
{"Rajma", "60"},
{"Rajma", "60"},
{"Rajma", "60"},
{"Rajma", "60"},
{"Rajma", "60"}
};
System.out.println("+++Menu Item+++");
for(int i = 0; i< 10; i++)
{
System.out.print(i+1+". ");
for(int j= 0; j<2;j++)
{
System.out.print(menuItem[i][j]);
System.out.print(" ");
}
System.out.println("");
}
Scanner scan = new Scanner(System.in);
// System.out.println(menuItem[2][1]);
for(int x=0;x<5;x++)
{
System.out.println("Enter the Table no:");
tnum=scan.nextInt();
while(ch=='y')
{
for(int y=0; y<=num; y++)
{
System.out.println("Enter the dish number:");
dish=scan.nextInt();
System.out.println("Enter the quantity:");
qun=scan.nextInt();
String nu=menuItem[dish-1][1];
sum = Integer.parseInt(nu)*qun+sum;
}
System.out.println("Do you want to add dish? Enter 'y' or 'n'.");
ch=scan.next().charAt(0);
if(ch=='y')
{
num=num+1;
}
}
tableDish[0][0]=tnum;
tableDish[0][1]=sum;
}
System.out.println("Sum:"+sum);
for(int i=0;i<1;i++)
{
for(int j=0;j<2;j++)
{
System.out.println("value:"+tableDish[i][j]);
}
}
}
}