Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Designandimplement Java program asfollows: There will be a Snack class with following attributes: id(combinationof numbersand letters), size (values S, M, orL), and price There will

Design and implement Java program as follows:

  1. There will be a Snack class with following attributes: id (combination of numbers and letters), size (values S, M, or L), and price
  2. There will be two child classes FruitSnack and SaltySnack with the following additional

attributes:

  • FruitSnackIt includes citrus fruit indication (value of thisvariable of is true or false)
  • SaltySnackIt includes nut snack indication (value of this variable ofis true or false)

 

  1. The Snack class hierarchy must provide the following functionality:
  • On creation, a snack instance must be given all attribute values except its price, which must be calculated
  • Price iscalculated as follows:
    • There is a flat fee of $19.99 for S snack, $29.99 for M snack, and $39.99 for L snack.
    • FruitSnack has an additional fee of $5.99 when it has a citrus fruit. Please add only a single citrus fruit, and no preventing coding isrequired to limit addingmore than one.
    • SaltySnack has an additional fee of $4.50 when it has a nut snack. Please add

only a single nut snack no preventing coding is required tolimit adding more than one.

  • Each class must have a method to return or display the class's values to the console

 

  1. Implement OrderSystem class with main method with following functionality:
    • Order asnack and after ordering it will display the snack type, its size, id and price
    • Exit program

 

  1. Your classes must be coded with correct encapsulation: private/protected attributes, get methods, and set methods
  2. There should be appropriate overloading and overriding methods
  3. OrderSystem should take advantage ofthe inheritance properties (e.g., use Snack variable regardless which snack instance as appropriate)
  4. The prices for S, M, L, citrus fruit, nut snack can be hardcoded in the program.

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

Alright lets craft a tasty Java program based on your snack hierarchy specifications Well design the Snack class along with its child classes FruitSna... 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

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions

Question

Under what conditions is the following SQL statement valid?

Answered: 1 week ago