-1

Error im getting: main.java:105: error: non-static method menu() cannot be referenced from a static context menu();

What I have tried: From the db, I have tried to use

public static void menu()

It still doesn't work Here are the code.

import java.util.Scanner; 

 52 public class main
 53 {
 54     public static void pln(String str)
 55     {
 56         System.out.println(str);
 57     }
 58     public static double add(final int option)
 59     {
 60         final double milk = 3.49;
 61         final double rice = 6.99;
 62         final double orangeJuice = 5.99;
 63         final double iceCream = 4.99;
 64         switch(option)
 65         {
 66         case 1:
 67             return milk;
 68         case 2:
 69             return rice;
 70         case 3:
 71             return orangeJuice;
 72         case 4:
 73             return iceCream;
 74         default:
 75             pln("Wrong input, $0 return");
 76             return 0;
 77         }
 79     }
 80     public static void menu()
 81     {
 82         Scanner s = new Scanner(System.in);
 83         int flag = 0, total = 0, option = 0;
 84         while(flag != 0)
 85         {
 86             pln("1: Milk: 3.49");
 87             pln("2: rice: 6.99");
 88             pln("3: orange juice: 5.99");
 89             pln("4: ice cream: 4.99");
 90             pln("Enter a product number: ");
 91             option = s.nextInt();
 92             total += add(option);
 93             pln("Entre 0 to quit, or enter '1' to continue");
 94             flag = s.nextInt();
 95         }
 98     }
 99     public static void main(String[] args)
100     {
101         menu();
102     //  pln("Thank You for coming, see you soon");
103     }
104 }  

1 Answers1

3

You program is not doing something because

int flag = 0
while(flag != 0)
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64