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

This is a Java exercise. Create a class of students (call the class \"student\")

ID: 3732622 • Letter: T

Question

This is a Java exercise. Create a class of students (call the class "student"). Each student should be characterized by their first and last name (two Strings), the year they were born (integer), their grade (char) and their height (double) When creating a student object, you should be able to define its properties. In the student class, add a method that calculates the age of the student based on the year of birth and a method that counts the number of 'a' and 'o' in their last name (and capitals too)

Explanation / Answer

here is your class : ----------->>>>>>>>>>

import java.util.*;

public class Student{
private String fname;
private String lname;
private int year;
private char grade;
private double height;

public Student(){
  fname = "";
  lname = "";
  year = 0;
  grade = ' ';
  height = 0.0;
}
public Student(String fn,String ln,int y,char g,double h){
  fname = fn;
  lname = ln;
  year = y;
  grade = g;
  height = h;
}

public String getFirstName(){
  return fname;
}
public String getLastName(){
  return lname;
}
public int getYear(){
  return year;
}
public char getGrade(){
  return grade;
}
public double getHeight(){
  return height;
}
public void setFirstName(String fn){
  fname = fn;
}
public void setLastName(String ln){
  lname = ln;
}
public void setGrade(char g){
  grade = g;
}
public void setYear(int y){
  year = y;
}
public void setHeight(double h){
  height = h;
}
public int getAge(){
  return Calendar.getInstance().get(Calendar.YEAR) - year;
}
public int countsaoC(){
  int r = 0;
  for(int i = 0;i<lname.length();i++){
   if(lname.charAt(i) == 'o' || lname.charAt(i) == 'a' || Character.isUpperCase(lname.charAt(i))){
    r++;
   }
  }

  return r;
}

public String toString(){
  return "Name : - "+fname+" "+lname+" Age : "+getAge()+" Height : "+height+" Grade : "+grade;
}
}

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