-
Notifications
You must be signed in to change notification settings - Fork 0
/
NestedClass.java
63 lines (63 loc) · 2.1 KB
/
NestedClass.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
class Phone {
String brand, model;
double price;
public Phone(String brand, String model, double price) {
this.brand = brand;
this.model = model;
this.price = price;
}
class Processor {
int cores;
String manufacturer;
public Processor(int cores, String manufacturer) {
this.cores = cores;
this.manufacturer = manufacturer;
}
public void disp() {
System.out.println("No of Cores: " + cores + "\nManufacturer: " + manufacturer);
}
}
class RAM {
int memory;
String manufacturer;
public RAM(int memory, String manufacturer) {
this.memory = memory;
this.manufacturer = manufacturer;
}
public void disp() {
System.out.println("Memory: " + memory + "\nManufacturer: " + manufacturer);
}
}
public void disp() {
System.out.println("Phone: " + brand + " " + model + "\nPrice: " + price);
}
}
public class NestedClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printf("Brand: ");
String brand = sc.next();
System.out.printf("Model: ");
String model = sc.next();
System.out.printf("Price: ");
double price = sc.nextDouble();
Phone ph1 = new Phone(brand, model, price);
System.out.printf("Processor\nManufacturer: ");
String manufacturer = sc.next();
System.out.printf("No of cores: ");
int cores = sc.nextInt();
Phone.Processor pr1 = ph1.new Processor(cores, manufacturer);
System.out.printf("RAM\nMemory(in GB): ");
int memory = sc.nextInt();
System.out.printf("Manufacturer: ");
manufacturer = sc.next();
Phone.RAM r1 = ph1.new RAM(memory, manufacturer);
System.out.println();
ph1.disp();
System.out.println("\nProcessor");
pr1.disp();
System.out.println("\nRAM");
r1.disp();
}
}