forked from Gomavijayan/Java_Accenture_LearningModules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncredible Toys.java
More file actions
124 lines (120 loc) · 2.86 KB
/
Incredible Toys.java
File metadata and controls
124 lines (120 loc) · 2.86 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
public class CustomerDetails {
private String customerId;
private String customerName;
private long phoneNumber;
private String emailId;
private String toyType;
private double price;
public CustomerDetails(String customerId, String customerName, long
phonenumber,
String emailId, String toyType, double price){
this.emailId=emailId;
this.toyType=toyType;
this.customerId=customerId;
this.customerName=customerName;
this.phoneNumber=phoneNumber;
this.price=price;
}
public double calculateDiscount() {
String type =this.toyType;
double discount=0;
if(type.equalsIgnoreCase("SoftToys")){
discount=5;
}else if (type.equalsIgnoreCase("FidgetToys")){
discount=10;
}else if (type.equalsIgnoreCase("SensoryToys")){
discount=15;
}else if (type.equalsIgnoreCase("Puzzles")){
discount=20;
}
discount=((this.price)*discount)/100;
double cost = this.price-discount;
return cost;
}
public String getCustomerId(){
return customerId;
}
public void setCustomerId(String customerId){
this.customerId=customerId;
}
public String getCustomerName(){
return customerName;
}
public void setCustomerName(String customerName){
this.customerName=customerName;
}
public long getPhoneNumber(){
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber){
this.phoneNumber=phoneNumber;
}
public String getEmailId(){
return emailId;
}
public void setEmailId(String emailId){
this.emailId=emailId;
}
public String getToyType(){
return toyType;
}
public void setToyType(String toyType){
this.toyType=toyType;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price=price;
}
public boolean validateNum(String str){
boolean result =str.matches("[0-9]+");
return result;
}
public boolean validateCustomerId(){
String[] data=customerId.split("/");
if(data.length==3){
if(data[0].equalsIgnoreCase("Incredible")){
if(data[1].length()==3){
boolean check =validateNum(data[1]);
if(check == true){
if(data[2].length()==4){
boolean check1 =validateNum(data[2]);
if(check1==true){
return true;
}
}
}
}
}
}
return false;
}
}
//====================================================//
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Customer Id");
String cid=sc.next();
System.out.println("Enter Customer Name");
String name=sc.next();
System.out.println("Enter Phone Number");
long phone=sc.nextLong();
System.out.println("Enter Email Id");
String email=sc.next();
System.out.println("Enter type");
String type=sc.next();
System.out.println("Enter Price");
double price = sc.nextDouble();
CustomerDetails cd = new
CustomerDetails(cid,name,phone,email,type,price);
if(cd.validateCustomerId()==false){
System.out.println("Provide a proper Customer Id");
return;
}
System.out.printf("Amount to be paid by the Customer
%.2f\n",cd.calculateDiscount());
}
}