so i have this homework about making a menu using array but i don't seem to understand how to make a table number or order number. however i am able to make the menu but the table number part is really complicated to add and i tried to search but i didn't found any correct code to help me make this so anyone please help so the teacher wants the output to be:
input :
Number of table : ..2..
Order table(1) : ..2..
Order again? (y/n) ..y...
Order table(1) : ..3..
Order again? (y/n) ..n...
Order table(2) : ..4..
Order again? (y/n) ..y...
Order table(2) : ..5..
Order again? (y/n) ..n...
Any changes? (y/n) ..y.. if "n" --> SUMMARY
Table no : ...1..
Order no: ..2..
Are you sure? (y/n) ..y..
if "n" --> Table no : ......
Order no: ......
Are you sure? (y/n) ..y..
output (SUMMARY) :
Table 1
menu3 price3
------------------- +
Total xxxxxx
Table 2
menu2 price2
menu3 price3
------------------- +
Total xxxxxx
GRAND TOTAL XXXXXXXX
and this is the code for the menu that i wrote:
package function;
import java.util.Scanner;
public class Function {
public static void main(String[] args) {
Scanner keyB = new Scanner(System.in); // Create a Scanner object
String[] menuname = {"1. fried rice","2. noodle","3. soup","4. meatballs","5. chicken tenders","6. ramen","7. iced tea","8. cola","9. mineral water","10. ice cream"};
int [] menuprice = {25000,27000,28000,20000,26000,30000,4000,6000,2000,12000};
int [] order = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
System.out.print("\u001B[2J");
System.out.println("M E N U");
for (int i=0; i<menuname.length; i++) {
System.out.println(menuname[i]+": Rp. "+String.valueOf(menuprice[i]));
}
System.out.println();
String orderagain="y";
int userorder=0, ordernum=0, ordertotal=0;
while (!orderagain.equals("n")) {
System.out.print("Enter your menu number: ");
userorder = keyB.nextInt()-1;
order[ordernum]=userorder;
ordertotal=ordertotal+menuprice[userorder];
ordernum++;
System.out.print("Order again (y/n): ");
orderagain = keyB.next().toLowerCase();
System.out.println();
}
System.out.println();
System.out.println("Your ordered menu:");
System.out.println();
for (int i=0; i<ordernum; i++) {
System.out.println(menuname[order[i]]+": Rp. "+String.valueOf(menuprice[order[i]]));
}
System.out.println("------------------------------------------ +");
System.out.println("The total is: Rp. "+String.valueOf(ordertotal));
System.out.println();
}
}
Aucun commentaire:
Enregistrer un commentaire