P2: Write a class Item that stores information about an object in a store. It should have variables for: the name of the item the full price of the item the sales price of the item Each price of the item should be stored as a double.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

answer should be in java with a easy method

P2: Write a class Item that stores information about an object in a store.
It should have variables for:
the name of the item
the full price of the item
the sales price of the item
Each price of the item should be stored as a double.
Write two constructors for this class: one which has the name of the item, the
full price, and the sales price as parameters, and one which only has the name
of the item and the full price as parameters. In the second case, the sales
price should be set to half the full price.
Write a method called format which takes a double as its parameter and returns
a string representing the double as a price. Specifically, put a $ in front of
the double value, and round the value to have exactly 2 decimal places. If the
double value is less than e, return $0.00. If the double value only has one
decimal place, add a e at the end (ex. 6.7 becomes $6.70)
Transcribed Image Text:P2: Write a class Item that stores information about an object in a store. It should have variables for: the name of the item the full price of the item the sales price of the item Each price of the item should be stored as a double. Write two constructors for this class: one which has the name of the item, the full price, and the sales price as parameters, and one which only has the name of the item and the full price as parameters. In the second case, the sales price should be set to half the full price. Write a method called format which takes a double as its parameter and returns a string representing the double as a price. Specifically, put a $ in front of the double value, and round the value to have exactly 2 decimal places. If the double value is less than e, return $0.00. If the double value only has one decimal place, add a e at the end (ex. 6.7 becomes $6.70)
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY