-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtravelExpenseMain.java
More file actions
134 lines (118 loc) · 4.84 KB
/
travelExpenseMain.java
File metadata and controls
134 lines (118 loc) · 4.84 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
125
126
127
128
129
130
131
132
133
134
//Import Scanner class
import java.util.Scanner;
public class travelExpenseMain {
public static void main(String[] args) {
//Create variables for the program
int days = 0;
double airfare = 0.0;
double carRentalFee = 0.0;
double miles = 0.0;
double parkFee = 0.0;
double taxiFee = 0.0;
double regFee = 0.0;
double lodging = 0.0;
boolean newTrip = true;
char choices = ' ';
//Create Scanner
Scanner userInput = new Scanner(System.in);
do {
//Create Travel Expense object
travelExpense travel = new travelExpense();
//Prompt user, for information and validate
do{
System.out.print("Number of days on the Trip: ");
days = userInput.nextInt();
if(days <= 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(days <= 0);
travel.setDays(days);
System.out.print("Did you have an Airfare Charge(y/n): ");
choices = userInput.next().charAt(0);
if(Character.compare('y', choices) == 0) {
do{
System.out.print("Airfare Charge: ");
airfare = userInput.nextDouble();
if(airfare <= 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(airfare <= 0);
}
travel.setAirfare(airfare);
System.out.print("Did you have a Car Rental Charge(y/n): ");
choices = userInput.next().charAt(0);
if(Character.compare('y', choices) == 0) {
do{
System.out.print("Car Rental Charge: ");
carRentalFee = userInput.nextDouble();
if(carRentalFee <= 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(carRentalFee <= 0);
}
travel.setCarRental(carRentalFee);
System.out.print("Did you drive your own car(y/n): ");
choices = userInput.next().charAt(0);
if(Character.compare('y', Character.toLowerCase(choices)) == 0) {
do{
System.out.print("Miles Driven: ");
miles = userInput.nextDouble();
if(miles <= 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(miles <= 0);
}
else {
travel.setMiles(0);
}
travel.setMiles(miles);
do{
System.out.print("Parking Fee: ");
parkFee = userInput.nextDouble();
if(parkFee < 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(parkFee < 0);
travel.setParkFee(parkFee);
do{
System.out.print("Taxi Fee: ");
taxiFee = userInput.nextDouble();
if(taxiFee < 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(taxiFee < 0);
travel.setTaxiFee(taxiFee);
do{
System.out.print("Conference Registration Fee: ");
regFee = userInput.nextDouble();
if(regFee < 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(regFee < 0);
travel.setRegFee(regFee);
do{
System.out.print("Lodging Per Night: ");
lodging = userInput.nextDouble();
if(lodging < 0) {
System.out.println("Invalid input given, please enter a number greater than 0");
}
} while(lodging < 0);
travel.setLodging(lodging);
//The Dipla method provided included calling the methods that calculate both expense total and allowable total
travel.displayMethod();
//Prompt user if they would like to enter a new trip
System.out.print("Would you like to enter in a new Trip(y/n): ");
choices = userInput.next().charAt(0);
switch(choices) {
case 'y':
newTrip = true;
break;
default:
newTrip = false;
break;
}
} while(newTrip == true);
//Close the Scanner object
userInput.close();
}
}