Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Candy class Add a private field (instance variable) for nuts. public Candy() calls the no-arg constructor of the parent class and then sets nuts

java

Candy class

Add a private field (instance variable) for nuts.

public Candy()

calls the no-arg constructor of the parent class and then sets nuts to false. This means, it contains no nuts by default.

public Candy(String name, double price, int quantity, boolean nuts)

calls the parent constructor. Which parameters must be sent?

sets the nuts data field to the value of nuts.

Add a public accessor and mutator for nuts.

public void display()

(Overrides the parents display method)

Calls the display method of the parent

Displays either (nuts) or (no nuts) depending if the nuts instance variable is true or false.

public String toString()

(Overrides the object class toString method)

Creates and returns a string that is built from:

Candy, plus

the returned result of the parents toString() method plus

a comma and the value stored in nuts.

Sample return value: Candy,Snickers,0.85,10,true

public void store(PrintWriter outFile) throws IOException

outFile refers to an opened output file stream

There is only one line of code that will print the returned result from the toString() method to the output stream.

Soda class

Add a private field (instance variable) for caffeine.

public Soda()

calls the no-arg constructor of the parent class and then sets caffeine to false. This means, it contains no caffeine by default.

public Soda(String name, double price, int quantity, boolean caffeine)

calls the parent constructor. Which parameters must be sent?

sets the caffeine data field to the value of caffeine.

Add a public accessor and mutator for caffeine.

public void display()

(Overrides the parents display method)

Calls the display method of the parent.

Displays either (caffeine) or (no caffeine) depending if the caffeine instance variable is true or false.

public String toString()

(Overrides the object class toString method)

Creates and returns a string that is built from:

Soda, plus

The returned result of the parents toString() method plus

a comma and the value stored in caffeine.

Sample return value: Soda,Mtn Dew,0.9,8,true

public void store(PrintWriter outFile) throws IOException

outFile refers to an opened output file stream

There is only one line of code that will println out to outFile the returned result from the toString() method.

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What determines the shape of the IS and LM curves?

Answered: 1 week ago

Question

17. What were the objections made by opponents of the PPACA? LO24.6

Answered: 1 week ago