Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fruit Baskets Sam has a small business whereby she sells fruit baskets that can be ordered for delivery to family and friends. Your job is

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Fruit Baskets Sam has a small business whereby she sells fruit baskets that can be ordered for delivery to family and friends. Your job is to create an application that simulates part of Sam's business. Unfortunately, at the moment Sam's ability to offer variety is severely limited. She can only put 3 fruit items in her baskets (each basket contains exactly 3 pieces of fruit). She can also swap the pieces of fruit out for new types. However, it's an 'all-or-nothing' operation. If a customer decides to change the type of fruit, they must change all three pieces. Create two object classes and one driver class for this assignment. Write a Java class Fruit that stores a name and price per unit. Write a second Java class FruitBasket that holds 3 Fruit objects. The total price for a FruitBasket is total of the unit price for each of the three Fruit objects, plus a base price of $10.00 that applles to all fruit baskets. You should develop two constructors for the FruitBasket class. 1. The first constructor for FruitBasket should accept three parameters: 3 Fruit objects. 2. The second constructor should accept six parameters: the names and prices of 3 fruit. This constructor creates the relevant Fruit objects as part of creating a FruitBasket. FruitBasket has a getTotalPrice() method, which adds together the base price of the basket with the unit price of each fruit. FruitBasket has a format( ) method that lists the names of the fruit in this FruitBasket in a sentence suitable for displaying to the user. Do not include price information. FruitBasket has a toString() method that displays the object information in our standard format. FruitBasket has a getTotalPrice() method, which adds together the base price of the basket with the unit price of each fruit. FruitBasket has a format() method that lists the names of the fruit in this FruitBasket in a sentence suitable for displaying to the user. Do not include price information. FruitBasket has a toString( ) method that displays the object information in our standard format. FruitBasket has a swapFruit( ) method that takes 3 Fruit objects as parameters and replaces the fruit in the basket with these new Fruit objects. Write a driver class TestFruitBasket that creates 2 FruitBasket objects and prints out the details and total price of each. Make sure you test both FruitBasket constructors. That is, create one FruitBasket object with the first constructor and the other object with the second constructor. Have your driver class get the names and unit prices of fruit from the user. Have your driver class test the toString( ) method for FruitBasket. Hint: you will also need a toString() method for Fruit. This is similar to how the toString() methods for Circle and Point are written, as described in Module 5. Make sure you conform to the to String() result formats shown in the sample output provided below. Have your driver class test the swapFruit() method. You can "hard-code" the Fruit the user for this test. Have your driver class test the swapFruit( ) method. You can "hard-code" the Fruit objects in the main method. That is, you do not have to gather more information from the user for this test. Display the fruit names and cost of this basket before and after the fruit has been swapped. Note: Later in the term we will learn how to create lists of objects, but for now you will need to create 3 separate Fruit instance variables in your FruitBasket class. Helpful Hint: You will need to create quite a few methods for your FruitBasket class, so it is important that you practice incremental development. Write one method at a time in your Fruit and FruitBasket classes. Each time you do, add a relevant test to your main method. Compile, test and debug that code before you attempt to move on to the next method. This will save you plenty of time in the long run. Sample Output: The following is an example of what the output from the driver program might resemble. Use different test values when testing your own program. Make your first fruit basket Enter the name of the first fruit orange Enter the unit price for orange 0.75 Enter the name of the second fruit apple Finter the unit price for apple 0.25 Make your first fruit basket Enter the name of the first fruit orange Enter the unit price for orange 0.75 Enter the name of the second fruit apple F.nter the unit price for apple 0.25 Enter the name of the third fruit pineapple Enter the price for pineapple 4.25 The first fruit basket: This fruit basket contains a(n) orange, a(n) apple and a(n) pineapple The total price for the first fruit basket is $15.25 Testing tostring() FruitBasket [f]=Fruit [name=orange, price=0. 75], f2=Fruit [name=apple, price=0.25], f3=Fruit [name=pineapple, price =4.25]] Make a second fruit basket- Enter the name of the first fruit mango Enter the unit price for mango 2.50 Enter the name of the second fruit banana Enter the unit price for banana 1.25 Enter the name of the third fruit melon Enter the unit price for melon 6.00 The second fruit basket: This fruit basket contains a(n) mango, a(n) banana and a(n) melon The total cost for the second fruit basket is $19.75 After swapping out the fruit in the second basket: This fruit basket contains a(n) strawberry, a (n) blueberry and a (n) papaya The total cost for the second fruit basket is $27.650000000000002

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

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions

Question

3. Define the attributions we use to explain behavior

Answered: 1 week ago