Answered step by step
Verified Expert Solution
Link Copied!

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 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

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions