The class name is StudentTest and the filename is StudentTest.java. The program must do the following (all in main):
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Student.java
public class Student {
//Declaring instance variables
private String firstname;
private String lastname;
private double gpa;
//Parameterized constructor
public Student(String firstname, String lastname,
double gpa) {
this.firstname = firstname;
this.lastname = lastname;
this.gpa = gpa;
}
// getters and setters
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
}
_______________________
// StudentTest.java
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
String fname,lname;
double gpa,maxGPA;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
Student student1=new Student("Kane","Williams",3.4);
Student student2=new Student("Sachin","Tendulkar",3.6);
//Getting the input entered
by the user
System.out.print("Enter student#3 first name :");
fname=sc.next();
System.out.print("Enter student#3 last name :");
lname=sc.next();
System.out.print("Enter student#3 GPA :");
gpa=sc.nextDouble();
Student student3=new Student(fname,lname,gpa);
System.out.println("First Name\tLast Name\tGPA");
System.out.println("---------\t--------\t---");
System.out.printf("%10s\t%10s\t%.2f\n",student1.getFirstname(),student1.getLastname(),student1.getGpa());
System.out.printf("%10s\t%10s\t%.2f\n",student2.getFirstname(),student2.getLastname(),student2.getGpa());
System.out.printf("%10s\t%10s\t%.2f\n",student3.getFirstname(),student3.getLastname(),student3.getGpa());
while(true)
{
System.out.print("Enter Student#1 GPA :");
gpa=sc.nextDouble();
if(gpa<0)
{
System.out.println("** Invalid.GPA
Must be positive **");
}
else
{
student1.setGpa(gpa);
break;
}
}
System.out.printf("Student#1 Name :%s
%s\n",student1.getFirstname(),student1.getLastname());
System.out.printf("Student#1 GPA :
%.2f\n",student1.getGpa());
if(student1.getGpa()>student2.getGpa() &&
student1.getGpa()>student3.getGpa())
{
maxGPA=student1.getGpa();
}
else if(student2.getGpa()>student3.getGpa())
{
maxGPA=student2.getGpa();
}
else
{
maxGPA=student3.getGpa();
}
System.out.printf("Highest GPA : %.2f\n",maxGPA);
}
}
____________________________
Output:
Enter student#3 first name :Ricky
Enter student#3 last name :Pointing
Enter student#3 GPA :3.2
First Name Last Name GPA
--------- -------- ---
Kane Williams 3.40
Sachin Tendulkar 3.60
Ricky Pointing 3.20
Enter Student#1 GPA :4.0
Student#1 Name :Kane Williams
Student#1 GPA : 4.00
Highest GPA : 4.00
_______________Could you plz rate me well.Thank You
Get Answers For Free
Most questions answered within 1 hours.