Question

In Java 8 Write a HomeworkGrades class that stores the homework grades for 8 chapters into...

In Java 8

Write a HomeworkGrades class that stores the homework grades for 8 chapters into an array of doubles. • Write a constructor that takes an array as input and copies the contents of the array into the class’ array. • Write methods to calculate: • The average of the homework grades • The lowest grade • Write a main function that creates an array with this data: • double[ ] grades = {98.7, 77.9, 90, 83, 67, 33, 81, 90 }; • Print the average for the homework and the lowest grade, by calling the methods written in the HomeworkGrades class. Average and lowest grade should be printed with 2 digits after the decimal.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

save the following code in file named Main.java

class HomeworkGrades
{
private double []grades;

public HomeworkGrades(double grades[])
{
this.grades=new double[grades.length];
for(int i=0;i<grades.length;i++)
this.grades[i]=grades[i];
}
public double getAverage()
{
double sum=0;
for(int i=0;i<grades.length;i++)
sum+=grades[i];
return sum/grades.length;
}
  
public double fildLowestGrade()
{
double min=grades[0];
for(int i=1;i<grades.length;i++)
if(min>grades[i])
min=grades[i];
return min;
}
  
}
public class Main
{
public static void main(String[] args)
{
double[ ] grades = {98.7, 77.9, 90, 83, 67, 33, 81, 90 };
HomeworkGrades homework=new HomeworkGrades(grades);
System.out.printf("Average grade is %.2f%n",homework.getAverage());
System.out.printf("Lowest grade is %.2f%n",homework.fildLowestGrade());
}
  
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Answer #2

Here is an implementation of the HomeworkGrades class that stores the homework grades for 8 chapters into an array of doubles, and provides methods to calculate the average and lowest grade:

public class HomeworkGrades {    private double[] grades;    public HomeworkGrades(double[] grades) {        this.grades = grades.clone();
    }    public double getAverage() {        double sum = 0;        for (double grade : grades) {
            sum += grade;
        }        return sum / grades.length;
    }    public double getLowestGrade() {        double min = Double.MAX_VALUE;        for (double grade : grades) {            if (grade < min) {
                min = grade;
            }
        }        return min;
    }
}

And here is a main function that creates an array with the given data and prints the average and lowest grade:

public static void main(String[] args) {    double[] grades = {98.7, 77.9, 90, 83, 67, 33, 81, 90};    HomeworkGrades hwGrades = new HomeworkGrades(grades);
    System.out.printf("Average: %.2f\n", hwGrades.getAverage());
    System.out.printf("Lowest grade: %.2f\n", hwGrades.getLowestGrade());
}

When you run the main function, it should output:

Average: 78.87Lowest grade: 33.00

Note that we use the printf method with the format string "%.2f" to print the average and lowest grade with two digits after the decimal.


answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
In Java 8 Write a HomeworkGrades class that stores the homework grades for 8 chapters into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • help 6. (15 points) Define class GradeStat to describe the grades of all people in a...

    help 6. (15 points) Define class GradeStat to describe the grades of all people in a group. (1) Declare data member grades as an array of integers (we can declare it as a double type, but use int type can be simpler). (2) Write a constructor taking an array of int as input parameter. Use it to initialize data member. Note that each element in the array should be a non- negative int not larger than 100, that is, an...

  • SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes...

    SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array....

  • Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person’s name and...

    Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList Copyright | Addison-Wesley | Starting Out with Java | [email protected] | Printed from Chegg iOS App

  • Write a C++ program. Using the while loop or the do – while loop write a...

    Write a C++ program. Using the while loop or the do – while loop write a program that does the following: Calculate the average of a series of homework grades (0 - 100) entered one at a time. In this case the lowest score will be dropped and the average computed with the remaining grades. For example suppose you enter the following grades: 78, 85, 81, 90, 88, 93 and 97.The average will be computed from the 6 grades 85,...

  • The given data is the grades for people in this class. The goal here is to...

    The given data is the grades for people in this class. The goal here is to determine the factors that effect student's Grade in the class. 4) Find the mean and median for the men's and the women's Quizzes. Gender Men Women 5) Test the claim that the majority of students at this class are women. F M F F M F F F F M M F F F M F F F F M M F F M...

  • Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class...

    Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT