Skip to content

Commit 695cbc5

Browse files
committed
feat(oop): setting up
1 parent 5adc47b commit 695cbc5

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public abstract class Customer { //make this class abstract
2+
public abstract String createMail(); //make this method abstract
3+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Scanner;
2+
public class CustomerMailApplication {
3+
/**
4+
* @param args the command line arguments
5+
*/
6+
private Customer customer;
7+
public CustomerMailApplication(Customer customer) {
8+
this.customer = customer;
9+
}
10+
public static String getCustomerTypeFromUser() {
11+
String customerType = null;
12+
Scanner inp = new Scanner(System.in);
13+
System.out.print("Please choose customer type 1. Regular, 2. Mountain, 3. Delinquent ");
14+
int type = inp.nextInt();
15+
switch(type) {
16+
case 1:
17+
customerType = "Regular";
18+
break;
19+
case 2:
20+
customerType = "Mountain";
21+
break;
22+
case 3:
23+
customerType = "Delinquent";
24+
break;
25+
}
26+
inp.close();
27+
return customerType;
28+
}
29+
public String generateMail() {
30+
return customer.createMail();
31+
}
32+
33+
public static void main(String[] args) {
34+
String customerType = getCustomerTypeFromUser();
35+
Customer customer = null;
36+
switch(customerType) {
37+
case "Regular":
38+
customer = new RegularCustomer();
39+
break;
40+
case "Mountain":
41+
customer = new MountainCustomer();
42+
break;
43+
case "Delinquent":
44+
customer = new DelinquentCustomer();
45+
break;
46+
}
47+
CustomerMailApplication app = new CustomerMailApplication(customer);
48+
System.out.println(app.generateMail());
49+
}
50+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//make this class a subclass of customer
2+
public class DelinquentCustomer extends Customer {
3+
@Override
4+
public String createMail() {
5+
return "Delinquent Customer";
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//make this class a subclass of customer
2+
public class MountainCustomer extends Customer {
3+
@Override
4+
public String createMail() {
5+
return "Mountain Customer";
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//make this class a subclass of customer
2+
public class RegularCustomer extends Customer {
3+
@Override
4+
public String createMail() {
5+
return "Regular Customer";
6+
}
7+
8+
}

0 commit comments

Comments
 (0)