JAVA Create an application that allows the user to put diffe

JAVA: Create an application that allows the user to put different types of fruit into a basket. First create a base class called Fruit. Using inheritance, create at least 5 types of specific fruits (e.g. Apple, Banana, Pear, Orange, Grape) and define those classes as subclasses from Fruit. Each Fruit object has the following fields: color, weight, price. In addition, each specific fruit can have additional fields. Examples are, an Apple can have a field AppleSubtype, which can hold the apple’s subtype (e.g. Granny Smith). A banana can have a field called Length. Grapes can have a field for number of grapes on one vine. Be creative and add at least 1 field to each individual, specific fruit class. The user has a basket (an array) that can hold 10 times. The user is asked how many of each items he wants to add to the basket, until either the basket is full, or each fruit has been offered to the user. Once the basket is full or the user chooses not to add 10 items, let the user know what the total weight of the basket is, and what the total price of the fruits is. You can decide yourself on the weights and the prices, but use somewhat appropriate numbers

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

-----------------------------------------------------------

OUTPUT:

Enter how many of each items he wants to add to the basket
How many Apples to add ?
2
How many Banana to add ?
3
How many Pear to add ?
2
How many Orange to add ?
1
How many Grape to add ?
4
Basket is full
Total weight = 65.61321809493714
Total price = 65.39888141204088

JAVA: Create an application that allows the user to put different types of fruit into a basket. First create a base class called Fruit. Using inheritance, creat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site