Modify the FrultBasket class as follows: - Fruit baskets should have one attribute basket: an array list that hold the Frult objects. - Build a constructor for FrultBasket - Create a addFrult() method that allows you to add another fruit to the fruit basket. ·A tostring() method is already provided. FruitBasket ArrayList

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java. Create a new class FruitBasket that will store fruit objects in a basket.

Starter code.

import java.util.*;


public class Fruit
{
//attributes
protected String name = null;
protected String colour = null;

//constructor
public Fruit(String name, String colour)
{
this.name = name;
this.colour = colour;
}

//Getters
public String getName(){return name;}
public String getColour(){return colour;}

//Setters
public void setName(String name){this.name = name;}
public void setColour(String colour){this.colour = colour;}

public String toString()
{
String fruitDetails = name+" ("+colour+")";

return fruitDetails;
}
}

 

 

import java.util.*;

public class FruitBasket
{

public String toString()
{
String basketContents = "FRUIT BASKET:\n";
for (Fruit fruit: basket)
{
basketContents += fruit.toString()+"\n";
}

return basketContents;
}
}

 

import java.util.*;

public class PoD
{

public static void main( String [] args ) {

Scanner in = new Scanner( System.in );

FruitBasket fruitBasket = new FruitBasket();

while(in.hasNextLine()){
String line = in.nextLine();
String[] fruitDetails = line.split(" ");

Fruit nextFruit = new Fruit(fruitDetails[0],fruitDetails[1]);
fruitBasket.addFruit(nextFruit);
}

System.out.println(fruitBasket);

in.close();
System.out.print("END OF OUTPUT");
}
}

 

 

 

Details
Input
Input is handled for you for this problem in POD.java.
Processing
Modify the FrultBasket class as follows:
- Fruit baskets should have one attribute basket: an array list that hold the Frult objects.
- Build a constructor for FrultBasket
Create a addFruitſ) method that allows vou to add another fruit to the fruit basket.
- A tostring() method is already provided.
FruitBasket
ArrayList<Fruit> : basket
void : addFruit(Fruit)
String : toString()
Output
The format of the output is given to you by the toString() method in the FrultBasket object class. This will be used by the main method in POD.java
Sample Input/output:
Sample Input
Sample Output
FRUIT BASKET:
apple red
apple (red)
pear green
pear (green)
END OF OUTPUT
Transcribed Image Text:Details Input Input is handled for you for this problem in POD.java. Processing Modify the FrultBasket class as follows: - Fruit baskets should have one attribute basket: an array list that hold the Frult objects. - Build a constructor for FrultBasket Create a addFruitſ) method that allows vou to add another fruit to the fruit basket. - A tostring() method is already provided. FruitBasket ArrayList<Fruit> : basket void : addFruit(Fruit) String : toString() Output The format of the output is given to you by the toString() method in the FrultBasket object class. This will be used by the main method in POD.java Sample Input/output: Sample Input Sample Output FRUIT BASKET: apple red apple (red) pear green pear (green) END OF OUTPUT
Instructions
Today you will be given a Frult class. From this, you will create a new class FrultBasket that will store fruit objects in a basket, just as you might on a Saturday morning down at the Halifax Seaport Farmers' Market. If you haven't checked that out, by the way,
you should!
The Frult class has the following fields:
name (String) : name of the fruit
colour (String): colour of the fruit's skin
It has a constructor and five methods, including a toString() method, 2 getters and 2 setters.
Fruit
String : name
String : colour
String : getName()
String : getColour()
void : setName(String)
void : setColour(String)
String : toString()
Details
Input
Input is handled for you for this problem in PoD.java.
Processing
Modify the FrultBasket class as follows:
- Fruit baskets should have one attribute basket: an array list that hold the Frult objects.
- Build a constructor for FrultBasket
- Create a addFrult() method that allows you to add another fruit to the fruit basket.
A toString() method is already provided.
Transcribed Image Text:Instructions Today you will be given a Frult class. From this, you will create a new class FrultBasket that will store fruit objects in a basket, just as you might on a Saturday morning down at the Halifax Seaport Farmers' Market. If you haven't checked that out, by the way, you should! The Frult class has the following fields: name (String) : name of the fruit colour (String): colour of the fruit's skin It has a constructor and five methods, including a toString() method, 2 getters and 2 setters. Fruit String : name String : colour String : getName() String : getColour() void : setName(String) void : setColour(String) String : toString() Details Input Input is handled for you for this problem in PoD.java. Processing Modify the FrultBasket class as follows: - Fruit baskets should have one attribute basket: an array list that hold the Frult objects. - Build a constructor for FrultBasket - Create a addFrult() method that allows you to add another fruit to the fruit basket. A toString() method is already provided.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education