daily pastebin goal
46%
SHARE
TWEET

Drink Class for AP CS A

a guest Mar 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Drink {
  2.    private String  name;
  3.    private boolean hasCarbonation;
  4.    private double  gramsOfSugar;
  5.    private double  ounces;
  6.  
  7.    public Drink (String n, Boolean h, double g) {
  8.        name = n;
  9.        hasCarbonation = h;
  10.        gramsOfSugar = g;
  11.        ounces = 8;           //FDA defines a serving as 8 oz.
  12.    }
  13.  
  14.    public void chug (double gulp) {
  15.        if (ounces < gulp) {
  16.            throw new IllegalArgumentException ("Not enough " + name + " left.");
  17.        } else {
  18.            System.out.println ("Glug, glug, glug!");
  19.            ounces -=gulp;
  20.            System.out.println("You have " + ounces + "oz. of " + name + " left.");
  21.        }
  22.    }
  23.  
  24.    public String getState() {
  25.        return "liquid";
  26.    }
  27.  
  28.    public void printLabel() {
  29.        System.out.println ("Enjoy refreshing " + name + " !");
  30.    }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top