Question: in java, Write a program which maintains the inventory of an auto dealer. Create a text file of a dealers inventory. The program must read

in java, Write a program which maintains the inventory of an auto dealer. Create a text file of a dealers inventory. The program must read the data into an ArrayList and then maintain it with sales and supplies. We need to create a class of inventory as each line of data will have different types of data. Then we need to create an ArrayList of these objects.

The program should read from a file and store it in a list. It should print the original inventory. I HAVE ATTACHED THE PROGRAMS NEEDED FOR THIS PART WITH A TEXT FILE. YOU SHOULD ADD THE REST. You should ask the user what he/she wants to do:

1. Print the inventory

2.Make a sale

3. Add the new supplies

4. Whenever a purchaser buys a car, it should print the total cost. I HAVE ADDED A METHOD IN THE INVENTORY CLASS.

dealer.txt

Caravan 10 19000 Corolla 25 25450 Mustang 20 31000 ChevyVolt 13 35800 Tesla3 8 42099 E-series 5 63876

This code is partly done but i need help finishing it.

( please do as simple as possible using the rest of my code, and explain with comments so that i may understand as much as possible. we are only on chapter 6. only use IF or CASE statements and not FOR statments nor parrsing please.)

import java.util.ArrayList; import java.util.Scanner; import java.io.*;

public class Inventory { private String model; private int stock; private double price; public Inventory() {} public Inventory(String md, int st, double pr) { model = md; stock = st; price = pr; } public String getModel() { return model; } public int getStock() { return stock; } public double getPrice() { return price; } public void update() // assuming a customer will buy only 1 car. { stock--; } public double salesPrice(double txRt, double registration) { return price+price*txRt/100 + registration; } /* public static void main(String args[]) { Inventory inv = new Inventory("Dodge",25, 23000); System.out.println(inv.getModel()+"\t"+inv.getStock()+"\t"+inv.getPrice()); }*/ public static void main(String args[]) throws IOException { Scanner file = new Scanner(new File("dealer.txt")); ArrayList stock = new ArrayList(); Scanner kb = new Scanner(System.in); Inventory inventory, inv1; String mod; int num; double price; while (file.hasNext()) { mod = file.next(); num = file.nextInt(); price = file.nextDouble(); inventory = new Inventory(mod,num,price); stock.add(inventory); } System.out.println(stock); // this prints the addresses where the // objects are stored, the pointers System.out.println(" "); System.out.println(" Model\tStock\tPrice"); System.out.println(" -----\t-----\t-----"); // Observe that stock.get(index) returns the first element of the // ArrayList stock, which is the first inventory object. // When index is zero, it returns the first object. So attaching // getModel() will return the first model which is model1. int index=0; while(index { inv1 = stock.get(index); // first object of ArrayList stock, an Inventory object System.out.println(index+". "+inv1.getModel()+"\t"+inv1.getStock()+"\t$"+inv1.getPrice()); index++; } // ADD SEVERAL OPTIONS THAT THE USER COULD SELECT FROM AND PERFORM // THE ACTIONS /* double price1 = stock.get(2).salesPrice(8.5,200); System.out.println(" Inv1 sales price = $"+price1);*/ // THIS PART CAN BE USED FOR Make a sale PART OF THE HW. System.out.print(" which model do you want to buy?, enter the number:"); num = kb.nextInt(); inv1 = stock.get(num); System.out.println("You have chosen "+inv1.getModel()+" model"); System.out.println("Your price is $"+inv1.salesPrice(10,500)); inv1.update(); System.out.println("There are "+inv1.getStock()+" of this model"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!