-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStest.java
More file actions
62 lines (35 loc) · 1.58 KB
/
Copy pathStest.java
File metadata and controls
62 lines (35 loc) · 1.58 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
import java.util.Scanner;
public class Stest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter miles per year: ");
double milesPerYear = in.nextDouble();
System.out.println("Please enter cost of gas: ");
double costOfGas = in.nextDouble();
String stickerHybrid = "Toyota,Prius";
String stickerRegular= "Toyota,Corolla";
String [] stuff2 = stickerHybrid.split(",");
String [] stuff = stickerRegular.split(",");
double [] corolla = new double [8];
double [] prius = new double [8];
int counter = 0;
int year = 1;
boolean isGreater = true;
while (isGreater){
corolla[counter] = 28000 + (((milesPerYear/20) * costOfGas )* year );
prius[counter] = 31000 + (((milesPerYear/30) * costOfGas )* year );
if (corolla[counter] > prius[counter]){
isGreater = false;
}
counter = counter + 1;
year = year + 1;
}
int year2 = 1;
for (int i=0; i<5; i++){
System.out.print("Cost to own " + stuff[0] + " " + stuff[1] + " after year "+ year2 + ": "+ corolla[i]);
System.out.println(" for " + stuff2[0] + stuff2[1] + ": " + prius[i]);
year2 = year2 + 1;
}
System.out.println("The Toyota Prius pays back after 5 years");
}
}