Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your bank makes many automobile loans. You need to write a program that tracks t

ID: 3831189 • Letter: Y

Question

Your bank makes many automobile loans. You need to write a program that tracks the automobiles that are collateral for automobile loans. You need to track vehicle identification number (VIN), make, model, year, loanID, and newCar. Make is the “brand”, for example Ford, Toyota, Subaru, Kia. The model would be “Mustang,” “WRX,” “Sportage.” The loan ID is the unique number for each loan made by the bank and newCar is a boolean field which stores the value “true” if the car was purchased new and false if used. All of this information is entered into the “inventory.txt” file and should be read in when your program starts. You should use an array or an array list to store the information on each car.

Your program is a collateral lookup program and will ask the user for the VIN of a car, and then will display all of the available information for that car. Your program should handle bad inputs gracefully, meaning you should include a try-catch block and be able to throw both a FileNotFound Exception and an IllegalArgument Exception and should repeat its task until you enter “quit” as a VIN.

It should output something like:

Explanation / Answer

import java.io.*;
import java.util.*;

class Car{
  
    String VIN;
    String make;
    String model;
    int year;
    long loanID;
    boolean newCar;
  
    public void setVIN(String VIN){
      
        this.VIN=VIN;
    }
    public String getVIN(){
      
        return this.VIN;
    }
  
    public void setMake(String make){
      
        this.make=make;
    }
    public String getMake(){
      
        return this.make;
    }
  
    public void setModel(String model){
      
        this.model=model;
    }
    public String getModel(){
      
        return this.model;
    }
  
    public void setYear(int year){
      
        this.year=year;
    }
    public int getYear(){
      
        return this.year;
    }
    public void setLoanId(long loanID){
      
        this.loanID=loanID;
    }
    public long getLoanId(){
      
        return this.loanID;
    }
    public void setNewCar(boolean newCar){
      
        this.newCar=newCar;
    }
    public boolean getNewCar(){
      
        return this.newCar;
    }
  
}


public class HelloWorld{

     public static void main(String []args){
      
        try{
       
         String carVIN;
         Scanner in = new Scanner(System.in);
         ArrayList <Car> carList = new ArrayList<Car> ();      
         FileReader freader = new FileReader("inventory.txt");
         BufferedReader br = new BufferedReader(freader);
         String s;
         while((s = br.readLine()) != null) {
       
            Car c = new Car();
            String[] splited = s.split("\s+");
            c.setVIN(splited[0]);
            c.setMake(splited[1]);
            c.setModel(splited[2]);
            c.setYear(Integer.parseInt(splited[3]));
            c.setLoanId(Long.parseLong(splited[4]));
            c.setNewCar(Boolean.parseBoolean(splited[4]));
          
            carList.add(c);
         }
       
         freader.close();
       
         while(true){
       
         System.out.println("Please Enter VIN of the car : ");
         carVIN=in.nextLine();
       
       
          if(carVIN.equals("quit")){
               
                 break;
          }
          else{
           for(Car c1 : carList){
           
             if(c1.getVIN().equals(carVIN)){
               
               System.out.print(c1.getVIN()+" "+c1.getMake()+" "+c1.getModel()
               +" "+c1.getYear()+" "+c1.getLoanId()+" "+c1.getNewCar());
               System.out.println();
               
             }
          }
        
          }
        }
       
        }catch(IllegalArgumentException E){
          
            System.out.println(E.getMessage());
        }
        catch(FileNotFoundException E){
          
            System.out.println(E.getMessage());
        }
        catch(IOException E){
          
            System.out.println(E.getMessage());
        }
      
     }
}

/*
output :-

Please Enter VIN of the car :                                                                                                                                            

3422XZ5                                                                                                                                                                  

3422XZ5 Ford Explorer 2013 11053 false                                                                                                                                   

Please Enter VIN of the car :                                                                                                                                            

123                                                                                                                                                                      

Please Enter VIN of the car :                                                                                                                                            

quit

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote