Advertisement
Guest User

kljasdka

a guest
Oct 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Project2 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner s = new Scanner(System.in);
  7. double average = 0;
  8. int exams = 0;
  9. double total = 0;
  10. double cScore = 0;
  11. System.out.println("Enter number of exams");
  12. exams = s.nextInt();
  13. System.out.println("Enter scores");
  14. int pos = 0;
  15. while(pos == 0)
  16. {
  17. for(int i=1;i<=exams;i++)
  18. {
  19. if((cScore = s.nextDouble()) < 0)
  20. {
  21. //pos++;
  22. System.out.println("negative value: " + cScore);
  23. }
  24. else{
  25. total+=cScore;
  26. pos++;
  27. System.out.println("counter is at: " + i + " current total: " + total);
  28. }
  29. }
  30. System.out.println("avg is: " + (total/exams) + " total is " + total);
  31. if(pos!=exams)
  32. { System.out.println("error, reenter");
  33. pos = 0;
  34. total = 0;
  35. }
  36. else if(pos==exams)
  37. { System.out.println("cool"); }
  38. }
  39.  
  40. /*
  41. for(int i=1;i<=exams;i++)
  42. {
  43. System.out.println("this is next double " + s.nextDouble());
  44. if(s.nextDouble() < 0)
  45. {
  46. i = 1;
  47. System.out.println("Error, reenter");
  48. }
  49. else
  50. {
  51. total += s.nextDouble();
  52. System.out.println("this is total " + total);
  53. }
  54. System.out.println("final total: " + total);
  55. }
  56. System.out.println((total/exams));
  57.  
  58. /*
  59. //beginning of program to set the number of students and exams
  60. System.out.print("Welcome to GradeCalculator!");
  61. System.out.println();
  62. System.out.print("Please enter the number of students: ");
  63. int students = s.nextInt();
  64. System.out.print("Please enter the number of exams: ");
  65. int exams = s.nextInt();
  66.  
  67. // defining class statistic variables and their starting values
  68. double classavg = 0;
  69. double classlow = 100;
  70. double classhigh = 0;
  71.  
  72. for (int i = 1; i <= students; i++) {
  73. System.out.println();
  74. System.out.println("--------------------------------------");
  75. System.out.print("Enter student " + i + "'s name : ");
  76. //scanner for students' names
  77. String fname = s.next();
  78. String lname = s.next();
  79. System.out.print("Enter exam scores : ");
  80. //setting starting values for individual student variables
  81. double average = 0;
  82. double lowest = 100;
  83. double highest = 0;
  84.  
  85. //loop for statistics begins
  86. for (int e = 1; e <= exams; e++) {
  87. double score = s.nextDouble();
  88. //setting requiremnts for correct input values
  89. if (score < 0) {
  90. System.out.print("Please re-enter only the invalid exam score(s): ");
  91. //invalid scores are wiped and re-enterable
  92. s.nextLine();
  93. score = s.nextDouble();
  94. }
  95. //finding the average
  96. average += (score / exams);
  97.  
  98. //finding the lowest score
  99. if (score < lowest) {
  100. lowest = score;
  101. }
  102.  
  103. //finding the highest score
  104. if (score > highest) {
  105. highest = score;
  106. }
  107.  
  108. } //displaying grade information
  109. System.out.println();
  110. System.out.println("Grade statistics for " + fname + " " + lname + ":");
  111. System.out.println("Lowest Score : " + lowest);
  112. System.out.println("Highest Score : " + highest);
  113. System.out.println("Average : " + average);
  114.  
  115. // deterimining grade
  116. if (average > 0 & average < 60) {
  117. System.out.println("Letter Grade : F");
  118. System.out.println(fname + " " + lname + " earns no stars.");
  119. } else if (average >= 60 & average < 70) {
  120. System.out.println("Letter Grade : D");
  121. System.out.println(fname + " " + lname + " earns 1 star! *");
  122. } else if (average >= 70 & average < 80) {
  123. System.out.println("Letter Grade : C");
  124. System.out.println(fname + " " + lname + " earns 2 stars! **");
  125. } else if (average >= 80 & average < 90) {
  126. System.out.println("Letter Grade : B");
  127. System.out.println(fname + " " + lname + " earns 3 stars! ***");
  128. } else if (average >= 90) {
  129. System.out.println("Letter Grade : A");
  130. System.out.println(fname + " " + lname + " earns 4 stars! ****");
  131. }
  132. //finding class statistics
  133. classavg += (average / students);
  134. if (average < classlow) {
  135. classlow = average;
  136. }
  137. if (average > classhigh) {
  138. classhigh = average;
  139. }
  140. //where the loop restarts for the next student
  141. }
  142. //main loop is over and class stats are displayed
  143. System.out.println("--------------------------------------");
  144. System.out.println("Class Statistics:");
  145. System.out.println(" Class Average : " + classavg);
  146. System.out.println(" Lowest Average : " + classlow);
  147. System.out.println(" Highest Average: " + classhigh);
  148. System.out.println();
  149. System.out.print("Done. Goodbye!");
  150. */
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement