-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathBoltsNuts.java
40 lines (35 loc) · 1.56 KB
/
BoltsNuts.java
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
package bolts_nuts;
import java.util.*;
import java.io.*;
public class BoltsNuts {
private static ArrayList<String> data = new ArrayList<>();
private static ArrayList<Double> bolt = new ArrayList<>();
private static ArrayList<Double> nuts = new ArrayList<>();
private static void getData() throws IOException{
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
data.add(sc.nextLine());
}
StringTokenizer stBolts = new StringTokenizer(data.get(0), " ");
while (stBolts.hasMoreTokens()){
bolt.add(Double.valueOf(stBolts.nextToken()));
}
StringTokenizer stNuts = new StringTokenizer(data.get(1), " ");
while (stNuts.hasMoreTokens()){
nuts.add(Double.valueOf(stNuts.nextToken()));
}
}
public static void main(String[] argv) throws IOException{
getData();
double subtotal = bolt.get(0) * (bolt.get(1) / 100) * bolt.get(2) + nuts.get(0) * (nuts.get(1) / 100) * nuts.get(2);
double boltSave = bolt.get(0) - bolt.get(0) * (bolt.get(1) / 100);
double nutsSave = nuts.get(0) - nuts.get(0) * (nuts.get(1) / 100);
double diffrentDetail = (boltSave > nutsSave) ? (boltSave - nutsSave) * bolt.get(2) :
(boltSave < nutsSave) ? (nutsSave - boltSave) * nuts.get(2) : 0;
double result = subtotal + diffrentDetail;
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.print(String.valueOf((int)result));
pw.close();
}
}