Question
I keep getting this error with this code. Please help. import java.io.*; import java.util.Scanner; public class WK2GarciaM { class Bottle { // Attributes private boolean
I keep getting this error with this code.
Please help.
import java.io.*; import java.util.Scanner;
public class WK2GarciaM { class Bottle { // Attributes private boolean isfull;
private String addLiquid;
// Constructors
public Bottle(boolean isfull, String addLiquid) { this.isfull = isfull;
this.addLiquid = "add liquid of choice"; }
public void addToBottle() { Scanner stdin = new Scanner(System.in);
System.out.println("Wish to flavor your liquid?");
String added = stdin.nextLine();
this.addLiquid = added;
if (added.equals("Mio Flavor"))
System.out.println("Changed the liquid flavor.");
else
this.addLiquid = added;
System.out.println("Added " + this.addLiquid); }
public void fill() { if (isfull == true) { System.out.println("Bottle is filled to the top");
return;
}
else { addToBottle(); isfull = true;
System.out.println("The bottle is getting filled up"); } }
public void empty() { if (isfull == false) { System.out.println("This bottle is dry and empty");
return;
}
else { isfull = false;
System.out.println("No liquid is in the bottle"); } } // Getters and Setters public String getAddLiquid() { return addLiquid; }
public void setAddLiquid(String addLiquid) { this.addLiquid = addLiquid; }
public void setIsfull(boolean isfull) { this.isfull = isfull; }
public boolean isfull() { return isfull; } }
public class Menu { public Bottle bottle;
// Constructor
public Menu() { // Displays as the menu legend }
public Menu(Bottle bottle) { this.bottle = bottle; } // Getters and Setters public Bottle getBottle() { return bottle; }
public void setBottle(Bottle bottle) { this.bottle = bottle; }
public void display() { System.out.println("What is your action?");
System.out.println("1. Clean and view your bottle");
System.out.println("2. Fill up your bottle");
System.out.println("3. Dispose of liquid in your bottle");
System.out.println("4. Recycle your bottle");
System.out.println("5. Error"); }
public void choice(int c) { switch (c) { case 1:
if (bottle.isfull()) { System.out.println( "Your bottle seems to be empty and ready to be filled up"); // bottle gets filled up
break;
}
else { System.out.println("Fill up your bottle with liquids of choice");
break; }
case 2:
bottle.fill();
break;
case 3:
bottle.empty();
break;
case 4:
if (bottle.isfull() == true) { System.out.println("Pour out the liquid in bottle");
break;
}
else { System.out.println("Bottle is recycled"); break; }
case 5:
bottle.addToBottle();
break;
default:
System.out.println("Error try again");
break; } } }
public class FilledBottle { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in);
Menu menu = new Menu(new Bottle(true, "liquid"));
int c = 0;
System.out.println("What do you wish to do with your bottle");
do { System.out.println();
menu.display();
c = scan.nextInt();
menu.choice(c);
} while (c != 4);
scan.close(); } } }
public class FilledBottle \{ public static void mai Scanner scan = new Sca Menu menu = new Menu(new variable this cannot be referenced from a static context (Alt-Enter shows hints) int c=0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started