secret
Last active — forked from /Calc.java

  • Download Gist
eogas revised this gist . 1 changed file with 128 additions and 135 deletions. View gist @ 26439d9
Calc.java
263 
... 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                                               153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186                                                               187 188 189 190   ... 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149                                                                 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182   183  
@@ -4,187 +4,180 @@
import java.io.IOException;
import java.util.Scanner;
-public class Calc
-{
- public static void main(String [] args) throws IOException
- {
- System.out.println("Enter the total number of courses you are going to enter:");
- Scanner scanner=new Scanner(System.in);
- int i=scanner.nextInt();
+public class Calc {
+ public static void main(String[] args) throws IOException {
+ System.out
+ .println("Enter the total number of courses you are going to enter:");
+ Scanner scanner = new Scanner(System.in);
+ int i = scanner.nextInt();
calculate(i);
}
- public static void calculate(int i) throws IOException
- {
- String [] courses=new String[i]; /* store the course name */
- String [] gradesl=new String[i]; /* store the course letter grades */
- int [] grades=new int[i]; /* store the course 12-point grades */
- double [] gradesf=new double[i]; /* store the course 4-point grades */
- double totalUnits=0.0; /* total number of units taken by the student */
- double sumT=0.0;
- double sumF=0.0;
- double gpaT; /* Cumulative 12-point GPA */
- double gpaF; /* Cumulative 4-point GPA */
+ public static void calculate(int i) throws IOException {
+ String[] courses = new String[i]; /* store the course name */
+ String[] gradesl = new String[i]; /* store the course letter grades */
+ int[] grades = new int[i]; /* store the course 12-point grades */
+ double[] gradesf = new double[i]; /* store the course 4-point grades */
+ double totalUnits = 0.0; /* total number of units taken by the student */
+ double sumT = 0.0;
+ double sumF = 0.0;
+ double gpaT; /* Cumulative 12-point GPA */
+ double gpaF; /* Cumulative 4-point GPA */
- System.out.println("Enter the course name and then the grade (on a 12 point scale or letter grade). Enter it as you'd like it to appear in your grade sheet that will be generated after you have entered all the courses and their grades.");
+ System.out
+ .println("Enter the course name and then the grade (on a 12 point scale or letter grade). Enter it as you'd like it to appear in your grade sheet that will be generated after you have entered all the courses and their grades.");
- for (int j=0;j<i;j++)
- {
+ for (int j = 0; j < i; j++) {
System.out.println("Course Name:");
- Scanner scanner1=new Scanner(System.in);
- String course=scanner1.nextLine();
+ Scanner scanner1 = new Scanner(System.in);
+ String course = scanner1.nextLine();
System.out.println("Grade:");
- Scanner scanner2=new Scanner(System.in);
- String grade=scanner2.nextLine();
+ Scanner scanner2 = new Scanner(System.in);
+ String grade = scanner2.nextLine();
System.out.println("Units:");
- Scanner scanner3=new Scanner(System.in);
- int units=scanner3.nextInt();
- int finalGrade=parseGrade(grade);
- double fourPoint=parseGradef(finalGrade);
- String letterGrade=parseGradel(finalGrade);
+ Scanner scanner3 = new Scanner(System.in);
+ int units = scanner3.nextInt();
+ int finalGrade = parseGrade(grade);
+ double fourPoint = parseGradef(finalGrade);
+ String letterGrade = parseGradel(finalGrade);
- if(finalGrade!=13)
- {
- totalUnits+=units;
- sumT+=units*finalGrade;
- sumF+=units*fourPoint;
- courses[j]=course;
- grades[j]=finalGrade;
- gradesf[j]=fourPoint;
- gradesl[j]=letterGrade;
+ if (finalGrade != 13) {
+ totalUnits += units;
+ sumT += units * finalGrade;
+ sumF += units * fourPoint;
+ courses[j] = course;
+ grades[j] = finalGrade;
+ gradesf[j] = fourPoint;
+ gradesl[j] = letterGrade;
}
- else
- {
- System.out.println("Incorrect grade value entered, enter again..");
+ else {
+ System.out
+ .println("Incorrect grade value entered, enter again..");
j--;
}
}
/* Calculate 4 point and 12 point GPA */
gpaF = sumF / totalUnits;
- gpaT=sumT/totalUnits;
+ gpaT = sumT / totalUnits;
- /* Write the grades and GPA to the text file*/
- File file=new File("/users/forkbattery/Documents/Grade Report.txt");
+ /* Write the grades and GPA to the text file */
+ File file = new File("/users/forkbattery/Documents/Grade Report.txt");
/* Create a file if it does not exist in the path above */
- if(!file.exists())
- {
+ if (!file.exists()) {
file.createNewFile();
}
/* Write the results to a file */
- FileWriter fileWriter=new FileWriter(file.getAbsoluteFile());
- BufferedWriter bufferedWriter=new BufferedWriter(fileWriter);
+ FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
+ BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
- for (int k=0;k<i;k++)
- {
- bufferedWriter.write(courses[k] + " " + gradesl[k] + " " + gradesf[k] + " " + grades[k]+"\n");
+ for (int k = 0; k < i; k++) {
+ bufferedWriter.write(courses[k] + " " + gradesl[k] + " "
+ + gradesf[k] + " " + grades[k] + "\n");
}
- bufferedWriter.write("\nGPA on 12 point scale: "+gpaT+"\n");
- bufferedWriter.write("\nGPA on 4 point scale: "+gpaF+"\n");
+ bufferedWriter.write("\nGPA on 12 point scale: " + gpaT + "\n");
+ bufferedWriter.write("\nGPA on 4 point scale: " + gpaF + "\n");
bufferedWriter.close();
System.out.println("Done!");
}
- public static int parseGrade(String gr)
- {
- if (gr.equals("0")||gr.equals("F")||gr.equals("f"))
+ public static int parseGrade(String gr) {
+ if (gr.equals("0") || gr.equals("F") || gr.equals("f"))
return 0;
- else if(gr.equals("1")||gr.equals("D-")||gr.equals("d-"))
+ else if (gr.equals("1") || gr.equals("D-") || gr.equals("d-"))
return 1;
- else if(gr.equals("2")||gr.equals("D")||gr.equals("d"))
+ else if (gr.equals("2") || gr.equals("D") || gr.equals("d"))
return 2;
- else if(gr.equals("3")||gr.equals("D+")||gr.equals("d+"))
+ else if (gr.equals("3") || gr.equals("D+") || gr.equals("d+"))
return 3;
- else if(gr.equals("4")||gr.equals("C-")||gr.equals("c-"))
+ else if (gr.equals("4") || gr.equals("C-") || gr.equals("c-"))
return 4;
- else if(gr.equals("5")||gr.equals("C")||gr.equals("c"))
+ else if (gr.equals("5") || gr.equals("C") || gr.equals("c"))
return 5;
- else if(gr.equals("6")||gr.equals("C+")||gr.equals("c+"))
+ else if (gr.equals("6") || gr.equals("C+") || gr.equals("c+"))
return 6;
- else if(gr.equals("7")||gr.equals("B-")||gr.equals("b-"))
+ else if (gr.equals("7") || gr.equals("B-") || gr.equals("b-"))
return 7;
- else if(gr.equals("8")||gr.equals("B")||gr.equals("b"))
+ else if (gr.equals("8") || gr.equals("B") || gr.equals("b"))
return 8;
- else if(gr.equals("9")||gr.equals("B+")||gr.equals("b+"))
+ else if (gr.equals("9") || gr.equals("B+") || gr.equals("b+"))
return 9;
- else if(gr.equals("10")||gr.equals("A-")||gr.equals("a-"))
+ else if (gr.equals("10") || gr.equals("A-") || gr.equals("a-"))
return 10;
- else if(gr.equals("11")||gr.equals("A")||gr.equals("a"))
+ else if (gr.equals("11") || gr.equals("A") || gr.equals("a"))
return 11;
- else if(gr.equals("12")||gr.equals("A+")||gr.equals("a+"))
+ else if (gr.equals("12") || gr.equals("A+") || gr.equals("a+"))
return 12;
- else return 13;
+ else
+ return 13;
}
- public static double parseGradef(int grf)
- {
- switch (grf)
- {
- case 0:
- return 0.0;
- case 1:
- return 0.7;
- case 2:
- return 1.0;
- case 3:
- return 1.3;
- case 4:
- return 1.7;
- case 5:
- return 2.0;
- case 6:
- return 2.3;
- case 7:
- return 2.7;
- case 8:
- return 3.0;
- case 9:
- return 3.3;
- case 10:
- return 3.7;
- case 11:
- return 3.9;
- case 12:
- return 4.0;
- default:
- return 5.0;
+
+ public static double parseGradef(int grf) {
+ switch (grf) {
+ case 0:
+ return 0.0;
+ case 1:
+ return 0.7;
+ case 2:
+ return 1.0;
+ case 3:
+ return 1.3;
+ case 4:
+ return 1.7;
+ case 5:
+ return 2.0;
+ case 6:
+ return 2.3;
+ case 7:
+ return 2.7;
+ case 8:
+ return 3.0;
+ case 9:
+ return 3.3;
+ case 10:
+ return 3.7;
+ case 11:
+ return 3.9;
+ case 12:
+ return 4.0;
+ default:
+ return 5.0;
}
}
- public static String parseGradel(int grl)
- {
- switch (grl)
- {
- case 0:
- return "F";
- case 1:
- return "D-";
- case 2:
- return "D";
- case 3:
- return "D+";
- case 4:
- return "C-";
- case 5:
- return "C";
- case 6:
- return "C+";
- case 7:
- return "B-";
- case 8:
- return "B";
- case 9:
- return "B+";
- case 10:
- return "A-";
- case 11:
- return "A";
- case 12:
- return "A+";
- default:
- return "error";
+
+ public static String parseGradel(int grl) {
+ switch (grl) {
+ case 0:
+ return "F";
+ case 1:
+ return "D-";
+ case 2:
+ return "D";
+ case 3:
+ return "D+";
+ case 4:
+ return "C-";
+ case 5:
+ return "C";
+ case 6:
+ return "C+";
+ case 7:
+ return "B-";
+ case 8:
+ return "B";
+ case 9:
+ return "B+";
+ case 10:
+ return "A-";
+ case 11:
+ return "A";
+ case 12:
+ return "A+";
+ default:
+ return "error";
}
}
-
}
\ No newline at end of file
Anonymous created this gist . View gist @ ac30a15
Calc.java
190 
...                                                                                                                                                                                                                                                                                                                                                                                               ... 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190  
@@ -0,0 +1,190 @@
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Scanner;
+
+public class Calc
+{
+ public static void main(String [] args) throws IOException
+ {
+ System.out.println("Enter the total number of courses you are going to enter:");
+ Scanner scanner=new Scanner(System.in);
+ int i=scanner.nextInt();
+ calculate(i);
+ }
+
+ public static void calculate(int i) throws IOException
+ {
+ String [] courses=new String[i]; /* store the course name */
+ String [] gradesl=new String[i]; /* store the course letter grades */
+ int [] grades=new int[i]; /* store the course 12-point grades */
+ double [] gradesf=new double[i]; /* store the course 4-point grades */
+ double totalUnits=0.0; /* total number of units taken by the student */
+ double sumT=0.0;
+ double sumF=0.0;
+ double gpaT; /* Cumulative 12-point GPA */
+ double gpaF; /* Cumulative 4-point GPA */
+
+ System.out.println("Enter the course name and then the grade (on a 12 point scale or letter grade). Enter it as you'd like it to appear in your grade sheet that will be generated after you have entered all the courses and their grades.");
+
+ for (int j=0;j<i;j++)
+ {
+ System.out.println("Course Name:");
+ Scanner scanner1=new Scanner(System.in);
+ String course=scanner1.nextLine();
+ System.out.println("Grade:");
+ Scanner scanner2=new Scanner(System.in);
+ String grade=scanner2.nextLine();
+ System.out.println("Units:");
+ Scanner scanner3=new Scanner(System.in);
+ int units=scanner3.nextInt();
+ int finalGrade=parseGrade(grade);
+ double fourPoint=parseGradef(finalGrade);
+ String letterGrade=parseGradel(finalGrade);
+
+ if(finalGrade!=13)
+ {
+ totalUnits+=units;
+ sumT+=units*finalGrade;
+ sumF+=units*fourPoint;
+ courses[j]=course;
+ grades[j]=finalGrade;
+ gradesf[j]=fourPoint;
+ gradesl[j]=letterGrade;
+ }
+ else
+ {
+ System.out.println("Incorrect grade value entered, enter again..");
+ j--;
+ }
+ }
+
+ /* Calculate 4 point and 12 point GPA */
+ gpaF = sumF / totalUnits;
+ gpaT=sumT/totalUnits;
+
+ /* Write the grades and GPA to the text file*/
+ File file=new File("/users/forkbattery/Documents/Grade Report.txt");
+
+ /* Create a file if it does not exist in the path above */
+ if(!file.exists())
+ {
+ file.createNewFile();
+ }
+
+ /* Write the results to a file */
+ FileWriter fileWriter=new FileWriter(file.getAbsoluteFile());
+ BufferedWriter bufferedWriter=new BufferedWriter(fileWriter);
+
+ for (int k=0;k<i;k++)
+ {
+ bufferedWriter.write(courses[k] + " " + gradesl[k] + " " + gradesf[k] + " " + grades[k]+"\n");
+ }
+ bufferedWriter.write("\nGPA on 12 point scale: "+gpaT+"\n");
+ bufferedWriter.write("\nGPA on 4 point scale: "+gpaF+"\n");
+ bufferedWriter.close();
+
+ System.out.println("Done!");
+ }
+
+ public static int parseGrade(String gr)
+ {
+ if (gr.equals("0")||gr.equals("F")||gr.equals("f"))
+ return 0;
+ else if(gr.equals("1")||gr.equals("D-")||gr.equals("d-"))
+ return 1;
+ else if(gr.equals("2")||gr.equals("D")||gr.equals("d"))
+ return 2;
+ else if(gr.equals("3")||gr.equals("D+")||gr.equals("d+"))
+ return 3;
+ else if(gr.equals("4")||gr.equals("C-")||gr.equals("c-"))
+ return 4;
+ else if(gr.equals("5")||gr.equals("C")||gr.equals("c"))
+ return 5;
+ else if(gr.equals("6")||gr.equals("C+")||gr.equals("c+"))
+ return 6;
+ else if(gr.equals("7")||gr.equals("B-")||gr.equals("b-"))
+ return 7;
+ else if(gr.equals("8")||gr.equals("B")||gr.equals("b"))
+ return 8;
+ else if(gr.equals("9")||gr.equals("B+")||gr.equals("b+"))
+ return 9;
+ else if(gr.equals("10")||gr.equals("A-")||gr.equals("a-"))
+ return 10;
+ else if(gr.equals("11")||gr.equals("A")||gr.equals("a"))
+ return 11;
+ else if(gr.equals("12")||gr.equals("A+")||gr.equals("a+"))
+ return 12;
+ else return 13;
+ }
+ public static double parseGradef(int grf)
+ {
+ switch (grf)
+ {
+ case 0:
+ return 0.0;
+ case 1:
+ return 0.7;
+ case 2:
+ return 1.0;
+ case 3:
+ return 1.3;
+ case 4:
+ return 1.7;
+ case 5:
+ return 2.0;
+ case 6:
+ return 2.3;
+ case 7:
+ return 2.7;
+ case 8:
+ return 3.0;
+ case 9:
+ return 3.3;
+ case 10:
+ return 3.7;
+ case 11:
+ return 3.9;
+ case 12:
+ return 4.0;
+ default:
+ return 5.0;
+ }
+ }
+ public static String parseGradel(int grl)
+ {
+ switch (grl)
+ {
+ case 0:
+ return "F";
+ case 1:
+ return "D-";
+ case 2:
+ return "D";
+ case 3:
+ return "D+";
+ case 4:
+ return "C-";
+ case 5:
+ return "C";
+ case 6:
+ return "C+";
+ case 7:
+ return "B-";
+ case 8:
+ return "B";
+ case 9:
+ return "B+";
+ case 10:
+ return "A-";
+ case 11:
+ return "A";
+ case 12:
+ return "A+";
+ default:
+ return "error";
+ }
+ }
+
+}
\ No newline at end of file
Something went wrong with that request. Please try again.