Write a program that contains two classes: the class StudentInfo and the class S
ID: 3616211 • Letter: W
Question
Write a program that contains two classes: the classStudentInfo and the classScoresReport
The StudentInfo class has following fields and methods
· firstname,lastname: String
· test1,test2, test3: double.
· constructor that accepts firstname, lastname, test1, test2 andtest3
· methodcalculateScores to calculate and return theaverage of test scores. The average could be a decimal number
The ScoresReport class includes the main method that :
· Theprogram asks users to enter the following information
-First name
-Last name
-Scores of test 1 (0 - 100)
-Scores of test 2 (0 - 100)
-Scores of test 3 (0 - 100)
· create anobject of StudentInfo class
· call themethod calculateScores of StudentInfo class to have the averagescores
· Displaythe following information
------------------------------------------------------------------------------
The number of characters in the last name is: <number>
The first character of the last name is: <char>
Student: LASTNAME, firstname
Average scores: scores from above calculation
------------------------------------------------------------------------------
Explanation / Answer
please rate - thanks class StudentInfo{
private String first,last;
private double test1,test2,test3;
public StudentInfo()
{
}
public StudentInfo(String f,String l,double t1, double t2, doublet3)
{
first=f;
last=l;
test1=t1;
test2=t2;
test3=t3;
}
public double calculateScores()
{
double average;
average=(test1+test2+test3)/3.;
return average;
}
public String getfirst()
{return first; }
public String getlast()
{return last; }
}
import java.util.*;
class ScoresReport
{static Scanner in=new Scanner(System.in);
public static void main(String args[])
{double average;
String last,first;
double t1,t2,t3;
last=getname("last");
first=getname("first");
t1=getgrade(1);
t2=getgrade(2);
t3=getgrade(3);
StudentInfo student=new StudentInfo(first,last,t1,t2,t3);
last=student.getlast();
System.out.println("The number of characters in the last name is:"+last.length());
System.out.println("The first character of the last name is:"+last.charAt(0));
System.out.println("Student: "+last.toUpperCase()+", "+student.getfirst());
System.out.printf("Average Scores:%.2f ",student.calculateScores());
}
public static double getgrade(int n)
{double grade;
System.out.print("Enter grade for test "+n+": ");
grade=in.nextDouble();
while(grade<0||grade>100)
{System.out.println("grade must be between 0 and100");
System.out.print("Ent grade for test "+n+": ");
grade=in.nextDouble();
}
return grade;
}
public static String getname(String mess)
{String name;
System.out.print("Enter students "+mess+" name: ");
name=in.next();
return name;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.