0% found this document useful (0 votes)
16 views

Coding Assignment - Fruit Stand

The document outlines a coding assignment to create a fruit stand program using inheritance with abstract classes and methods. The program should allow users to select and purchase fruits, validate inputs, and display purchase details including total price with tax. It requires implementing a Fruit abstract class and at least two fruit subclasses, along with a demo class to showcase functionality.

Uploaded by

firelightning01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Coding Assignment - Fruit Stand

The document outlines a coding assignment to create a fruit stand program using inheritance with abstract classes and methods. The program should allow users to select and purchase fruits, validate inputs, and display purchase details including total price with tax. It requires implementing a Fruit abstract class and at least two fruit subclasses, along with a demo class to showcase functionality.

Uploaded by

firelightning01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Coding Assignment: Fruit Stand – Inheritance with Abstract classes and methods

Objective:
Create a comprehensive program that emulates a fruit stand. The program should initiate by prompting the user to
input the type of fruit they would like to purchase. After, the user selects the type of fruit they would like to
purchase, the program will prompt the user to enter the amount of the fruit item that they would like to purchase.
After, the amount is entered, the program will prompt the user if they would like to continue shopping. If the user
chooses to continue the program will continue to run until the user chooses to stop shopping. Upon completion of
shopping, the program should display the fruit with their amounts and total price of the purchase.

Requirements:
1. Class – Fruit
o Create an abstract class named Fruit.
o Define at least three fields to describe the fruit with the appropriate access modifiers (e.g. color,
type, etc.)
o Define a price variable with the appropriate access modifier
Constructors:
o Implement a copy constructor that takes a Vehicle object as a parameter and initializes the fields
accordingly.
Methods:
o Define necessary accessor and mutator methods.
o Define at least three abstract methods for this class
o Define another abstract method to calculate the total price of the fruit. Add a 7% sales tax to
each purchase
2. Fruit Classes – Create a least two other classes that represent a piece of fruit (e.g. orange, kiwi). These
classes will inherit the Fruit class – These classes must be implemented in different files
o Class names should reflect the type of fruit that is being implemented
Methods:
o Implement all abstract methods (override the method in the Fruit class to calculate the total
price of the fruit
o Override the toString method to reflect each specific fruit details
3. Class - Demo
o Demonstrate the functionality of the fruit stand in a separate class called Demo.
o Create necessary objects from Fruit classes to allow users to shop

4. Input Validation
o Ensure users can input case-insensitive values to quit the program.
o Validate menu options to ensure that only valid selections are accepted, catching any invalid
inputs.
5. Output
o Display fruit stand information in a user-friendly format
o Format prices to include dollar signs, two decimal places, and commas
o Display fruit price and total price of purchase after the user finishes shopping
6. Implementation Details
o Utilize concepts from chapters 1-11 only.
o Follow the program rubric closely.
7. Naming Convention
o Name the project fruit-stand.zip.
o Export your project as a zip file.

Sample Runs (Please use your own fruit classes. The fruits below are for example):
Run 1 – Purchase one fruit item
---------------------------------------------
Welcome to the Fruit Stand!
We sell Red Apples, Green Apples, and Bananas
---------------------------------------------
What fruit would you like to purchase? Banana

How many Bananas would you like to purchase? 1


Would you like to continue shopping? (Yes or No) No
You purchased 1 Banana(s) at $1.39 each.
Product Details:
Color: Yellow
Texture: Soft
Type: Organic
Has Seeds: true
Your total price is $1.49

Run 2a - Input Validation


---------------------------------------------
Welcome to the Fruit Stand!
We sell Red Apples, Green Apples, and Bananas
---------------------------------------------
What fruit would you like to purchase? 1
Invalid Selection please choose Red Apple, Green Apple, or Banana

Run 2b – Input Validation


---------------------------------------------
Welcome to the Fruit Stand!
We sell Red Apples, Green Apples, and Bananas
---------------------------------------------
What fruit would you like to purchase? Banana

How many Bananas would you like to purchase? 1


Would you like to continue shopping? (Yes or No) Banana
Invalid Input, Please try again
Yes
What fruit would you like to purchase?

Run 3 – Continuous Shopping and Price calculation


---------------------------------------------
Welcome to the Fruit Stand!
We sell Red Apples, Green Apples, and Bananas
---------------------------------------------
What fruit would you like to purchase? Banana

How many Bananas would you like to purchase? 1


Would you like to continue shopping? (Yes or No) Yes
What fruit would you like to purchase? Red Apple
How many Red apples would you like to purchase? 1
Would you like to continue shopping? (Yes or No) Yes
What fruit would you like to purchase? Green Apple
How many Red apples would you like to purchase? 1
Would you like to continue shopping? (Yes or No) No
You purchased 1 Banana(s) at $1.39 each.
Product Details:
Color: Yellow
Texture: Soft
Type: Organic
Has Seeds: true
You purchased 1 Green Apple(s) at $2.34 each.
Product Details:
Color: Green
Texture: Smooth
Type: Farm Grown
Has Seeds: true
You purchased 1 Red Apple(s) at $2.34 each.
Product Details:
Color: Red
Texture: Smooth
Type: Farm Grown
Has Seeds: true
Your total price is $6.49

You might also like