Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need a program made for what is in the pictures and this is the sample usage. Thank you! public class TestGlass { public static
I need a program made for what is in the pictures and this is the sample usage. Thank you! 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 { // Declare a variable to keep track of the number of ounces in a glass here // Write the methods here. You will need a constructor, plus the drink, report, fill, // and spill methods. These methods are for any generic glass -- they are not specific // to the milk or juice instances of a glass (i.e., you should not mention "juice" or // "milk" inside the Glass class). } An object is a collection of data and methods that model ("imitate") some thing in the real world, such as a car, a building or a bank. When modelling something, the programmer must decide what aspect of the thing needs to be modeled. For a car you could keep track of its price, its owner, its color, its odometer, the amount of gas in its tank, etc. You might need to model all of these traits, or just one or two of them. Once you decide which trait to model, such as the odometer for a car, then that trait is the data of your object. All of the methods that will become part of the object will have something to do with that data for example, you might have a drive method that makes the odometer increase, and a report method that shows the current value of the odometer. You would also need a constructor to set the starting value of the odometer when the object is created.Remember that to get an object you must first create a class, which is a blueprint for the object. You create the actual objects from the class with the new operator. For example, if you have a Car
I need a program made for what is in the pictures and this is the sample usage. Thank you!
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
{
// Declare a variable to keep track of the number of ounces in a glass here
// Write the methods here. You will need a constructor, plus the drink, report, fill,
// and spill methods. These methods are for any generic glass -- they are not specific
// to the milk or juice instances of a glass (i.e., you should not mention "juice" or
// "milk" inside the Glass class).
}
Step 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