I am a beginner in java, I have tried to solve the below program, but getting error, can anyone tell me where I am doing mistake?
public class TestGlass
{
public static void main(String [] args)
{
Glass milk = new Glass(15); // 15 ounces of milk
Glass juice = new Glass(3); // 3 ources of juice
milk.drink(2);
milk.drink(1);
milk.report();
juice.fill(6); // went from 3 to 9 ounces
juice.drink(1); // now down to 8 ounces
juice.report();
juice.spill();
juice.report();
}
}
class Glass
{
int ounce;
public void spill()
{
ounce = 0;
}
public void drink(int x){
ounce = ounce-x;
}
public void fill(int x){
ounce = ounce+x;
}
public int getOunce()
{
return ounce;
}
public void report()
{
int x = getOunce();
System.out.println("Glass has " + x + " ounces");
}
}
Here is the error,
TestGlass.java:5: error: constructor Glass in class Glass cannot be applied to given types;
Glass milk = new Glass(15); // 15 ounces of milk
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
TestGlass.java:6: error: constructor Glass in class Glass cannot be applied to given types;
Glass juice = new Glass(3); // 3 ources of juice
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
2 errors
Glassclass is missing a constructor.