Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help inputing the following compiling the following JAVA code in NETBEANS. it is for How to program Java tenth edition chapter 3. Create

I need help inputing the following compiling the following JAVA code in NETBEANS. it is for How to program Java tenth edition chapter 3.

Create a Candy class

Instance variables: name (String), price (double), quantity (int)

Constructor take a String to set the name

Get and set methods for each instance variables

If attempt to set quantity to a negative number, print a message and set it to 1

display() will print the data in the format name quantity at price

Print price with 2 decimal places

getCost() returns quantity * price

TestCandy class should contain main()

Display the Candy object

Prompt for the name, price, quantity (all on separate lines)

Use nextLine for name

Set the data in a Candy object

Display the Candy object

Display the cost of for the Candy object

Requirements:

Put System.out.println() after you finish each call to a next Scanner methodThis will help you match the Test Program and make it easier to use it.

Sample Run #1: (the highlighted text is what the user types)

Default: Kit Kat - 0 at 0.00

Enter new name: Reese

Price: 1.50

Quantity: 2

Updated: Reese - 2 at 1.50

Total cost = $3.00

Sample Run #2: (the highlighted text is what the user types)

Default: Kit Kat - 0 at 0.00

Enter new name: Snickers

Price: 2.75

Quantity: -3

Sorry no negative quantities -- setting to 1

Updated: Snickers - 1 at 2.75

Total cost = $2.75

Extra Notes:

Did you correctly name the package/folder?

Did you correctly name the class/file?

Did you include comments?

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

More Books

Students also viewed these Databases questions