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

In this assignment I will ask you to write two classes in JAVA that might be par

ID: 3747028 • Letter: I

Question

In this assignment I will ask you to write two classes in JAVA that might be part of a student/course management system at a university. Notice that you will also be required to create/use a third class - with a main method - to test these classes.

Class One - Student

Each student at the university is stored as an instance of the Student class. Each instance knows the student's name, idNumber, total credits earned and total grade points earned.

Individual instances respond to the following methods

getName() - returns the String representing the student's full name

changeName() - takes a String as a parameter representing the student's full name (allows for name changes)

getID() - returns the String representing the student's id number (yes, the String)

addCredits() - takes in an int representing how many credits the student has earned. Used at the end of the semester to add credit hours

getCredits() - returns an int representing the number of credit points this student has accumulated

addGradePoints() - takes in a double representing how many new grade points the student has earned. Used at the end of the semester to add grade points

getGradePoints() - returns a double representing the number of grade points this student has accumulated

getGPA() - returns a double representing the student's current GPA (notice this is a calculation)

getStatus() - returns a String indicating whether the student is a freshman, sophomore, junior, or senior given UNI's definition of those terms (notice this is a calculation)

getLoginName() - returns the student's computer lab id name which consists of the first four characters of their name (bonus if you can make it of their last name) concatenated with the first 3 digits of their student ID number.

printInfo() - prints the name and ID number of the student in the format "Ben Schafer (123456)" (without the quotes)

toString() - returns a String with the same name and ID format used in printInfo

Additionally, Student has a single constructor that requires the client code provide the student's full name and ID numbers (as Strings) at construction time. By default, students begin with 0 credit hours and a total grade points of 0.0

For example,

A UML class diagram for this class would look like

Student

IN-CLASS DECISIONS

If client code asks a Student object for the GPA before the object has acquired any credits (totalCredits is zero) than the object should print a message and return 0.0.

0-29 means freshman, 30-59 means sophomore, 60-89 means junior, 90+ means senior

Any methods which take in numbers as parameters SHOULD accept negative numbers, but only up to the limit of the current state. For example,

if a student has 12 credits the class should accept addCredits(-4) where the result is 8 credits.

if a student has 12 credits the class should accept addCredits(-12) where the result is 0.

if a student has 12 credits the class should reject addCredits(-13)

by reject I mean completely ignore the request. Make no mathematical change but also print no messages.

For loginname you MAY take the first four characters in the name field regardless of what those characters are.

Student

  name : String  idNumber : String  totalCredits : int  gradePoints : double
  Student(String name, String id)  getName() : String  changeName(String newVal)  getID()  : String  addCredits(int amount)  getCredits() : int  addGradePoints(double amount)  getGradePoints():double  getGPA() : double  getStatus() : String  getLoginName() : String  toString() : String  printInfo() 

Explanation / Answer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Vamsi
*/
public class student {
  
//data members
String name,idNumber;
int totalCredits;
double gradePoints;
  
//methods
//constructor
student(String name,String id)
{
//variable initializing
this.name=name;
this.idNumber=id;
totalCredits=0;
gradePoints=0;
}
  
//getter methods
String getName()
{
return name;//returning name
}
String getID()
{
return idNumber;//returning id
}
int getCredits()
{
return totalCredits;//returning totalcredits
}
double getGradePoints()
{
return gradePoints;//returning gradePoints
}
void addGradePoints(double amount)
{
double d = gradePoints+amount;
if(d<0)System.out.println(" Amount can't be added to grade points ");//printing error message
else
gradePoints+=amount;
}
void addCredits(int amount)
{
int d= totalCredits+amount;
if(d<0)System.out.println(" Amount can't be added to totalCredits ");//printing error message
else
totalCredits+=amount;
}
//method to find and retun gpa of a student
double getGPA()
{
if(totalCredits==0)//if totalCredits is zero then
return 0;
return (gradePoints/totalCredits)*10;//calculating gpa
}
//method to find and return status of a student
String getStatus()
{
  
if(totalCredits <= 29)
{
return "Freshman";
}
else if(totalCredits <= 59)
{
return "Sophomore";
}
else if(totalCredits<=89)
{
return "Junior";
}
else
{
return "Senior";
}
}
  
  
@Override
public String toString(){
  
return "Name:"+this.name+", ID:"+this.idNumber+", Total credit:"+this.totalCredits+", Gradepoints: "+this.gradePoints+", Status: "+this.getStatus()+", Gpa :"+this.getGPA()+" ";
}
  
//method to print info
void printInfo(){
System.out.println("Name:"+this.name+", ID:"+this.idNumber+", Total credit:"+this.totalCredits+", Gradepoints: "+this.gradePoints+", Status: "+this.getStatus()+", Gpa :"+this.getGPA()+" ");
}
  
  
  
  
public static void main(String argv[])
{
//creating object
student n = new student("name lastname","123456");
  
//adding grade points
n.addGradePoints(80);
//adding total credis
n.addCredits(100);
  
n.printInfo();
}
}

output:

run:
Name:name lastname, ID:123456, Total credit:100, Gradepoints: 80.0, Status: Senior, Gpa :8.0

BUILD SUCCESSFUL (total time: 0 seconds)