In: Computer Science
Complete the attached program by adding the following:
a) add the Java codes to complete the constructors for Student class
b) add the Java code to complete the findClassification() method
c) create an object of Student and print out its info in main() method of StudentInfo class.
* * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //Create an object of Student //Print out this object's info: myName, myAge,myGender, //and classification } } class Student{ String myName; int myAge; char myGender; int myCreditsEarned; Student() //no-arg constructor //assigns initial values to the data membmers in Student { } Student(String name, int age, char gender, int credits) //parameterized constructor //uses the paramters to assign initial values to //the data members in Student { } String findClassification() // use myCreditsEarned to determine the student's classification // if myCreditsEarned>=90, return "Senior"; // if 60<=myCreditsEarned<90, return "Junior"; // if 30<=myCreditsEarned<60, return "Sophomore"; // if myCreditsEarned<30, return "Freshman". { } }
public class StudentInfo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// Create an object of Student
// Print out this object's info: myName, myAge,myGender,
// and classification
//created student object
Student s = new Student("Uday", 25, 'M', 99);
// printing the data
System.out.println("Name: " + s.myName);
System.out.println("Age: " + s.myAge);
System.out.println("Gender: " + s.myGender);
System.out.println("Classification: " + s.findClassification());
}
}
class Student {
String myName;
int myAge;
char myGender;
int myCreditsEarned;
Student()
// no-arg constructor
// assigns initial values to the data membmers in Student
{
myAge = 0;
myCreditsEarned = 0;
myName = "";
myGender = ' ';
}
Student(String name, int age, char gender, int credits)
// parameterized constructor
// uses the paramters to assign initial values to
// the data members in Student
{
// assignign the data to the instance variables
myName = name;
myAge = age;
myGender = gender;
myCreditsEarned = credits;
}
String findClassification()
// use myCreditsEarned to determine the student's classification
// if myCreditsEarned>=90, return "Senior";
// if 60<=myCreditsEarned<90, return "Junior";
// if 30<=myCreditsEarned<60, return "Sophomore";
// if myCreditsEarned<30, return "Freshman".
{
// checking creditsEarned and returning the appropriate classification
if (myCreditsEarned >= 90)
return "Senior";
if (myCreditsEarned >= 60)
return "Junior";
if (myCreditsEarned >= 30)
return "Sophomore";
return "Freshman";
}
}