hey guys, my code requires a toString method and an equals method. My question is, did i do them correctly? im a bit confused on this topic, Any help, im greatful for, and the toString and equals methods are at the bottom, Thank you so much.
import java.util.*;
class Scores
{
public double quiz, quizPercentage, totalPoints, total;
public double midTerm, midTermPercent;
public double finalExam, finalPercent, friendFinalExam;
public String grade, gradeM, gradeF, classGrade, schoolName, friendSchool;
Scanner keyboard = new Scanner(System.in);
public double setQuizes(int number)
{
System.out.println("Enter your grade for quiz "+number);
quiz = keyboard.nextDouble();
return quiz;
}
public double setmidTermGrade(int number)
{
System.out.println("Enter the grade of your mid term exam ");
midTerm = keyboard.nextDouble();
return midTerm;
}
public double setfinalExamGrade(int number)
{
System.out.println("Enter the grade of your the final exam ");
finalExam = keyboard.nextDouble();
return finalExam;
}
public String setnameSchool()
{
System.out.println("Enter the name of your school");
schoolName = keyboard.nextLine();
return schoolName;
}
public String setfriendSchool()
{
System.out.println("Enter the name of your friend's school");
friendSchool = keyboard.nextLine();
return friendSchool;
}
public double setfriendFinal()
{
System.out.println("Enter your friends final exam score");
friendFinalExam = keyboard.nextDouble();
return friendFinalExam;
}
public String getquizGrade(double quiz)
{
if (quiz>=0 && quiz<=10)
{
if (quiz<=10 && quiz>=9)
{
grade = "A";
}
else if (quiz<9 && quiz>=8)
{
grade = "B";
}
else if (quiz<8 && quiz>=7)
{
grade = "C";
}
else if (quiz<7 && quiz>=6)
{
grade = "D";
}
else if (quiz<6 && quiz>= 0)
{
grade = "F";
}
}
return grade;
}
public String getmidTerm(double midTerm)
{
if (midTerm>=0 && midTerm<=100)
{
if (midTerm<=100 && midTerm>=90)
{
gradeM = "A";
}
else if (midTerm<90 && midTerm>=80)
{
gradeM = "B";
}
else if (midTerm<80 && midTerm>=70)
{
gradeM = "C";
}
else if (midTerm<70 && midTerm>=60)
{
gradeM = "D";
}
else if (midTerm<60 && midTerm>=0)
{
gradeM = "F";
}
}
return gradeM;
}
public String getfinalExam(double finalExam)
{
if (finalExam>=0 && finalExam<=100)
{
if (finalExam<=100 && finalExam>=90)
{
gradeF = "A";
}
else if (finalExam<90 && finalExam>=80)
{
gradeF = "B";
}
else if (finalExam<80 && finalExam>=70)
{
gradeF = "C";
}
else if (finalExam<70 && finalExam>=60)
{
gradeF = "D";
}
else if (finalExam<60 && finalExam>=0)
{
gradeF = "F";
}
}
return gradeF;
}
public double percentQuizes(double number1, double number2, double number3)
{
total = number1 + number2 + number3;
quizPercentage = ((total*25)/30);
return quizPercentage;
}
public double percentMidTerm()
{
midTermPercent = ((midTerm*35)/100);
return midTermPercent;
}
public double percentFinal()
{
finalPercent = ((finalExam*40)/100);
return finalPercent;
}
public double gradePercentage()
{
totalPoints = quizPercentage + midTermPercent + finalPercent;
return totalPoints;
}
public String getclassGrade(double totalPoints)
{
if (totalPoints>=0 && totalPoints<=100)
{
if (totalPoints<=100 && totalPoints>=90)
{
classGrade = "A";
}
else if (totalPoints<90 && totalPoints>=80)
{
classGrade = "B";
}
else if (totalPoints<80 && totalPoints>=70)
{
classGrade = "C";
}
else if (totalPoints<70 && totalPoints>=60)
{
classGrade = "D";
}
else if (totalPoints<60 && totalPoints>=0)
{
classGrade = "F";
}
}
return classGrade;
}
public String toString()
{
String str = "School name is: " + schoolName
+ "\nFinal exam is: " + finalExam;
return str;
}
public boolean equals(Scores object2)
{
boolean status;
if (schoolName.equals(object2.friendSchool) &&
friendFinalExam == object2.finalExam)
status = true;
else
status = false;
return status;
}
}