create an ArrayList of Cars in a class ShowRoom having name and address as attributes as well, Provide appropriate methods, store values in array List (take values form user).
Provide a buy method which will ask user to buy a Car by providing its name, check that it is present or not then ask for quantity and create bill for user.
After that you have to print the following
1. Add Car
2. Delete Car
3. Buy a Car.
4. Display All cars also display
· Car of brand “Audi”;
· Car with name starting with ‘L’.
· Car name end with ‘n’.
· Display only last three and first three letters of Showroom name.
package showroom;
import java.util.ArrayList;
import java.util.Scanner;
class Cars{
private String name, address;
public Cars(){
}
public Cars(String n, String a){
name = n;
address = a;
}
public String getName(){
return name;
}
public String getAddress(){
return address;
}
}
public class ShowRoom {
static ArrayList<Cars> list=new ArrayList<Cars>();
static void addCar(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the car name: ");
String name = scan.nextLine();
System.out.println("Enter the car address: ");
String address = scan.nextLine();
Cars c = new Cars(name, address);
list.add(c);
}
static void DeleteCar(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the car name: ");
String name = scan.nextLine();
System.out.println("Enter the car address: ");
String address = scan.nextLine();
Cars c = new Cars(name, address);
list.remove(list.indexOf(c));
}
static void BoughtCar(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the car name: ");
String name = scan.nextLine();
System.out.println("Enter the car address: ");
String address = scan.nextLine();
Cars c = new Cars(name, address);
System.out.println("Bought successfully");
list.remove(list.indexOf(c));
}
public static void main(String[] args) {
}
}
Comments
Leave a comment