Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.44 KB | None | 0 0
  1. package Student;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.text.NumberFormat;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.Scanner;
  8.  
  9. public class Project_2 {
  10.  
  11.     public static void main(String[] args) {
  12.  
  13.         // Program to calculate the grade for ITSE 1302-007 students
  14.        
  15.         NumberFormat percent = NumberFormat.getPercentInstance();
  16.         DecimalFormat deci = new DecimalFormat("#.#");
  17.         String studentFirst, studentLast;
  18.         String courseNumber, className;
  19.         float hw, qz, proj, tst, final_exam, atnd_grade;
  20.         double qtyGrades, hSum = 0,  qSum = 0,  pSum = 0, tSum = 0;
  21.         double hCount = 0, qCount = 0, pCount = 0, tCount = 0, count = 0, atndCount = 0;
  22.         double totalSum,totalCount;
  23.         Scanner userInput = new Scanner(System.in);
  24.         Student student;
  25.        
  26.         //prompts user for course number and class name
  27.         System.out.print("What is the course number?  ");
  28.         courseNumber = userInput.nextLine();
  29.         System.out.print("What is the class name?  ");
  30.         className = userInput.nextLine();
  31.        
  32.         System.out.println("\t\t\t\t------------------------");
  33.         System.out.println("\t\t\t\t-                      -");
  34.         System.out.println("\t\t\t\t-\t"+courseNumber+"      -");
  35.         System.out.println("\t\t\t\t- "+className+" -");
  36.         System.out.println("\t\t\t\t-    Semester Grade    -");
  37.         System.out.println("\t\t\t\t-                      -");
  38.         System.out.println("\t\t\t\t------------------------");
  39.  
  40.         System.out.println("\nThis program will calculate the student's final grade in the "
  41.                         + courseNumber +" "+className+" class.");
  42.  
  43.         //list the percentage weight that each assignment holds on final grade
  44.         System.out.println("\nAssignment percentages: ");
  45.         System.out.println(" Homework:  " + percent.format(.2));
  46.         System.out.println(" Quizes:    " + percent.format(.1));
  47.         System.out.println(" Test:              " + percent.format(.15));
  48.         System.out.println(" Projects:  " + percent.format(.2));
  49.         System.out.println(" Final Exam:        " + percent.format(.25));
  50.         System.out.println(" Attendance:        " + percent.format(.1));
  51.  
  52.         //prompts user to enter student's information
  53.         System.out.print("\nPlease enter student's first name. ");
  54.         studentFirst = userInput.next();
  55.         System.out.print("Please enter student's last name. ");
  56.         studentLast = userInput.next();
  57.         student = new Student(studentFirst, studentLast);
  58.  
  59.         // prompts the user for the number of homework grades to be entered
  60.         System.out.println("\n:ASSIGNMENT/HOMEWORK GRADES:");
  61.         System.out.print("\nHow many homework grades will you be entering? ");
  62.         qtyGrades = userInput.nextInt();
  63.  
  64.         //prompts the user for all homework grades
  65.         for (int a = 0; a < qtyGrades; a++) {
  66.             hCount++;
  67.             System.out.print("Enter homework grade #" + (a + 1) + ". ");
  68.             hw = userInput.nextInt();
  69.             hSum += hw;
  70.         }
  71.  
  72.         // prompts the user for the number of quiz grades to be entered
  73.         System.out.println("\n:QUIZ GRADES:");
  74.         System.out.print("\nHow many quiz grades will you be entering? ");
  75.         qtyGrades = userInput.nextInt();
  76.  
  77.         //prompts the user for all quiz grades
  78.         for (int q = 0; q < qtyGrades; q++) {
  79.             qCount++;
  80.             System.out.print("Enter quiz grade #" + (q + 1) + ". ");
  81.             qz = userInput.nextInt();
  82.             qSum += qz;
  83.         }
  84.        
  85.         // prompts the user for the number of project grades to be entered
  86.         System.out.println("\n:PROJECT GRADES:");
  87.         System.out.print("\nHow many projects grades will you be entering? ");
  88.         qtyGrades = userInput.nextInt();
  89.  
  90.         // prompts the user to input all project grades
  91.         for (int p = 0; p < qtyGrades; p++) {
  92.             pCount++;
  93.             System.out.print("Enter project grade #" + (p + 1) + ". ");
  94.             proj = userInput.nextInt();
  95.             pSum += proj;
  96.         }
  97.  
  98.         // prompts the user for the number of test grades to be entered
  99.         System.out.println("\n:TEST GRADES:");
  100.         System.out.print("\nHow many test grades will you be entering? ");
  101.         qtyGrades = userInput.nextInt();
  102.        
  103.         //prompts the user for all test grades
  104.         for (int t = 0; t < qtyGrades; t++) {
  105.             tCount++;
  106.             System.out.print("Enter test grade #" + (t + 1) + ". ");
  107.             tst = userInput.nextInt();
  108.             tSum += tst;
  109.         }
  110.        
  111.         //prompts the user for the student's final test grade
  112.         System.out.println("\n:FINAL EXAM GRADE:");
  113.         System.out.print("\nWhat is the student's final exam grade? ");
  114.         final_exam = userInput.nextFloat();
  115.         count++;
  116.  
  117.         // prompts the user to input the student's attendance grade
  118.         System.out.print("\nWhat is the student's attendance grade? ");
  119.         atnd_grade = userInput.nextFloat();
  120.         atndCount++;
  121.  
  122.         //calculate and display student's semester grade for the class
  123.         totalSum = hSum + qSum + pSum + tSum + final_exam + atnd_grade;
  124.         totalCount = hCount + qCount + pCount + tCount + count + atndCount;
  125.        
  126.         // update user the date and time stamp for last modification
  127.         Date today = new Date();
  128.         SimpleDateFormat date = new SimpleDateFormat("EEEE, MMMM d, yyyy h:mm a");
  129.         System.out.println("\n\nLast Modified: " + date.format(today));
  130.         System.out.println(student+"\tSEMESTER GRADE: "+
  131.                 deci.format(student.finalGrade(totalSum,totalCount)));
  132.        
  133.         System.out.println("\n:ASSIGNMENT AVERAGES:\n");
  134.        
  135.         //display each assignments average as well as final exam grade and attendance grade
  136.         System.out.println("Homework Average\t{ "+deci.format(student.avg(hSum,hCount))+" }");
  137.         System.out.println("Quiz Average\t\t{ "+deci.format(student.avg(qSum,qCount))+" }");
  138.         System.out.println("Project Average\t\t{ "+deci.format(student.avg(pSum,pCount))+" }");
  139.         System.out.println("Test Average\t\t{ "+deci.format(student.avg(tSum,tCount))+" }");
  140.         System.out.println("Final Exam Grade\t{ "+final_exam+" }");
  141.         System.out.println("Attendance Grade\t{ "+atnd_grade+" }");
  142.        
  143.        
  144.  
  145.        
  146.  
  147.     }
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement