Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a Student class with instance variables name, id, midterm1, midterm2 and

ID: 3591612 • Letter: D

Question

Define a Student class with instance variables name, id, midterm1, midterm2 and final. Name is a string whereas others are all integers`. Also, add a static variable nextId, which is an integer and statically initialized to 1. Have some overloaded constructors. In each of them, the id should be assigned to the next available id given by nextId. The default constructor should set the name of the student object to “StudentX” where X is the next id. Add a calculateGrade() method which returns a string for the letter grade of the student, like “A”, “B”, “C”, “D” or “F”, based on the overall score. Overall score should be calculated as (30% of midterm1 + 30% of midterm2 + 40% of final). The letter grade should be calculated the same way as in the homework 1 exercises.
Your test class, to be named as TestStudents, should create 25 student objects with default constructor and invoke the setter methods for midterm1, midterm2 and final with random numbers ranging from 50 to 100 inclusive. After that, it should print the student information. Student information should include name, midterm1, midterm2, final and the letter grade given by the calculateGrade() method.

Explanation / Answer

Student.java

public class Student {
// Declaring instance variables
private int id;
private String name;
private int midterm1;
private int midterm2;
private int finalxam;

// Declaring a static variable
static int nextId;

// Zero argumented constructor
public Student() {
id = ++nextId;
this.name = "Student" + id;
}

// Parameterized constructor
public Student(String name, int midterm1, int midterm2, int finalxam) {
super();
this.id = ++nextId;
this.name = name;
this.midterm1 = midterm1;
this.midterm2 = midterm2;
this.finalxam = finalxam;
}

// This method will calculate overall score and return the grade letter
public String calculateGrade() {
String gradeLetter = null;
double overallScore = 0.30 * midterm1 + 0.30 * midterm2 + 0.40 * finalxam;
if (overallScore >= 90)
gradeLetter = "A";
else if (overallScore >= 80 && overallScore < 90)
gradeLetter = "B";
else if (overallScore >= 70 && overallScore < 80)
gradeLetter = "C";
else if (overallScore >= 60 && overallScore < 70)
gradeLetter = "D";
else if (overallScore < 60)
gradeLetter = "F";

return gradeLetter;
}

// getters and setters
public int getMidterm1() {
return midterm1;
}

public void setMidterm1(int midterm1) {
this.midterm1 = midterm1;
}

public int getMidterm2() {
return midterm2;
}

public void setMidterm2(int midterm2) {
this.midterm2 = midterm2;
}

public int getFinalxam() {
return finalxam;
}

public void setFinalxam(int finalxam) {
this.finalxam = finalxam;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Name=" + name + ", Midterm1=" + midterm1 + ", Midterm2=" + midterm2 + ", Final =" + finalxam + " grade=" + calculateGrade();
}

}

_________________

TestStudents.java

import java.util.Random;

public class TestStudents {


public static void main(String[] args) {

//Creating an random class object
Random r = new Random();

//Creating an Array of Student array which holds student objects
Student studs[] = new Student[25];

/* This for loop will set the midterm1 ,mindterm2 and
* final exm scores randomly for all students
*/
for (int i = 0; i < studs.length; i++) {
studs[i] = new Student();
studs[i].setMidterm1(r.nextInt((100 - 50) + 1) + 50);
studs[i].setMidterm2(r.nextInt((100 - 50) + 1) + 50);
studs[i].setFinalxam(r.nextInt((100 - 50) + 1) + 50);


}

//Displaying each student info
System.out.println("** Displaying Students Info **");
for (int i = 0; i < studs.length; i++) {
System.out.println(studs[i].toString());
}

}

}

___________________

Output:

** Displaying Students Info **
Name=Student1, Midterm1=80, Midterm2=77, Final =54 grade=D
Name=Student2, Midterm1=51, Midterm2=91, Final =63 grade=D
Name=Student3, Midterm1=58, Midterm2=80, Final =98 grade=B
Name=Student4, Midterm1=89, Midterm2=69, Final =85 grade=B
Name=Student5, Midterm1=89, Midterm2=51, Final =64 grade=D
Name=Student6, Midterm1=99, Midterm2=78, Final =64 grade=C
Name=Student7, Midterm1=73, Midterm2=97, Final =54 grade=C
Name=Student8, Midterm1=55, Midterm2=80, Final =94 grade=C
Name=Student9, Midterm1=97, Midterm2=66, Final =97 grade=B
Name=Student10, Midterm1=53, Midterm2=63, Final =66 grade=D
Name=Student11, Midterm1=61, Midterm2=82, Final =85 grade=C
Name=Student12, Midterm1=60, Midterm2=74, Final =72 grade=D
Name=Student13, Midterm1=62, Midterm2=84, Final =73 grade=C
Name=Student14, Midterm1=65, Midterm2=87, Final =96 grade=B
Name=Student15, Midterm1=54, Midterm2=88, Final =88 grade=C
Name=Student16, Midterm1=57, Midterm2=98, Final =79 grade=C
Name=Student17, Midterm1=50, Midterm2=90, Final =73 grade=C
Name=Student18, Midterm1=60, Midterm2=57, Final =65 grade=D
Name=Student19, Midterm1=53, Midterm2=72, Final =92 grade=C
Name=Student20, Midterm1=61, Midterm2=95, Final =72 grade=C
Name=Student21, Midterm1=96, Midterm2=92, Final =53 grade=C
Name=Student22, Midterm1=97, Midterm2=89, Final =67 grade=B
Name=Student23, Midterm1=50, Midterm2=74, Final =58 grade=D
Name=Student24, Midterm1=83, Midterm2=70, Final =89 grade=B
Name=Student25, Midterm1=79, Midterm2=88, Final =82 grade=B

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote