Question

Java netbeans, points out of 10
Exercise#3 Create a class CourseGrades that consists of two data fields, student_id and grade. The class has set and get methods for each data variable. Then, write a Java program that reads students ids and corresponding grades into an array of type CourseGrades and print the average grade for the class. Your program should have two methods in addition to main(), one method for reading the students ids and grades and another method for computing the average grade

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// Please find the required solution
import java.util.Scanner;

//Course grade class
public class CourseGrades {

   // declare fields
   int student_id;
   int grade;

   // getters and setters for fields
   public int getStudent_id()
   {
      return student_id;
   }

   public void setStudent_id( int student_id )
   {
      this.student_id = student_id;
   }

   public int getGrade()
   {
      return grade;
   }

   public void setGrade( int grade )
   {
      this.grade = grade;
   }

   // read compute average
   public static float computeAverageGrade( CourseGrades[] courseGrades )
   {
      int sumOfGrades = 0;
      for( CourseGrades courseGrade : courseGrades )
         sumOfGrades += courseGrade.getGrade();
      return sumOfGrades / courseGrades.length;
   }

   // read input from user
   public static CourseGrades[] readCourseGrade()
   {
      System.out.println("Input for 5 students");
      Scanner input = new Scanner(System.in);
      CourseGrades[] courseGrades = new CourseGrades[5];
      for( int i = 0; i < 5; i++ )
      {
         courseGrades[i] = new CourseGrades();
         System.out.print("Input the student Id:");
         courseGrades[i].setStudent_id(input.nextInt());
         System.out.print("Input the student Grade:");
         courseGrades[i].setGrade(input.nextInt());
      }
      input.close();
      return courseGrades;
   }

   public static void main( String[] args )
   {
      // reads 5 student id's and grades
      CourseGrades[] courseGrades = readCourseGrade();

      // print the computed average
      System.out.println("Average of grades:" + computeAverageGrade(courseGrades));
   }
}
Sample output screenshot:

Input for 5 students Input the student Id:1 Input the student Grade:7 Input the student Id:2 Input the student Grade:8 Input

Add a comment
Know the answer?
Add Answer to:
Java netbeans, points out of 10 Exercise#3 Create a class CourseGrades that consists of two data...
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
  • Java - In NetBeans IDE: • Create a class called Student which stores: - the name...

    Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...

  • 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,...

  • IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the...

    IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade a student earned in each test, and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : In test 1 the highest grade was 93% and...

  • Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student...

    Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X 5...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • This is for JAVA programming. Create a test class that contains two arrays and two methods:...

    This is for JAVA programming. Create a test class that contains two arrays and two methods: - The first array has 3 rows and 3 columns and is initialized with type double data - The second array has 4 rows and 4 columns and is also initialized with type double data - The first method ArraysRows will receive an array of type double as an argument and then print out the sum and average of all elements in each ROW....

  • Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create...

    Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create two dog objects with names “spot” (who says, “Ruff!”) and “scruffy” (who says, “Wurf!”). Then display their names and what they say. Be sure to use setter and getter methods to assign(set) and retrieve(get) values for both Strings name and says. Your Task: Create the program using Netbeans and easyUML (i.e: Open a project in NetBeans then create the classes, attributes, and methods in...

  • Using Java coding, complete the following: This program should implement a LinkedList data structure to handle...

    Using Java coding, complete the following: This program should implement a LinkedList data structure to handle the management of student records. It will need to be able to store any number of students, using a Linked List. LinearNode.java can be used to aid creating this program Student should be a class defined with the following:    • String name    • int year    • A linked list of college classes (college classes are represented using strings)    • An...

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