Skip to content

Instantly share code, notes, and snippets.

@jthomp
Created February 26, 2009 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthomp/70706 to your computer and use it in GitHub Desktop.
Save jthomp/70706 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.io.*;
import java.text.DecimalFormat;
public class StudentDissector
{
public static void main (String[] args) throws IOException
{
String record;
Scanner fileScan, recordScan;
fileScan = new Scanner (new File("/Users/justin/Desktop/hw5.inp"));
// Read and process each line of the file
while (fileScan.hasNext())
{
record = fileScan.nextLine();
System.out.println ("Student record: " + record);
recordScan = new Scanner (record);
recordScan.useDelimiter(" ");
DecimalFormat fmt = new DecimalFormat("0.#");
// Print each part of the record
while (recordScan.hasNext())
System.out.println (" " + recordScan.next());
String fn = recordScan.next();
String ln = recordScan.next();
int t1s = Integer.parseInt(recordScan.next());
int t2s = Integer.parseInt(recordScan.next());
int t3s = Integer.parseInt(recordScan.next());
int t4s = Integer.parseInt(recordScan.next());
int t5s = Integer.parseInt(recordScan.next());
int t6s = Integer.parseInt(recordScan.next());
int t7s = Integer.parseInt(recordScan.next());
//perform calculation
getScore(t1s, t2s, t3s, t4s, t5s, t6s, t7s);
getGrade(score);
//output result
System.out.println(justify(ln + ", " + fn)
+ fmt.format(score) + "\t" + grade);
System.out.println();
}
}
public static String justify (String name)
{
String s = name;
for (int i = name.length(); i<25; i++)
s = s + " ";
return s;
}
public static double getScore(int t1s, int t2s, int t3s, int t4s, int t5s, int t6s, int t7s)
{
//declarations
double score1 = Double.parseDouble(t1s);
double score2 = Double.parseDouble(t2s);
double score3 = Double.parseDouble(t3s);
double score4 = Double.parseDouble(t4s);
double score5 = Double.parseDouble(t5s);
double score6 = Double.parseDouble(t6s);
double score7 = Double.parseDouble(t7s);
//first 3 are test scores, weight is 60%
double weightedTestScore = ((score1 + score2 + score3) * 0.6);
//last 4 are homework scores, weight is 40%
double weightedHomeWorkScore = ((score4 + score5 + score6 +
score7) * 0.4);
//get average pass as score.
double score = ((weightedTestScore + weightedHomeWorkScore) / 2);
return score;
}
public static String getGrade()
{
return grade;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment