Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING JAVA 1. Create a class that represents computer parts, and stores name, manufacturer, and price. It should use the following methods and validation. class

USING JAVA

1. Create a class that represents computer parts, and stores name, manufacturer, and price. It should use the following methods and validation. class should be named Parts.

- constructor must accept part name, manufacturer, and price (in that order) and should be validated based on rules in methods below

- setName() - receives string as argument, validates it is at least 3 characters long, then sets the name instance variable. throw IllegalArgumentException if it not is not valid

- setPrice() - receives double as argument, validates it is in range of 0-10,000, and sets price instance variable. same exception as above if not valid

- setManufacturuer() receives string as an argument, and should validate that the argument is in the list of "apple" "asus" "toshiba" "samsung". if validation passes, set instance variable, if not throw IllegalArgumentException

- toString() - returns string in format of "(name) - (manufacturer), (price)" - brackets indicate instance variables. Must show exactly 2 decimal places.

2. create a class named Order that stores a collection of Parts objects in an ArrayList.

- constructor should not accept arguments, but should initalize the arraylist instance to hold the Parts objects

- addItem() - should accept a Part as an argument, and add it to the ArrayList. no validation required.

- getTotalPrice() - sums up the cost of all Parts objects and return it as a double

- getPartName() - return a string object listing each of the Part objects separated by a comma. ex: "processor, mouse, case, keyboard".There is NO comma after the last Part listed

- toString() - returns a string object in the format of "The order has (x) parts with a grand total price of $[yy.yy]" x is number of parts, yy.yy is the total cost of all purchases.

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

c. What is the most likely value for X?

Answered: 1 week ago