Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 LabB
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 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 If the second is greater, return a Otherwise return a
The value of an object is determined by multiplying the number of apples by the number of oranges by the number of pineapples by and then adding that all together.
In your main LabB 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, InputBtxt 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: apples"
at java.basejavalang.NumberFormatException.forInputStringNumberFormatExceptionjava:
at java.basejavalang.Integer.parseIntIntegerjava:
at java.basejavalang.Integer.parseIntIntegerjava:
at LabBmainLabBjava:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started