Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Project2 {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- double average = 0;
- int exams = 0;
- double total = 0;
- double cScore = 0;
- System.out.println("Enter number of exams");
- exams = s.nextInt();
- System.out.println("Enter scores");
- int pos = 0;
- while(pos == 0)
- {
- for(int i=1;i<=exams;i++)
- {
- if((cScore = s.nextDouble()) < 0)
- {
- //pos++;
- System.out.println("negative value: " + cScore);
- }
- else{
- total+=cScore;
- pos++;
- System.out.println("counter is at: " + i + " current total: " + total);
- }
- }
- System.out.println("avg is: " + (total/exams) + " total is " + total);
- if(pos!=exams)
- { System.out.println("error, reenter");
- pos = 0;
- total = 0;
- }
- else if(pos==exams)
- { System.out.println("cool"); }
- }
- /*
- for(int i=1;i<=exams;i++)
- {
- System.out.println("this is next double " + s.nextDouble());
- if(s.nextDouble() < 0)
- {
- i = 1;
- System.out.println("Error, reenter");
- }
- else
- {
- total += s.nextDouble();
- System.out.println("this is total " + total);
- }
- System.out.println("final total: " + total);
- }
- System.out.println((total/exams));
- /*
- //beginning of program to set the number of students and exams
- System.out.print("Welcome to GradeCalculator!");
- System.out.println();
- System.out.print("Please enter the number of students: ");
- int students = s.nextInt();
- System.out.print("Please enter the number of exams: ");
- int exams = s.nextInt();
- // defining class statistic variables and their starting values
- double classavg = 0;
- double classlow = 100;
- double classhigh = 0;
- for (int i = 1; i <= students; i++) {
- System.out.println();
- System.out.println("--------------------------------------");
- System.out.print("Enter student " + i + "'s name : ");
- //scanner for students' names
- String fname = s.next();
- String lname = s.next();
- System.out.print("Enter exam scores : ");
- //setting starting values for individual student variables
- double average = 0;
- double lowest = 100;
- double highest = 0;
- //loop for statistics begins
- for (int e = 1; e <= exams; e++) {
- double score = s.nextDouble();
- //setting requiremnts for correct input values
- if (score < 0) {
- System.out.print("Please re-enter only the invalid exam score(s): ");
- //invalid scores are wiped and re-enterable
- s.nextLine();
- score = s.nextDouble();
- }
- //finding the average
- average += (score / exams);
- //finding the lowest score
- if (score < lowest) {
- lowest = score;
- }
- //finding the highest score
- if (score > highest) {
- highest = score;
- }
- } //displaying grade information
- System.out.println();
- System.out.println("Grade statistics for " + fname + " " + lname + ":");
- System.out.println("Lowest Score : " + lowest);
- System.out.println("Highest Score : " + highest);
- System.out.println("Average : " + average);
- // deterimining grade
- if (average > 0 & average < 60) {
- System.out.println("Letter Grade : F");
- System.out.println(fname + " " + lname + " earns no stars.");
- } else if (average >= 60 & average < 70) {
- System.out.println("Letter Grade : D");
- System.out.println(fname + " " + lname + " earns 1 star! *");
- } else if (average >= 70 & average < 80) {
- System.out.println("Letter Grade : C");
- System.out.println(fname + " " + lname + " earns 2 stars! **");
- } else if (average >= 80 & average < 90) {
- System.out.println("Letter Grade : B");
- System.out.println(fname + " " + lname + " earns 3 stars! ***");
- } else if (average >= 90) {
- System.out.println("Letter Grade : A");
- System.out.println(fname + " " + lname + " earns 4 stars! ****");
- }
- //finding class statistics
- classavg += (average / students);
- if (average < classlow) {
- classlow = average;
- }
- if (average > classhigh) {
- classhigh = average;
- }
- //where the loop restarts for the next student
- }
- //main loop is over and class stats are displayed
- System.out.println("--------------------------------------");
- System.out.println("Class Statistics:");
- System.out.println(" Class Average : " + classavg);
- System.out.println(" Lowest Average : " + classlow);
- System.out.println(" Highest Average: " + classhigh);
- System.out.println();
- System.out.print("Done. Goodbye!");
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement