Question

The class name is StudentTest and the filename is StudentTest.java. The program must do the following...

The class name is StudentTest and the filename is StudentTest.java. The program must do the following (all in main):

  1. The program must create three Student objects using the Student constructor. Use literal data for the arguments to the constructor for the first two Students, and variables for the third Student. Prompt for and input the first name, last name and GPA for the third Student object.
  2. The program must display the name and GPA for each Student. Use printf and the get methods to access the data. Be sure to label the output.
  3. You must format the GPA with two places past the decimal point using the format String %.2f
  4. The program must prompt for a new GPA for the first Student. Update the GPA by calling the setGPA method. You should test with valid and invalid input. Display the first Student’s name and GPA after the update.
  5. Compare the GPAs of all three students to determine and display the highest GPA. Use the getGPA method to retrieve each GPA.
  6. Here is a sample program run:

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that utilizes a Professor class. A professor has a first name, last name,...
Write a program that utilizes a Professor class. A professor has a first name, last name, affiliation, easiness grade, and a helpfulness grade. Grades range from 1 (lowest) to 5 (highest). The Professor class has two constructors. The first constructor initiates the object with just the first name, the last name, and the affiliation. The default value for easiness and helpfulness grade is 3. The second constructor initiates the object using the first name, the last name, the affiliation, and...
4. Write a C++ program that reads Id, name, and GPA of each of n students...
4. Write a C++ program that reads Id, name, and GPA of each of n students in a course, where n is an integer number between 10 and 30 (inclusive). Use bubble sorting to display the list of students in an ascending order according to the student name.
/* *Your name *Date * *Explanation of Program *-Modifying the first program * - print,printf, escape...
/* *Your name *Date * *Explanation of Program *-Modifying the first program * - print,printf, escape values, arithmetic operators */ public class Welcome1 { //main method begins execution f Java application public static void main (String [] args) { System.out.println("Welcome to Java Programming"); }//end method mai }//end class Welcome1 /* Output copied from display/message windowo * ----jGRASP exec: java Welcome1 *Welcom to Java Programming * *----jGRASP: operation complete. */ in JAVA Please edit this program in Java and update it
Create a program named admission that takes as Input the student name, GPA and the admission...
Create a program named admission that takes as Input the student name, GPA and the admission Test Score, the application should display if the student got accepted or rejected. The program should use a function named AcceptOrReject( gpa, testScore) to control the program. Acceptance is based on the following criteria: The student can get accepted in the following two cases : 1- if the GPA is less than 3.0, the test score has to be more than 80 to get...
Create a class hierarchy to be used in a university setting. The classes are as follows:...
Create a class hierarchy to be used in a university setting. The classes are as follows:  The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
I can open the file in the program, but I cannot figure out how to properly...
I can open the file in the program, but I cannot figure out how to properly split the data and assign a grade to the number values in the text file. I keep getting :: ValueError: invalid literal for int() with base 10: 'Roger Jones 75\n' Below are the assignment details: This program processes grades for a small class. It reads an input file named grade_input.txt where each record contains a student’s first name, last name and numeric grade (a...