CS506 Web Design and Development Assignment 1 Solution Fall 2014

Please read the following instructions carefully before solving & submitting assignment:

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:
  1. All the source code (.java files) and other necessary files to compile and run your program.
  2. 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

    Following is the detail of StudentRecord class

    ٰIn“StudentRecord”class, itshould have the following data members:

    • Student ID
    • Course ID
    • Course Name

    StudentRecord class must have the following member methods:

    • Parameterized constructor
    • Setter methods 
    • Getter methods
    • Print method

    Parameterized constructor: It should take three String parameters named as (Student Id, Course Id and Course Name) and initializes the data members of StudentRecord class by using the setter methods. In Student Id you have to store your VUID.

    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.

Solution:

public class Student {
private String studentid;
private String courseid;
private String studentname;

public Student()
{
studentid =”not set”;
courseid =”not set”;
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;
}
String getStudentID()
{
return studentid;
}
String 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 );
}

DOWNLOAD SOLUTION HERE
loading...