-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelivery.java
More file actions
93 lines (80 loc) · 2.42 KB
/
Copy pathDelivery.java
File metadata and controls
93 lines (80 loc) · 2.42 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
import java.util.Scanner;
public class Delivery {
String id;
char destination;
double weight;
public Delivery() {
id="xxx000";
destination='X';
weight=0.00;
}
public Delivery(Delivery a) {
id=a.id;
destination=a.destination;
weight=a.weight;
}
//accessors
public String getId() {return id;}
public char getDestination() {return destination;}
public double getWeight() {return weight;}
//mutators
public void setId(String i) {id = i;}
public void setDestination(char d) {destination = d;}
public void setWeight(double w) {weight=w;}
public double calculateFee() {
double fee=0;
if(weight<5) {
switch(destination) {
case 'L' :
{
fee=5.5*weight;
break;
}
case 'O':
{
fee=(7.5*weight)+10.0;
break;
}
default: System.out.println("\nERROR : Unknown Input");
}
}
else if(5<=weight) {
switch(destination) {
case 'L' :
{
if(weight<=16)
fee=5.3*weight;
else if(weight>16)
fee=5.0*weight;
break;
}
case 'O':
{
fee=(7.0*weight)+15.0;
break;
}
default: System.out.println("\nERROR : Unknown Input");
}
}
return fee;
}
public String toString() {
return "\nID : "+id+" Destination : "+destination+" Weight (kg) : "+weight+" Total Fee : RM"+calculateFee();
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println(" ID Number: ");
String id=input.nextLine();
System.out.println(" Destination (L/O) : ");
char destination=input.next().charAt(0);
System.out.println(" Weight : ");
int weight=input.nextInt();
Delivery d = new Delivery();
d.setId(id);
d.setDestination(destination);
d.setWeight(weight);
if(weight<5.0)
System.out.println(d.toString());
input.close();
}
}