Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a java code Design a class that stores information about products that are sold in a store. Write a class named Item that has

write a java code

Design a class that stores information about products that are sold in a store. Write a class named Item that has (at least) the following member variables:

name: a String that holds the name of the inventory item.

vendor: a String that stores the name of the vendor for the product.

salePrice: a double that stores the current selling price of the item (how much the customer pays to buy it).

costPrice: a double that stores the current cost price of the item (how much the store pays to acquire it).

weight: a double that stores the weight of a single item of this type.

taxable: a boolean field that indicates whether or not tax is charged on the item.

Make sure to choose appropriate access specifiers for the data members and methods in your Item class.

In addition, the class should have the following member methods:

Constructor. The constructor should accept the items name, cost price, and selling price as arguments and assign these values to the object's name, costPrice, and salePrice member variables. The constructor should initialize the weight to 1 and taxable to true.

Accessors. Appropriate accessor methods should be created to allow values to be retrieved from an object's name, vendor, salePrice, weight, and taxable member variables.

Mutators. Appropriate mutator methods should be created to allow values to be changed in an objects weight and taxable fields.

increaseCost. This method should increase the cost price by 1 dollar. This is a void method since it modifies the current state of the object.

profit. This method should accept no parameters and return the profit on the item, which is calculated as the cost price subtracted from the selling price.

Demonstrate the class in a program that creates an Item object. Then increase the cost 3 times by a dollar, calculate the profit and display it on the screen. Call the mutator method that sets the weight to a number you specify. Create several other Item objects and see that the fields have different values.

If your Item class is written properly, the following lines of code should be valid in your main method:

Item chair = new Item("Desk Chair", 30, 55); //increase cost price by $3.

chair.increaseCost();

chair.increaseCost();

chair.increaseCost();

//display the profit

System.out.println("The chairs profit is now $" + chair.profit());

//set the chairs weight to 7 lb

chair.setWeight(7);

Item table = new Item("Picnic Table, 70, 88);

System.out.println("The tables profit is now $" + table.profit());

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_2

Step: 3

blur-text-image_3

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Is Jacks dream a social venture opportunity or merely a dream?

Answered: 1 week ago

Question

3. Evaluate a Web-based training site.

Answered: 1 week ago