Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Student;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Scanner;
- public class Project_2 {
- public static void main(String[] args) {
- // Program to calculate the grade for ITSE 1302-007 students
- NumberFormat percent = NumberFormat.getPercentInstance();
- DecimalFormat deci = new DecimalFormat("#.#");
- String studentFirst, studentLast;
- String courseNumber, className;
- float hw, qz, proj, tst, final_exam, atnd_grade;
- double qtyGrades, hSum = 0, qSum = 0, pSum = 0, tSum = 0;
- double hCount = 0, qCount = 0, pCount = 0, tCount = 0, count = 0, atndCount = 0;
- double totalSum,totalCount;
- Scanner userInput = new Scanner(System.in);
- Student student;
- //prompts user for course number and class name
- System.out.print("What is the course number? ");
- courseNumber = userInput.nextLine();
- System.out.print("What is the class name? ");
- className = userInput.nextLine();
- System.out.println("\t\t\t\t------------------------");
- System.out.println("\t\t\t\t- -");
- System.out.println("\t\t\t\t-\t"+courseNumber+" -");
- System.out.println("\t\t\t\t- "+className+" -");
- System.out.println("\t\t\t\t- Semester Grade -");
- System.out.println("\t\t\t\t- -");
- System.out.println("\t\t\t\t------------------------");
- System.out.println("\nThis program will calculate the student's final grade in the "
- + courseNumber +" "+className+" class.");
- //list the percentage weight that each assignment holds on final grade
- System.out.println("\nAssignment percentages: ");
- System.out.println(" Homework: " + percent.format(.2));
- System.out.println(" Quizes: " + percent.format(.1));
- System.out.println(" Test: " + percent.format(.15));
- System.out.println(" Projects: " + percent.format(.2));
- System.out.println(" Final Exam: " + percent.format(.25));
- System.out.println(" Attendance: " + percent.format(.1));
- //prompts user to enter student's information
- System.out.print("\nPlease enter student's first name. ");
- studentFirst = userInput.next();
- System.out.print("Please enter student's last name. ");
- studentLast = userInput.next();
- student = new Student(studentFirst, studentLast);
- // prompts the user for the number of homework grades to be entered
- System.out.println("\n:ASSIGNMENT/HOMEWORK GRADES:");
- System.out.print("\nHow many homework grades will you be entering? ");
- qtyGrades = userInput.nextInt();
- //prompts the user for all homework grades
- for (int a = 0; a < qtyGrades; a++) {
- hCount++;
- System.out.print("Enter homework grade #" + (a + 1) + ". ");
- hw = userInput.nextInt();
- hSum += hw;
- }
- // prompts the user for the number of quiz grades to be entered
- System.out.println("\n:QUIZ GRADES:");
- System.out.print("\nHow many quiz grades will you be entering? ");
- qtyGrades = userInput.nextInt();
- //prompts the user for all quiz grades
- for (int q = 0; q < qtyGrades; q++) {
- qCount++;
- System.out.print("Enter quiz grade #" + (q + 1) + ". ");
- qz = userInput.nextInt();
- qSum += qz;
- }
- // prompts the user for the number of project grades to be entered
- System.out.println("\n:PROJECT GRADES:");
- System.out.print("\nHow many projects grades will you be entering? ");
- qtyGrades = userInput.nextInt();
- // prompts the user to input all project grades
- for (int p = 0; p < qtyGrades; p++) {
- pCount++;
- System.out.print("Enter project grade #" + (p + 1) + ". ");
- proj = userInput.nextInt();
- pSum += proj;
- }
- // prompts the user for the number of test grades to be entered
- System.out.println("\n:TEST GRADES:");
- System.out.print("\nHow many test grades will you be entering? ");
- qtyGrades = userInput.nextInt();
- //prompts the user for all test grades
- for (int t = 0; t < qtyGrades; t++) {
- tCount++;
- System.out.print("Enter test grade #" + (t + 1) + ". ");
- tst = userInput.nextInt();
- tSum += tst;
- }
- //prompts the user for the student's final test grade
- System.out.println("\n:FINAL EXAM GRADE:");
- System.out.print("\nWhat is the student's final exam grade? ");
- final_exam = userInput.nextFloat();
- count++;
- // prompts the user to input the student's attendance grade
- System.out.print("\nWhat is the student's attendance grade? ");
- atnd_grade = userInput.nextFloat();
- atndCount++;
- //calculate and display student's semester grade for the class
- totalSum = hSum + qSum + pSum + tSum + final_exam + atnd_grade;
- totalCount = hCount + qCount + pCount + tCount + count + atndCount;
- // update user the date and time stamp for last modification
- Date today = new Date();
- SimpleDateFormat date = new SimpleDateFormat("EEEE, MMMM d, yyyy h:mm a");
- System.out.println("\n\nLast Modified: " + date.format(today));
- System.out.println(student+"\tSEMESTER GRADE: "+
- deci.format(student.finalGrade(totalSum,totalCount)));
- System.out.println("\n:ASSIGNMENT AVERAGES:\n");
- //display each assignments average as well as final exam grade and attendance grade
- System.out.println("Homework Average\t{ "+deci.format(student.avg(hSum,hCount))+" }");
- System.out.println("Quiz Average\t\t{ "+deci.format(student.avg(qSum,qCount))+" }");
- System.out.println("Project Average\t\t{ "+deci.format(student.avg(pSum,pCount))+" }");
- System.out.println("Test Average\t\t{ "+deci.format(student.avg(tSum,tCount))+" }");
- System.out.println("Final Exam Grade\t{ "+final_exam+" }");
- System.out.println("Attendance Grade\t{ "+atnd_grade+" }");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement