Java - UML Diagram provided in the uploaded file _________________________________________ Implement the ULM diagram above. Separate files for each class. Each class with a constructor and toString()...

1 answer below »

Java - UML Diagram provided in the uploaded file


_________________________________________



Implement the ULM diagram above. Separate files for each class. Each class with a constructor and toString() method. toString() will return a String with the labeled variables of each member variables.

The constructor will accept the name as an argument (as many arguments). Use super() to call the base class constructor and pass up the name.

From each of the 3 subclasses above derive 2 classes of your own. You can choose to add more member variables or just use the inherited from the parent classes. Provide each class with a constructor that sets of all the member variables, both local and inherited. Use super() to pass the name up the base class constructor.

In main() create an array of 6 items. Assign each element an object from each of your classes. Use a for loop to call toString() on all 6 elements. Display the Strings as they are returned.



Example: Class chocolateCake extends Dessert {



ChocolateCake () {



super(“Chocolate Cake”);


price = 4.99f;



}}

Answered Same DayJan 20, 2021

Answer To: Java - UML Diagram provided in the uploaded file _________________________________________ Implement...

Neha answered on Jan 21 2021
148 Votes
javafiles/Beer.java
javafiles/Beer.java
package chegg;
public class Beer extends Beverage{
    public Beer(String name) {
        super(name);
    }
    @Over
ride
    public String toString() {
        return "Beer [name=" + name + ", description=" + description + ", price=" + price + "]";
    }

}
javafiles/Beverage.java
javafiles/Beverage.java
package chegg;
public class Beverage extends Item{

    boolean hot;
    boolean alcoholic;
    float oz;

    enum Sizes{
        LARGE, MEDIUM, SMALL
    }
    Sizes size;

    public Beverage(String name) {
        super(name);
    }
    @Override
    public String toString() {
        return "Beverage [hot=" + hot + ", alcoholic=" + alcoholic + ", oz=" + oz + ", size=" + size + "]";
    }

}
javafiles/Cake.java
javafiles/Cake.java
package chegg;
public class Cake extends Dessert{
    public Cake(String name) {
        super(name);
    }
    @Override
    public String toString() {
        return "Cake [sugarFree=" + sugarFree + ", name=" + name + "]";
    }

}
javafiles/Candy.java
javafiles/Candy.java
package chegg;
public class Candy extends Dessert{
    public Candy(String name) {
        super(name);
    }
    @Override
    public String toString() {
        return "Candy [sugarFree=" + sugarFree + ", name=" + name + "]";
    }

}
javafiles/Dessert.java
javafiles/Dessert.java
package chegg;
public class Dessert extends Item{
    boolean sugarFree;
    public Dessert(String name) {
        super(name);
    }
    @Override
    public String toString() {
        return "Desser...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here