Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Description : Write a Cup class that will simulate storing liquid in a cup. You can add to the cup and pour from the

Lab Description : Write a Cup class that will simulate storing liquid in a cup. You can add to the cup and pour from the cup.
Sample Runner Code :
System.out.println( "made a cup of 10");
Cup c = new Cup(10);
System.out.println( "amt in cup "+ c.getAmtInCup()); //returns amt in the cup
System.out.println( "add "+ c.add(5)); //adds amt and returns overflow
System.out.println( "amt in cup "+ c.getAmtInCup()); //returns amt in the cup
System.out.println( "add "+ c.add(2)); //adds amt and returns overflow
System.out.println( "num adds "+ c.getNumAdds()); //returns the number of adds
System.out.println("is full "+ c.isFull()); //checks if the cup is full
System.out.println( "will overflow 10"+ c.willOverflow(10)); //checks to the see if
//adding the amount will
//cause an overflow
System.out.println( "pour 7"); //pours out an amt from the cup
c.pour(7);
System.out.println( "amt in cup "+ c.getAmtInCup()); //returns amt in the cup
System.out.println("is full "+ c.isFull()); //checks to the if the cup is full
Sample Output :
made a cup of 10
amt in cup 0.0
add 0.0
amt in cup 5.0
add 0.0
num adds 2
is full false
will overflow 10 true
pour 7
amt in cup 0.0
is full false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What are the pros and cons of using credit? (p. 321)

Answered: 1 week ago