Course Hero Logo

Untitled_document - public class CoffeeTester { public...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 6 out of 22 pages.

public class CoffeeTester{public static void main(String[] args){// Create Specialized CoffeeCoffee latte = new Coffee(4, false, "soy");System.out.println(latte);// Create a default coffee// This should work after you create the default// constructorCoffee plain = new Coffee();System.out.println(plain);}}
/** This class represents a cup of coffee**/public class Coffee{// Instance Variablesprivate int brewStrength; // on a scale of 1 to 5, 5 being the darkestprivate boolean sugar;// has sugar (true) or does not (false)// takes the values "none", "whole", "nonfat", "soy", or "almond"private String milkType;// Add a default constructor (no parameters)// to initialize the instance variables// to a default cup of coffee// Specialized constructorpublic Coffee(int howStrong, boolean hasSugar, String milk){brewStrength = howStrong;sugar = hasSugar;milkType = milk;}public Coffee(){brewStrength = 3;sugar = true;milkType = "whole";}// String representation to print// Do not modify this functionpublic String toString(){return "Coffee brewed to level " + brewStrength + " with " + milkType + " milk. Sugar? " +sugar;}}
public class PinataTester{public static void main(String[] args){// Make Pinatas!Pinata ella = new Pinata();Pinata pete = new Pinata("chocolate", "blue", "star");Pinata sweetie = new Pinata("sour straws");// Print the pinatasSystem.out.println(ella);System.out.println(pete);System.out.println(sweetie);}}public class Pinata{// Instance variablesprivate String candy;// what kind of candy is inside
private String color;private String shape;// Constructor without parameterspublic Pinata(){candy = "hard candy";color = "rainbow";shape = "donkey";}// Add an overloaded constructor that allows the user// to customize all of the instance variablespublic Pinata(String Vcandy, String Vcolor, String Vshape){candy = Vcandy;color = Vcolor;shape = Vshape;}// Add an overloaded constructor that allows the user// to customize the color and shapepublic Pinata(String Vcolor, String Vshape){candy = "hard candy";color = Vcolor;shape = Vshape;}// Add an overloaded constructor that allows the user// to customize the candy

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 22 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
hegde
Tags
Subroutine, My Name Is, public class CoffeeTester

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture