Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java Modify the application so that it can deal with multiple students. First, ask the user for all student names. Then read in the

in java

Modify the application so that it can deal with multiple students. First, ask the user for all student names. Then read in the scores for all quizzes, prompting for the score of each student. Finally, print the names of all students and their final scores. Use a single class and only static methods.

public class Student 

2

{ 

3

 private double[] scores; 

4

 private int scoresSize; 

5

 

6

 /** 

7

 Constructs a student with no scores and a maximum number of scores. 

8

 @capacity the maximum number of scores for this student 

9

 */ 

10

 public Student(int capacity) 

11

 { 

12

 scores = new double[capacity]; 

13

 scoresSize = 0; 

14

 } 

15

 

16

 /** 

17

 Adds a score for this student. 

18

 @param score the score to add 

19

 @return true if the score was added, false if there was no room to add the score 

20

 */ 

21

 public boolean addScore(double score) 

22

 { 

23

 if (scoresSize < scores.length) 

24

 { 

25

 scores[scoresSize] = score; 

26

 scoresSize++; 

27

 return true; 

28

 } 

29

 else 

30

 { 

31

 return false; 

32

 } 

33

 } 

34

 

35

 /** 

36

 Computes the sum of the scores of this student. 

37

 @return the sum of the scores 
 

38

 */ 
 

39

 public double sum() 
 

40

 { 

41

 double total = 0; 

42

 for (int i = 0; i < scoresSize; i++) 

43

 { 

44

 total = total + scores[i]; 
 

45

 } 

46

 return total; 

47

 } 

48

 

49

 /** 

50

 Gets the minimum score of this student. 

51

 @return the minimum score, or 0 if there are no scores. 

52

 */ 

53

 public double minimum() 

54

 { 

55

 if (scoresSize == 0) { return 0; } 

56

 double smallest = scores[0]; 

57

 for (int i = 1; i < scoresSize; i++) 

58

 { 

59

 if (scores[i] < smallest) 

60

 { 

61

 smallest = scores[i]; 

62

 } 

63

 } 

64

 return smallest; 

65

 } 

66

 

67

 /** 

68

 Gets the final score for this student. 

69

 @return the sum of the scores, with the lowest score dropped if 

70

 there are at least two scores, or 0 if there are no scores. 

71

 */ 

72

 public double finalScore() 

73

 { 

74

 if (scoresSize == 0) 

75

 { 

76

 return 0; 

77

 } 

78

 else if (scoresSize == 1) 

79

 { 

80

 return scores[0]; 

81

 } 

82

 else 

83

 { 

84

 return sum() - minimum(); 

85

 } 

86

 } 

87

} 

how_to_1/Score Analyzer.java

1

import java.util.Scanner; 

2

 

3

public class ScoreAnalyzer 

4

{ 

5

 public static void main(String[] args) 

6

 { 

7

 Scanner in = new Scanner(System.in); 

8

 Student fred = new Student(100); 

9

 System.out.println("Please enter values, Q to quit:"); 

10

 while (in.hasNextDouble()) 

11

 { 

12

 if (!fred.addScore(in.nextDouble())) 

13

 { 

14

 System.out.println("Too many scores."); 

15

 return; 

16

 } 

17

 } 

18

 System.out.println("Final score: " + fred.finalScore()); 

19

 } 

20

} 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

ISBN: 0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago