-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowroom.java
More file actions
32 lines (30 loc) · 869 Bytes
/
Copy pathShowroom.java
File metadata and controls
32 lines (30 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*Create two classes:
Car → Has attributes brand and model.
Showroom → Creates Car objects and displays their details using a method.*/
import java.util.Scanner;
class Car{
String brand;
int model;
void print(){
System.out.println("The name of the car brand is "+this.brand+" & the model number is "+this.model);
}
}
class Showroom{
public static void main(String[]args){
Scanner s1=new Scanner(System.in);
Car c1=new Car();
Car c2=new Car();
System.out.print("Enter first car model number : ");
c1.model=s1.nextInt();
s1.nextLine();
System.out.print("Enter first car brand : ");
c1.brand=s1.nextLine();
System.out.print("Enter second car model number : ");
c2.model=s1.nextInt();
s1.nextLine();
System.out.print("Enter second car brand : ");
c2.brand=s1.nextLine();
c1.print();
c2.print();
}
}