1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
I am Lyosha [343]
3 years ago
5

Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an

ArrayList list. Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program are located.
Class Car describes one car object and has variables vin, make, model all of String type, cost of type double, and year of int type. Variable vin is vehicle identification number and consist of digits and letters . In addition, class Car has methods:

public double getCost() // returns car’s cost

public String getMake() // returns car’s make

public boolean isExpensive() // returns true if car has cost above 30000 and false

//otherwise

public boolean isAntique() // returns true if car’s has above 50 years, and false

// otherwise

public String toString() // returns string with all car’s data in one line

// separated by tabs.

Design class CarList that has instance variable list of ArrayList type. Variable list is initialized in the constructor by reading data for each car from an input file. Each line of input file "inData.txt" has vin, make, model, cost, and year data in this order, and separated by a space. The data for the first five cars in the input file should be as follows:

1234567CS2 Subaru Impreza 27000 2017

1233219CS2 Toyota Camry 31000 2010

9876543CS2 Ford Mustang 51000 1968

3456789CS2 Toyota Tercel 20000 2004

4567890CS2 Crysler Royal 11000 1951

Add remaining two rows for the two additional cars of your choice.

Class CarList also has the following methods:

public void printList() // Prints title and list of all cars (each row prints one car)
public void printExpensiveCars() //Prints "List of expensive cars:" followed by
// list of expensive cars (one car per row)

public Car cheapestCar() // Method returns Car object with lowest cost.
public int countCarsWithModel(String model) // Method accept model and
// returns count of cars with given model.

//Method antiqueCarList is extra credit.

public ArrayList antiqueCarList () // Returns ArrayList of all antique
//cars from the list.

The last three methods just return the specified data type. Do not print anything within those methods. Just return result, and have explanation printed at the place where those methods are invoked.

Class TestCarList will have main method. In it, instantiate an object from CarList class and use it to invoke each of the five methods from CarList class.

Do not forget to append throws IOException to the constructor of CarList class and main method header in class TestCarList. In addition, you have to provide

import java.io.*;

import java.util.*;

in order to use Scanner and ArrayList classes from Java.

SUBMIT a single word or PDF document named p1yourLastNameCS152 with the following:

Your name, class section and project number and date of submission in the upper left corner
Copy of the code for each class in separate rectangle (table of size 1x1 with single cell)
Copy of your input file
Picture of program run from BlueJ.
Computers and Technology
1 answer:
vaieri [72.5K]3 years ago
3 0

Answer:

Java code is explained below

Explanation:

// Car.java

import java.util.Calendar;

public class Car {

  private String vin;

  private String make;

  private String model;

  private double cost;

  private int year;

  public Car(String vin, String make, String model, double cost, int year) {

      this.vin = vin;

      this.make = make;

      this.model = model;

      this.cost = cost;

      this.year = year;

  }

  public String getModel() {

      return model;

  }

  public double getCost() // returns car’s cost

  {

      return cost;

  }

  public String getMake() // returns car’s make

  {

      return make;

  }

  public boolean isExpensive() // returns true if car has cost above 30000 and

                                  // false

  // otherwise

  {

      if (cost > 30000)

          return true;

      else

          return false;

  }

  public boolean isAntique() // returns true if car’s has above 50 years, and

                              // false

  // otherwise

  {

      int cyear = Calendar.getInstance().get(Calendar.YEAR);

      if ((cyear-year) > 50)

          return true;

      else

          return false;

  }

  public String toString() // returns string with all car’s data in one line

  // separated by tabs.

  {

      return vin + "\t" + make + "\t" + model + " " + cost + "\t" + year;

  }

}

___________________________

// CarList.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class CarList {

  private ArrayList<Car> type;

  public CarList() throws FileNotFoundException {

      this.type = new ArrayList<Car>();

      Scanner sc1 = new Scanner(new File("inData.txt"));

      while (sc1.hasNextLine()) {

          String str = sc1.nextLine();

          String arr[] = str.split(" ");

          type.add(new Car(arr[0], arr[1], arr[2], Integer.parseInt(arr[3]),

                  Integer.parseInt(arr[4])));

      }

      sc1.close();

  }

 

  public void printList()

  {

      System.out.println("Displaying cars:");

      for(int i=0;i<type.size();i++)

      {

          System.out.println(type.get(i));

      }

  }

  public void printExpensiveCars()

  {

     

      System.out.println("List of expensive cars:");

      for(int i=0;i<type.size();i++)

      {

          if(type.get(i).isExpensive())

          {

              System.out.println(type.get(i));

          }

      }

  }

 

  public Car cheapestCar()

  {

      int cheapIndx=0;

      double min=type.get(0).getCost();

      for(int i=0;i<type.size();i++)

      {

      if(min>type.get(i).getCost())

      {

          min=type.get(i).getCost();

          cheapIndx=i;

      }

      }

      return type.get(cheapIndx);

  }

  public int countCarsWithModel(String model)

  {

      int cnt=0;

      for(int i=0;i<type.size();i++)

      {

          if(type.get(i).getModel().equals(model))

          {

              cnt++;

          }

      }

      return cnt;

  }

 

  public ArrayList<Car> antiqueCarList ()

  {

      ArrayList<Car> arl=new ArrayList<Car>();

      for(int i=0;i<type.size();i++)

      {

          if(type.get(i).isAntique())

          arl.add(type.get(i));

      }

      return arl;

  }

}

_________________________________

// TestCarList.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class TestCarList {

  public static void main(String[] args) throws FileNotFoundException {

      CarList cl = new CarList();

      cl.printList();

      cl.printExpensiveCars();

      ArrayList arl = cl.antiqueCarList();

      System.out.println("Displaying the AntiqueCar list:");

      for (int i = 0; i < arl.size(); i++) {

          System.out.println(arl.get(i));

      }

      System.out.println("Displaying the cheapest car :");

      System.out.println(cl.cheapestCar());

      System.out.println("No of Royal model Cars :"+ cl.countCarsWithModel("Royal"));

  }

}

____________________________

Output:

Displaying cars:

1234567CS2   Subaru   Impreza 27000.0   2017

1233219CS2   Toyota   Camry 31000.0   2010

9876543CS2   Ford   Mustang 51000.0   1968

3456789CS2   Toyota   Tercel 20000.0   2004

4567890CS2   Crysler   Royal 11000.0   1951

List of expensive cars:

1233219CS2   Toyota   Camry 31000.0   2010

9876543CS2   Ford   Mustang 51000.0   1968

Displaying the AntiqueCar list:

9876543CS2   Ford   Mustang 51000.0   1968

4567890CS2   Crysler   Royal 11000.0   1951

Displaying the cheapest car :

4567890CS2   Crysler   Royal 11000.0   1951

No of Royal model Cars :1

You might be interested in
Write a program to check the password( qbasic)​
snow_tiger [21]

Answer:

Assuming this is in python:

def check_password(password):

   

   correct_password = "qbasic"

   

   if password == correct_password:

       return True

   else:

       return False

def main():

   

   user_input = input("Type in your password: ")

   

   if check_password(user_input):

       print("Correct!")

   else:

       print("Wrong, try again")

     

       

main()

Explanation:

Hope this helped :) If it wasn't suppose to be in python, tell me so I can make it in the correct programming language.

Have a good day :)

4 0
2 years ago
How is the pattern matching done in the SQL?
Alinara [238K]

Answer:

SQL pattern matching allows you to search for patterns in data if you don't know the exact word or phrase you are seeking. This kind of SQL query uses wildcard characters to match a pattern, rather than specifying it exactly. For example, you can use the wildcard "C%" to match any string beginning with a capital C.

Explanation:

6 0
2 years ago
Read 2 more answers
An Internet service provider that wants to influence consumers to immediately switch to its service would most likely utilize __
frutty [35]

Answer: Direct competitive

Explanation:

 The direct competitive situation occur when the two and more than two business in the market offering the similar type of services and the products so it automatically increase the level of competition in the market.

According to the question, the internet service is one of the most efficient tool for influence the customers or consumers about their products in the market and when the services are get switched then it utilize the direct competitive in the market.

Therefore, direct competitive is the correct option.

6 0
3 years ago
a circuit has an inductor with an inductive reactance of 230 ohms. this inductor is in series with a 500 ohm resistor. if the so
Amanda [17]

Answer: attached below

Explanation:

8 0
3 years ago
3<br> Select the correct answer.<br> What is the output of the following HTML code?<br>Please
maw [93]

Answer: or element_id Specifies the relationship between the result of the calculation, and the elements used in the calculation

form form_id Specifies which form the output element belongs to

name name Specifies a name for the output element

Explanation:

7 0
2 years ago
Read 2 more answers
Other questions:
  • A ____ is harmful computer code that spreads without your interaction, slipping from one network to another and replicating itse
    15·1 answer
  • Because health and safety are important in all workplaces, not just hazardous ones, what working conditions must ALL employers p
    10·2 answers
  • Which field can be used to track the progress on tasks that a user has created?
    10·1 answer
  • Using underlining and italics at the same time is which of these? A. allowed but might be overkill B. always a good idea C. not
    15·2 answers
  • 20 points
    6·2 answers
  • Does anyone have the GCSE 2018 Design Technology J310/01 practice paper?
    15·1 answer
  • The CMOS battery located on a computer's motherboard allows for maintaining the correct time and date information stored in CMOS
    7·1 answer
  • write a program with total change amount as an integer input and output the change using the fewest coins, one coin type per lin
    8·1 answer
  • What is GIGO ?<br>plz answer me​
    7·1 answer
  • True or false FAFSA awards work study, but jobspeaker can be used to learn which jobs are available
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!