-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoringMarks
More file actions
51 lines (42 loc) · 1.37 KB
/
StoringMarks
File metadata and controls
51 lines (42 loc) · 1.37 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
import java.io.File;
import java.util.Scanner;
public class StoringMarks {
public static void main(String[] args){
Scanner scanner= new Scanner(System.in);
String fileName= scanner.nextLine();
scanner.nextLine();
int min= scanner.nextInt();
scanner.nextInt();
int max= scanner.nextInt();
scanner.nextLine();
int width= scanner.nextInt();
scanner.nextLine();
int[] marks= new int[max-min+1];
int total=0;
try(Scanner file= new Scanner(new File("text.txt"))){
file.nextLine();
while(file.hasNext()){
String line[] = file.nextLine().split(",");
int d = Integer.parseInt(line[1]);
marks[d-min]+=1;
total+=1;
}
}catch(Exception e){
e.printStackTrace();
}
for(int i=0;i<marks.length;i+=width){
int sum=0;
for (int j=0;j<marks.length;j++){
sum+=marks[i+j];
}
int percentage=(int)(100*(1.0*sum)/total);
String bar="";
if(percentage>0){
bar=String.format("%"+percentage +"s"+" ").replace(" ","=");
}
int lower= i+min;
int upper=lower+width-1;
System.out.format("%.03d-%.03d:%s", lower, upper , bar);
}
}
}