It should be clear that your assignment will not get any credit if:
- The assignment is submitted after due date.
- The submitted assignment does not open or file corrupt.
- The assignment is fully or partially copied from (other student or ditto copy from handouts or internet).
- Student ID is not mentioned in the assignment File or name of file is other than student ID.
- The assignment is not submitted in .java format.
Uploading instructions
Your submission must include:
- All the source code (.java files) and other necessary files to compile and run your program.
- Place both files (StudentRecord and TestStudentRecord) in a Zip file and Upload it on VULMS.
Note:Use Notepad or Notepad++ for coding and JDK package for java source code compilation and running (A video tutorial of JDK installation and configuration is given in course download section)
Objective
The objective of this assignment is- To give you some practice exercise of Classes and Objects. And how to compile and run java programs.
- Problem Statement:
You are required to write a java program which stores and display the Student information.
Detailed Description:
Your program should have following two classes.
- StudentRecord
- TestStudentRecord
ٰIn“StudentRecord”class, itshould have the following data members:
- Student ID
- Course ID
- Course Name
- Parameterized constructor
- Setter methods
- Getter methods
- Print method
Following is the detail of member method of “StudentRecord” class.
Setter methods: There must be a setter method for each data member of a class
Getter methods: There must be a getter method for each data member of class
Print method: It should display the values of each data member of class by calling getter methods.
Following is the detail of TestStudentRecord class
“TestStudentRecord” class containthe main method,within main () method, create an object of StudentRecord class by using the parameterized constructor, and pass it the three string parameters i.e. (student id, course id and course name). In Student id you must store your own VUID.
At the end, call the Print() method which will display the values of student id, course id and course name by calling the getter methods.
Lectures Covered: This assignment covers Lecture # 1-5
Deadline
Your assignment must be uploaded/submitted at or before 18/11/2014.
For any query about the assignment, contact at cs506@vu.edu.pk
GOOD LUCK
Solution:
public class Student {
private int studentid;
private int courseid;
private String studentname;
public Student()
{
studentid =0;
courseid =0;
studentname = "not set";
}
public void setStudentID(int sid)
{
if(sid>0){
this.studentid = sid;
}
else
{
this.studentid=100;
}
}
public void setCourseID(int cid)
{
if(cid>0){
this.studentid = cid;
}
else
{
this.studentid=100;
}
}
public void setName(String name)
{
this.studentname=name;
}
int getStudentID()
{
return studentid;
}
int getCourseID()
{
return courseid;
}
String getName()
{
return studentname;
}
public void print()
{
System.out.println("Student ID is:" + studentid );
System.out.println("Course ID is:" + courseid );
System.out.println("Student ID is:" + studentname );
}
}