Write your solutions to both questions A and B in a plain te

Write your solutions to both questions (A and B) in a plain text file called Problem1. txt or PDF tile called Probleml.pdf. Do NOT submit a .doc, .doc x, .rtf or any other kind of file. You are asked to design a Student class that models students at Carleton University. What attributes would your class have? What methods would your class have? For your solution, write it in point/tabular form as follows: Student state attribute 1 name - short description attribute 2 name - short description attribute N name - short description Student behavior method 1 name - short description method 2 name - short description method M name - short description Your class should have at least 5 attributes and 5 methods.

Solution

public class Student {

private String name; // First name for the student.

private int ID; // Unique ID number for the student.

private int age; // Age of student.

private int grades[]={80,75,90}; // Marks scored by Student in 3 different subjects.

private float average=0; // Average Marks scored by student.

public Student(String name, int iD, int age) {

this.name = name;

ID = iD;

this.age = age;

}

public String getName() {

return name;

}

public int getID() {

return ID;

}

public int getAge() {

return age;

}

public float getAverage() {

int sum=0;

for(int i=0;i<3;i++)

{

sum+=grades[i];

}

average=sum/3;

return average;

}

public void display(){

System.out.println(\"Student Name : \"+name+\" , ID : \"+ID+\" , Age : \"+age);

System.out.println(\"Average marks secured : \"+average);

}

public static void main(String args[]) {

Student ob=new Student(\"Sam\",01,15);

ob.getAverage();

ob.display();

}

}

 Write your solutions to both questions (A and B) in a plain text file called Problem1. txt or PDF tile called Probleml.pdf. Do NOT submit a .doc, .doc x, .rtf
 Write your solutions to both questions (A and B) in a plain text file called Problem1. txt or PDF tile called Probleml.pdf. Do NOT submit a .doc, .doc x, .rtf

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site