1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dima020 [189]
3 years ago
8

Grade Average Lab Assignment Purpose: The goal of this lab assignment is to learn how to use for loops and if/else commands. Wri

te a program that will calculate a numeric average and a letter grade for a student. The main method creates an object of the Grades class that sends two parameters to the Grade class constructor: a student name and the grades to be averaged.
Computers and Technology
1 answer:
miss Akunina [59]3 years ago
3 0
<h2>Answer:</h2><h2></h2>

//class to test the Grade class

public class GradeTest{

    public static void main(String []args){        

       //create the grades to be averaged

      double [] grades = {23, 45, 67, 12.6};

       

       //create an object of the Grade class and

       //pass in the necessary arguments to the constructor

       Grade grade = new Grade("John", grades);

       

       //print out the results from the Grade object.

       System.out.println("Your name is " + grade.getName());

       System.out.println("Your average score is " + grade.getAverage());

       System.out.println("Your letter grade is " + grade.getLetterGrade());

       

   }

}  //End of the GradeTest class

//The Grade class

class Grade {

   

   //create instance variables

   private String name;

   private double [] grades;

   

   //constructor for the class

  public Grade(String name, double [] grades){

       

       //initialize the instance variables

      this.name = name;

       this.grades = grades;

       

   }

   

   //method to return the name of the student

  public String getName(){

       //return the name

       return this.name;

   }

   

   

   //method to calculate the average of the grades

  public double getAverage(){

       

       double [] grades = this.grades;

       

       //initialize some needed variables

       double sum = 0;

       double average = 0;

       

       //loop through the grades array and add each element to the sum variable

       for(int i =0; i < grades.length; i++){

           sum += grades[0];    

       }

       

       //calculate the average

      average = sum / grades.length;

       

       //return the average grade

       return average;

     

   }

   

   

   //method the calculate the letter grade from the average

   public char getLetterGrade(){

       

       //initialize some variables

      double average = this.getAverage();

       char letterGrade;

       

       //check the average and determine its corresponding letter grade

       if(average >= 40 && average < 45){

           letterGrade = 'E';

       }

       else if(average >= 45 && average < 50){

           letterGrade = 'D';

       }

       else if(average >= 50 && average < 60){

           letterGrade = 'C';

       }

       else if(average >= 60 && average < 70){

           letterGrade = 'B';

       }

       else if(average >= 70 && average <= 100){

           letterGrade = 'A';

       }

       else {

           letterGrade = 'F';

       }

       //return the letter grade

       return letterGrade;

       

   }

   

}   //End of the Grade class

<h2>Sample Output:</h2>

Your name is John

Your average score is 23.0

Your letter grade is F

<h2>Explanation:</h2>

The code above is written in Java and it contains comments explaining important parts of the code. It also contains a sample output got from running the program. To run this on your machine, copy the code and save in a file named GradeTest.java

You might be interested in
Selet the correct answer.
diamong [38]

Answer:

magnetic

Explanation:

With tapes, you can selectively overwrite parts of a recording with new content.

6 0
3 years ago
Read 2 more answers
The time delay of a long-distance call can be determined by multiplying a small fixed constant by the number of communication li
lara [203]

Answer:

The diameter of T is 2k+1.

See explaination for the details

Explanation:

We can compute the diameter of the tree T by a pruning procedure, starting at the leaves (external nodes).

Remove all leaves of T. Let the remaining tree be T1.

Remove all leaves of T1. Let the remaining tree be T2.

Repeat the "remove" operation as follows: Remove all leaves of Ti. Let remaining tree be Ti+1.

When the remaining tree has only one node or two nodes, stop! Suppose now the remaining tree is Tk.

If Tk has only one node, that is the center of T. The diameter of T is 2k.

If Tk has two nodes, either can be the center of T. The diameter of T is 2k+1.

7 0
3 years ago
Write a function isCString which accepts as arguments a const pointer to a char array and an integer for the size of the array
Umnica [9.8K]

Answer:

Mnnmnkjhsgxlsjzgxfckabxvzuajs

7 0
3 years ago
What technology changes led to industrialization?
qwelly [4]
Factors, also this is the wrong place to post this question
7 0
3 years ago
Arrange the following units of storage in descending<br> order. B, TB,KB, GB,MB
adell [148]

Answer:

TB,GB,MB,KB,B

Explanation:

7 0
3 years ago
Other questions:
  • What does CMOS stand for?
    15·2 answers
  • Percy is a lighting technician in a film production. For a shot, the chief lighting technician instructs Percy to get the kind o
    15·1 answer
  • By including ______
    15·2 answers
  • What came after the Phonograph
    13·2 answers
  • What were thomas edison's contributions to advances in technology?
    9·1 answer
  • To make slides in a PowerPoint Online application presentation have the same transition effect, select __________ on the Transit
    11·2 answers
  • What is the purpose of a report?
    6·2 answers
  • 3.4.6 colorful bracelet ?
    5·1 answer
  • Someone, please help me w/ king.com
    10·1 answer
  • What is the full form of MPEG?<br> The full form for MPEG is ________.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!