Write in Java a class named RetailItem that holds data about an item in a retail store. The class should have the follow

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Write in Java a class named RetailItem that holds data about an item in a retail store. The class should have the follow

Post by answerhappygod »

Write in Java a class named RetailItem that holds data about an
item in a retail store. The
class should have the following fields:
 description: The description field is a String object that holds
a brief
description of the item.
 unitsOnHand: The unitsOnHand field is an int variable that holds
the
number of units currently in inventory.
 Price: The price field is a double that holds the item’s retail
price.
Write appropriate constructor and mutator methods that store values
in these
fields, and accessor methods that return the values from these
fields. Note: Your
mutator methods must protect your object from bad data.
Next create a file that contains the following data. Each row below
should be 1
row in the file. Name this RetailItemDatabase.txt.
Description Units On Hand Price
Jacket 12 59.95
DesignerJeans 40 34.95
Shirt 20 24.95
Create a method in RetailItem called readData(). This method reads
one
record/line from the file and initializes its data members (fields)
to the values in
that line. This method will have 1 input that is a Scanner
reference to the file
RetailItemDatabase.txt.
Now create main program. The main program should create 3
RetailItems using
an array. Then it should open the file RetailItemDatabase can call
readData for
all 3 RetailItems. When done don’t forget to close the file. Next
using your
accessor methods print the data in each of the 3 RetailItems.
Create a method in RetailItem called writeData(). This method
writes one
record/line to a file. This method will work very similar to
readData(), but instead
of reading instance data from the file it will write 1 row/line
of instance data to
the file. Test this method in main(). Main will open a new file
called
newRetailItemDatabase.txt using the PrintWriter class which will be
passed into
writeData as a parameter so it can write to the file.
Make sure your main program tests each of the methods in
RetailItem. Also,
make sure RetailItem has the necessary constructors. This will be
put into eclipse, please describe the purpose of every line to I
can understand with //.
The RetailItemDataBae.txt file can't be attached but the
content it
DesignerJeans 40 34.95
Shirt 20 24.95
Jacket
Jacket 12.0 59.95
Jacket 12
Jacket 12 $59.95
Jacket -12 59.95
Jacket 12 -59.95
Jacket 12 59.95 xyz
Jacket 12 59.95
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply