Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. In ths lab, you will learn how to do the following: Build a Java superclass. Build several Java subclasses. Overload methods with multiple signatures.

1. In ths lab, you will learn how to do the following:

  • Build a Java superclass.
  • Build several Java subclasses.
  • Overload methods with multiple signatures.
  • Build a project with three levels in the Inheritance Hierarchy.
  • Create JUnit test cases for constructors, get methods, set methods, and other methods.

Structure:

Create the following structure in Eclipse for this lab.

  • Package Name: DessertShop
  • Class Names:
    • DessertItem
    • Candy
    • Cookie
    • IceCream
    • Sundae

Program: Dessert Shop, Part 1Class Structure

A Dessert Shop sells candy by the pound, cookies by the dozen, ice cream by the scoop, and sundaes (ice cream with a topping).

In ths lab, you will create thestructurefor a Dessert Shop program. There will be no user interface or input/output in conjunction with this lab. The lab will be tested using JUnit test cases.

To do ths, you will implement an inheritance hierarchy of classes derived from a DessertItem superclass. Candy, Cookie, and IceCream classes will derive from the DessertItem class. The Sundae class will derive from the IceCream class. The classes will be structured as follows:

The DessertItem superclass contains:

      • A single-attribute name
        • The name attribute MUST be private. You may not use the 'protected' access modifier.
      • Two constructors:
        • A default that takes no arguments and sets the name instance variable to a default 0-type value.
        • One that has one argument and sets the name instance variable to the passed-in argument.
      • An appropriate get()-type method and a set()-type method for the name attribute.
        • The getter()-type method takes no arguments and returns the appropriate instance variable.
        • The setter()-type method takes an appropriate argument and sets the appropriate instance variable. The setter() -type methods will not return any values.

All derived subclasses (Candy, Cookie, IceCream, and Sundae) contain:

    • Attributes as described below.
    • Two constructors:
      • A default that takes no arguments calls the default constructor of the superclass and sets all instance variables local to the class to default 0-type values.
      • One that has enough arguments to populate ALL instance variables (both local and those from the superclass) calls the all-argument constructor of the superclass and sets all instance variables local to the class to the passed-in arguments of the constructor.
    • Appropriate get()-type methods and a set()-type methods for each instance variable local to the class.
      • Each getter()-type method takes no arguments and returns the appropriate instance variable.
      • The setter()-type method takes an appropriate argument and sets the appropriate instance variable. The setter() -type methods will not return any values.

The Candy Class:

    • Containsonlytwo attributes:
      • double candyWeight
      • double pricePerPound

The Cookie Class:

    • Containsonlytwo attributes:
      • int cookieQty
      • double pricePerDozen

The IceCream Class:

    • Containsonlytwo attributes:
      • int scoopCount
      • double pricePerScoop

The Sundae Class:

    • Containsonlytwo attributes:
      • String toppingName
      • double toppingPrice

UML Diagram:

JUnit Test Cases:

Creat JUnit test cases for each method for each class.

  • The DessertItem class will have two test cases.
  • All other classes will have four test cases.

Keep each test case simple, as described below.

getter()-type methods

Test cases for all get()-type methods will

    • invoke the all-attribute constructor,
    • call the appropriate get() method, and
    • compare the value returned from the get() method with the value passed into the constructor.

setter()-type methods

Test cases for all set()-type methods will

    • invoke the all-attribute constructor;
    • call the appropriate set() method, changing the value passed in through the constructor; and
    • compare the valuepassedto the set() method with the valuereturnedfrom the getter() method to ensure the value change from the original constructor invocation.

Key Program Requirements:

All classes and methods are creatd as described above.

All JUnit test cases are creatd as described above.

All JUnit test cases pass.

Turn in TEN (10) .java files:

    • DessertItem.java
    • DessertItemTest.java
    • Candy.java
    • CandyTest.java
    • Cookie.java
    • CookieTest.java
    • IceCream.java
    • IceCreamTest.java
    • Sundae.java
    • SundaeTest.java

2. Objectives:

In ths lab, you will learn how to

  • use an existing structure of Java classes to build an application,
  • creat an interface to test your application, and
  • creat JUnit test cases for your application.

Structure:

Creat the following structure in Eclipse for this lab.

  • Package Name: DessertShop
  • Class Names:
    • Order
    • DessertShop

Program: Dessert Shop, Part 2Order

A Dessert Shop sells candy by the pound, cookies by the dozen, ice cream by the scoop, and sundaes (ice cream with a topping).

In ths lab, you will implement the ability to creat an order consisting of items available at a Dessert Shop. These items include candy, cookies, ice cream, and sundaes. You will also implement a class to hold the main method for the application called DesertShop with a simple user interface to test the order entry system.

To do ths, you will implement two new classes for your Dessert Shop application as described below:

The Order class contains:

      • A single attribute,order, that is of typ ArrayList.
      • A single default constructor that takes no arguments and instantiates the order instance variable to a new ArrayList().
      • A getOrderList() method that takes no arguments and returns the ArrayList instance variable, order.
      • An add() method that takes a single DessertItem argument and adds it to the ArrayList instance variable, order. The add() method returns nothing (void).
      • An itemCount() method that takes no arguments and returns the size of the ArrayList instance variable, order.

NOTE: The Order class is a stand-alone clas. It is neither a superclass nor a subclass.

The DessertShop class contains:

    • No attributes
    • A single method, main(), that tests the Dessert Shop application
    • The public static void main(String[] args) method:
      • Creats a new instance of the order class
      • Adds the following items to the order:
        • Candy("Candy Corn", 1.5, .25)
        • Candy("Gummy Bears", .25, .35)
        • Cookie("Chocolate Chip", 6, 3.99)
        • IceCream("Pistachio", 2, .79)
        • Sundae("Vanilla", 3, .69, "Hot Fudge", 1.29)
        • Cookie("Oatmeal Raisin", 2, 3.45)
      • Prints out just the name of each DessertItem in the order
      • Prints out the total number of items in the order

NOTE: The DessertShop class is a stand-alone clas. It is neither a superclass nor a subclass. It is used to house the user interface and run the program.

UML Diagram:

JUnit Test Cases:

You do not need to creat any JUnit test case for the Order or DessertShop classes.

No existing JUnit classes need to be updated for this lab.

Key Program Requirements:

The Order class and DessertShop class are implemented as described above.

The output of running your Dessert Shop program should look exactly like the example run.

Turn in two (2) .java files:

    • Order.java
    • DessertShop.java

Example run

Candy Corn

Gummy Bears Chocolate Chip Pistachio Vanilla Oatmeal Raisin

Total number of items in order: 6

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

Step: 3

blur-text-image

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

Principles of Information Systems

Authors: Ralph M. Stair, George W. Reynolds

9th edition

978-1337097536, 1337097535, 978-1337515634, 1337515639, 978-0324665284

More Books

Students also viewed these Programming questions

Question

What is the value chain?

Answered: 1 week ago