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

Create a constructor for the Student class you created. The constructor should i

ID: 644621 • Letter: C

Question

Create a constructor for the Student class you created. The constructor should initialize each Student's ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. Save the application as ShowStudent2.java

Here's the Student class:

public class Student {
   private int ID;
   private int creditHours;
   private int pointsEarned;
   double GPA;
   public Student()
   {
   }

   public Student(int id,int hrs, int pts)   
   {
   ID=id;
   creditHours=hrs;
   pointsEarned=pts;
   }
   public double getGPA()   
   {
   return GPA;   
   }
   public void setGPA()
   {
   GPA = (double) pointsEarned / creditHours;
   }   
   public void setID(int number)
   {
   ID = number;
   }
   public int getID()
   {
   return ID;
   }
   public void setCreditHours(int hours)
   {
   creditHours = hours;
   }
   public int getCreditHours()
   {
   return creditHours;
   }
   public void setPointsEarned(int points)
   {
   pointsEarned = points;
   }
   public int getPointsEarned()
   {
   return pointsEarned;
   }
   }

Thank you!

Explanation / Answer

Open a file named ShowStudent.java a

class Student
{
private int ID;
private int creditHours;
private int pointsEarned;
double GPA;
public Student()
{
}

public Student(int id,int hrs, int pts)         
{
  ID=id;
  creditHours=hrs;
  pointsEarned=pts;
}
public double getGPA()       
{
  return GPA;         
}
public void setGPA()    
{
  GPA = (double) pointsEarned / creditHours;
}   
public void setID(int number)
{
  ID = number;
}
public int getID()
{
  return ID;
}
public void setCreditHours(int hours)
{
  creditHours = hours;
}
public int getCreditHours()
{
  return creditHours;
}
public void setPointsEarned(int points)
{
  pointsEarned = points;
}
public int getPointsEarned()
{
  return pointsEarned;
}
}
public class ShowStudent
{
public static void main(String[] args)
{
  // TODO Auto-generated method stub
  Student st1=new Student(9999,3,12);
  st1.setGPA();
  System.out.print("Student ID:"+st1.getID()+" GPA:"+st1.getGPA());

}

}

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