-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb03.java
More file actions
60 lines (59 loc) · 1.93 KB
/
Prob03.java
File metadata and controls
60 lines (59 loc) · 1.93 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
//Prob 03:
/*
Basketball is full of advanced shooting metrics and one of
these metrics is true shooting percentage.
Though it is not a perfect statistical measurement, the main
idea of TS% is that it is a measure of scoring efficiency
based on the number of points scored over the number of
possessions in which a player attempted to score. In simple
terms, true shooting percentage can be thought of as points
per shot.
True shooting percentage is calculated by using the formula:
TS% = 100 * PTS/(2(FGA + (0.44 * FTA)))
Where:
PTS = points scored
FGA = field goal attempts (shots taken)
FTA = free throw attempts
Write a program to calculate the true shooting percentage of a player given the PTS scored, FGA and FTA.
Input
The input consists of three whole numbers in one line separated by spaces: the total PTS, total FGA, and total
FTA.
98 71 43
Output
Use the PTS, FGA, and FTA to calculate the TS%. Print the true shooting percentage, including two decimal
places rounded, and append a '%' sign. [1]
54.49%
Discussion
Round to nearest hundredth. The denominator may contain a 0 but will not result in 0. The result may be more
than 100%.
[1] Rounding should follow the rule of: round up if the last number is 5-9, leave the hundreths place (the 2nd digit)
unchanged if the last number is 0-4.
E.G.
0.465 -> 0.47
0.464 -> 0.46
*/
import java.util.Scanner;
import java.lang.Math;
class Main {
public static String addZero(double num,int zeros){
String num1 = "" + num ;
if (num-(int)num == 0 ){
for(int i = 0; i<zeros; i++){
num1+= "0";
}
return num1;
}
else{
return num1;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int PTS = sc.nextInt();
int FGA = sc.nextInt();
int FTA = sc.nextInt();
double percent = 100 * PTS/(2*(FGA+(0.44*FTA)));
percent = Math.round(percent*100);
System.out.print(addZero(percent/100,1) + "%");
}
}