Question
In Java Part 1 Inventory program In this program, we will input information from a file and save it into an ArrayList of objects. Item.java
In Java
Part 1
Inventory program
In this program, we will input information from a file and save it into an ArrayList of objects. Item.java
public class Item
{
private int id;
private String itemName;
private String itemType;
private double price;
//attributes
public Item()
{
id = 0;
setItemName("");
setItemType("");
price = 0.0;
}//default constructor
public Item( int i, String name, String type, double p )
}
id = i;
setItemName(name);
setItemType(type);
price = p;
}//overloaded constructor
public String getItemName() {
return itemName;
}
public void setItemName(String name) {
itemName = name;
}
public String getItemType() {
return itemType;
}
public void setItemType(String type) {
itemType = type;
}
public double getPrice(){
return price;
}
public int getId() {
return id;
}
public void setId(int i) {
id = i;
}
public double computeCost(int quantity)
{
double cost = price * quantity;
return cost;
}//computeCost
This is a simple Item class that contains an Item class with attributes for id, itemName, itemType, and price. It also has the following methods: default and overloaded constructors, set and get methods, and a computeCost method.
Inventory.java (to complete)
1
iPad Air
tablet
499.00
2
iPad mini
tablet
299.00
3iPad 2
Tablet
399.00
4
MacBook Pro
Laptop
1299.00
5
MacBook Air
Laptop
999.00
6
iMac
desktop
1299.00
7
iPhone 11
phone
599.00
8
iPhone 6
phone
349.00
9
Watch Series 6
Watch
399.00
10
Watch Series 6
Watch
749.00
11
iPhone 11
phone
499.00
Will contain a main method that imports data from a file called inventory.txt(is above text) and saves it into an ArrayList of Item objects. It then displays the information on the screen. It will then ask the user which item id to purchase, how many, and display the cost. Sample interaction:
Id Item name Item type Price 1 iPad Air tablet 499.00 2 iPad mini tablet 299.00 3 iPad 2 tablet 399.00 4 MacBook Pro laptop 1299.00 5 MacBook Air laptop 999.00 6 iMac desktop 1299.00 7 iPhone 11 phone 599.00 8 iPhone 6 phone 349.00 9 Watch Series 6 watch 399.00 10 Watch Series 6 watch 749.00 11 iPhone 11 phone 499.00
Enter the id of the item you wish to purchase: 8 Item name: iPhone 6 Item type: phone Price: 349.0 Enter the quantity to purchase: 2 Cost will be: 698.0
Part 2
Here we will build on the Student ArrayList program you have completed for your previous assignment. Enhance the program to input the information for the ArrayList of Student objects from a text file. When the program begins, the student information will be read in from the text file, for example class.txt, and the ArrayList will be created. Modify the "7 - Exit" option to be called "7 - Save and exit", and when a user chooses this option, the updated ArrayList of student information will be written to the file. Make sure to write the information to the file in the same format that it is input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started