Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
List of Cars manufactured in 2000 with price higher than 5000
-------------------------------
ID: 12
Make: Toyota
Model: SUV
Manufacture Year: 2000
Color: Blue
Price: 20008
Registration Number: BH0C0411
-------------------------------
ID: 14
Make: AUDI
Model: Hatchback
Manufacture Year: 2000
Color: White
Price: 20010
Registration Number: BH0C0003
-------------------------------
18 changes: 18 additions & 0 deletions newnew/List_of_Cars_of_BMW.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
List of Cars of a given brand: BMW
-------------------------------
ID: 2
Make: BMW
Model: Sedan
Manufacture Year: 2005
Color: White
Price: 5500
Registration Number: DL2C9898
-------------------------------
ID: 10
Make: BMW
Model: Sedan
Manufacture Year: 1996
Color: Pink
Price: 2000
Registration Number: BH0C2052
-------------------------------
34 changes: 34 additions & 0 deletions newnew/List_of_Cars_of_Sedan_more_than_10_years.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
List of Cars of a given model used for more than 10 years: Sedan
-------------------------------
ID: 1
Make: Mercedes
Model: Sedan
Manufacture Year: 1995
Color: Grey
Price: 2500
Registration Number: DL3C2001
-------------------------------
ID: 2
Make: BMW
Model: Sedan
Manufacture Year: 2005
Color: White
Price: 5500
Registration Number: DL2C9898
-------------------------------
ID: 8
Make: AUDI
Model: Sedan
Manufacture Year: 2001
Color: Black
Price: 12500
Registration Number: DL3C8501
-------------------------------
ID: 10
Make: BMW
Model: Sedan
Manufacture Year: 1996
Color: Pink
Price: 2000
Registration Number: BH0C2052
-------------------------------
69 changes: 69 additions & 0 deletions newnew/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.io.*;

class Car {
int id;
String make;
String model;
int manufacture_year;
String color;
int price;
String registration_number;

public Car(int id, String make, String model, int manufacture_year, String color, int price, String registration_number) {
this.id = id;
this.make = make;
this.model = model;
this.manufacture_year = manufacture_year;
this.color = color;
this.price = price;
this.registration_number = registration_number;
}
}

public class Main {
public static void main(String[] args) {
Car[] obj = {
new Car(1,"Mercedes","Sedan",1995,"Grey",2500,"DL3C2001"),
new Car(2,"BMW","Sedan",2005,"White",5500,"DL2C9898"),
new Car(3,"Mercedes","SUV",2010,"White",7000,"DL2C2000"),
new Car(4,"Bugatti","Coupe",2016,"Red",592500,"DL4C2041"),
new Car(5,"AUDI","Coupe",2022,"Black",72500,"DL6C8451"),
new Car(6,"Mercedes","Convertible",2015,"Grey",152500,"DL3C6666"),
new Car(7,"Porsche","Coupe",2015,"White",102500,"DL3C6333"),
new Car(8,"AUDI","Sedan",2001,"Black",12500,"DL3C8501"),
new Car(9,"AUDI","Hatchback",2005,"White",4000,"DLAC2581"),
new Car(10,"BMW","Sedan",1996,"Pink",2000,"BH0C2052"),
new Car(11,"BMW","SUV",2016,"Blue",20010,"BH0C0001"),
};

String brandToFilter = "BMW";
String listFilePath = "List_of_Cars_of_" + brandToFilter + ".txt";

try {
System.out.println("Creating a list of cars of the given brand: " + brandToFilter);
FileWriter fileWriter = new FileWriter(listFilePath);
fileWriter.write("List of Cars of a given brand: " + brandToFilter);
fileWriter.write("\n-------------------------------\n");

for (Car car : obj) {
String carBrand = car.make.toLowerCase();
if (carBrand.equals(brandToFilter.toLowerCase())) {

fileWriter.write("ID: " + car.id + "\n");
fileWriter.write("Make: " + car.make + "\n");
fileWriter.write("Model: " + car.model + "\n");
fileWriter.write("Manufacture Year: " + car.manufacture_year + "\n");
fileWriter.write("Color: " + car.color + "\n");
fileWriter.write("Price: " + car.price + "\n");
fileWriter.write("Registration Number: " + car.registration_number + "\n");
fileWriter.write("-------------------------------\n");
}
}

fileWriter.close();
System.out.println("List of cars saved to: " + listFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
}
68 changes: 68 additions & 0 deletions newnew/Main2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.io.*;

class Car {
int id;
String make;
String model;
int manufacture_year;
String color;
int price;
String registration_number;

public Car(int id, String make, String model, int manufacture_year, String color, int price, String registration_number) {
this.id = id;
this.make = make;
this.model = model;
this.manufacture_year = manufacture_year;
this.color = color;
this.price = price;
this.registration_number = registration_number;
}
}

public class Main2 {
public static void main(String[] args) {
Car[] obj = {
new Car(1,"Mercedes","Sedan",1995,"Grey",2500,"DL3C2001"),
new Car(2,"BMW","Sedan",2005,"White",5500,"DL2C9898"),
new Car(3,"Mercedes","SUV",2010,"White",7000,"DL2C2000"),
new Car(4,"Bugatti","Coupe",2016,"Red",592500,"DL4C2041"),
new Car(5,"AUDI","Coupe",2022,"Black",72500,"DL6C8451"),
new Car(6,"Mercedes","Convertible",2015,"Grey",152500,"DL3C6666"),
new Car(7,"Porsche","Coupe",2015,"White",102500,"DL3C6333"),
new Car(8,"AUDI","Sedan",2001,"Black",12500,"DL3C8501"),
new Car(9,"AUDI","Hatchback",2005,"White",4000,"DLAC2581"),
new Car(10,"BMW","Sedan",1996,"Pink",2000,"BH0C2052"),
new Car(11,"BMW","SUV",2016,"Blue",20010,"BH0C0001"),
};

String modelToFilter = "Sedan";
int yearsThreshold = 10; // Cars used for more than 10 years
String listFilePath = "List_of_Cars_of_" + modelToFilter + "_more_than_" + yearsThreshold + "_years.txt";

try {
System.out.println("Creating a list of cars of the given model used for more than " + yearsThreshold + " years: " + modelToFilter);
FileWriter fileWriter = new FileWriter(listFilePath);
fileWriter.write("List of Cars of a given model used for more than " + yearsThreshold + " years: " + modelToFilter);
fileWriter.write("\n-------------------------------\n");

for (Car car : obj) {
if (car.model.equalsIgnoreCase(modelToFilter) && (2023 - car.manufacture_year > yearsThreshold)) {
fileWriter.write("ID: " + car.id + "\n");
fileWriter.write("Make: " + car.make + "\n");
fileWriter.write("Model: " + car.model + "\n");
fileWriter.write("Manufacture Year: " + car.manufacture_year + "\n");
fileWriter.write("Color: " + car.color + "\n");
fileWriter.write("Price: " + car.price + "\n");
fileWriter.write("Registration Number: " + car.registration_number + "\n");
fileWriter.write("-------------------------------\n");
}
}

fileWriter.close();
System.out.println("List of cars saved to: " + listFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
}
73 changes: 73 additions & 0 deletions newnew/Main3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.io.*;

class Car {
int id;
String make;
String model;
int manufacture_year;
String color;
int price;
String registration_number;

public Car(int id, String make, String model, int manufacture_year, String color, int price, String registration_number) {
this.id = id;
this.make = make;
this.model = model;
this.manufacture_year = manufacture_year;
this.color = color;
this.price = price;
this.registration_number = registration_number;
}
}

public class Main3 {
public static void main(String[] args) {
Car[] obj = {
new Car(1, "Mercedes", "Sedan", 1995, "Grey", 2500, "DL3C2001"),
new Car(2, "BMW", "Sedan", 2005, "White", 5500, "DL2C9898"),
new Car(3, "Mercedes", "SUV", 2010, "White", 7000, "DL2C2000"),
new Car(4, "Bugatti", "Coupe", 2016, "Red", 592500, "DL4C2041"),
new Car(5, "AUDI", "Coupe", 2022, "Black", 72500, "DL6C8451"),
new Car(6, "Mercedes", "Convertible", 2015, "Grey", 152500, "DL3C6666"),
new Car(7, "Porsche", "Coupe", 2015, "White", 102500, "DL3C6333"),
new Car(8, "AUDI", "Sedan", 2001, "Black", 12500, "DL3C8501"),
new Car(9, "AUDI", "Hatchback", 2005, "White", 4000, "DLAC2581"),
new Car(10, "BMW", "Sedan", 1996, "Pink", 2000, "BH0C2052"),
new Car(11, "BMW", "SUV", 2016, "Blue", 20710, "BH0C0001"),
new Car(12, "Toyota", "SUV", 2000, "Blue", 20008, "BH0C0411"),
new Car(13, "Toyota", "SUV", 2016, "Black", 40010, "BH0C0002"),
new Car(14, "AUDI", "Hatchback", 2000, "White", 20010, "BH0C0003"),
};

int yearToFilter = 2000;
int priceThreshold = 5000; // Cars with price higher than 5000
String listFilePath = "List_of_Cars_manufactured_in_" + yearToFilter + "_price_higher_than_" + priceThreshold + ".txt";

try {
System.out.println("Creating a list of cars manufactured in " + yearToFilter +
" with price higher than " + priceThreshold);
FileWriter fileWriter = new FileWriter(listFilePath);
fileWriter.write("List of Cars manufactured in " + yearToFilter +
" with price higher than " + priceThreshold);
fileWriter.write("\n-------------------------------\n");

for (Car car : obj) {
if (car.manufacture_year == yearToFilter && car.price > priceThreshold) {
fileWriter.write("ID: " + car.id + "\n");
fileWriter.write("Make: " + car.make + "\n");
fileWriter.write("Model: " + car.model + "\n");
fileWriter.write("Manufacture Year: " + car.manufacture_year + "\n");
fileWriter.write("Color: " + car.color + "\n");
fileWriter.write("Price: " + car.price + "\n");
fileWriter.write("Registration Number: " + car.registration_number + "\n");
fileWriter.write("-------------------------------\n");
}
}

fileWriter.close();
System.out.println("List of cars saved to: " + listFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading