For this assignment you are required to suggest a Java class of your own. Your J
ID: 3870189 • Letter: F
Question
For this assignment you are required to suggest a Java class of your own.
Your Java class must do something useful and/or interesting.
Write code for your approved Java program as follows:
Create a class, which was approved per your proposal, with a main method that creates an instance of your class and calls one or more constructor(s), and the methods of your class.
Create a minimum of three private data attributes for your class. These can all be primitive variables (int, char, long, double etc..), or they can be reference variables (another class*).
Explanation / Answer
Student.java
public class Student
{
private String stName;
private int marks;
private char grade;
private double average;
public void setStName(String stName){
this.stName=stName;
}
public String getStName(){
return stName;
}
public void setMarks(int marks){
this.marks=marks;
}
public int getMarks(){
return marks;
}
public void setGrade(char grade){
this.grade=grade;
}
public char getGrade(){
return grade;
}
public void setAverage(double average){
this.average=average;
}
public double getAverage(){
return average;
}
// Default constructor
public Student(){
}
//Parameterized constructor
public Student(String stName, int marks, char grade, double average){
this.stName=stName;
this.marks=marks;
this.grade=grade;
this.average=average;
}
public static void display(Student student){
System.out.println("Student details.....");
System.out.println("Student Name : "+student.getStName());
System.out.println("Marks : "+student.getMarks());
System.out.println("Grade : "+student.getGrade());
System.out.println("Average : "+student.getAverage());
System.out.println();
}
public static void main(String[] args)
{
Student st1=new Student();
display(st1);
Student st2=new Student("Mr. ABC",500,'A',83.66);
display(st2);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.