Question: Create a program named Lab 2 0 B . Create a secondary class named FruitBasket with: Instance variables: An int variable for number of apples

Create a program named Lab20B.
Create a secondary class named FruitBasket with:
Instance variables:
An int variable for number of apples
An int variable for number of oranges
An int variable for the number of pineapples
A constructor that accepts 3 parameters to fill in the instance variables. (The parameter data types should match the instance variable types.)
An int method that returns the number of apples (no parameters)
An int method that returns the number of oranges (no parameters)
An int method that returns the number of pineapples (no parameters)
A String method named toString that returns a string with each instance variable value and a label in front of each.
Create a secondary class named MyComparator that will compare two FruitBasket objects. If the value of the first is greater, return a 1. If the second is greater, return a -1. Otherwise return a 0.
The value of an object is determined by multiplying the number of apples by 5, the number of oranges by 2, the number of pineapples by 10 and then adding that all together.
In your main Lab20B class write a method that receives a linked list of FruitBasket objects as a parameter, and it should have a FruitBasket return type. It should use the MyComparator class to find and return the basket object with the highest value.
In the main method:
Create a LinkedList of FruitBasket objects.
Read lines from the text file, Input20B.txt to get the data for your FruitBasket objects. (You only need the numbers, not the words from the file.)
Read a number for apples, a number for oranges, and a number for pineapples for each basket.
Create each object and add it to the LinkedList.
Print the linked list with a label before it.
Call your method to find the highest valued basket and print the result.
I get this errors:
Exception in thread "main" java.lang.NumberFormatException: For input string: "5 apples"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:786)
at Lab20B.main(Lab20B.java:25)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!