Student Class:
// Practical 7A
// Student class
// gman
public class Student
{
// instance variables
private int studentID;
private String studentName;
private String course;
private double printQuota;
// constructor
public Student()
{
studentID = 0;
studentName = new String();
course = new String();
printQuota = 7.00;
}
// set student ID method
public void setStudentID(int ID)
{
studentID = ID;
}
// get student ID method
public int getStudentID()
{
return studentID;
}
// set student name method
public void setStudentName(String sName)
{
studentName = sName;
}
// get student name method
public String getStudentName()
{
return studentName;
}
// set student course method
public void setCourse(String sCourse)
{
course = sCourse;
}
// get student course method
public String getCourse()
{
return course;
}
// set student ( TOP UP ) printQuota method
public void setPrintQuota(double topUP)
{
printQuota = printQuota + topUP;
}
// get student printQuota method
public double getPrintQuota()
{
return printQuota;
}
}
Main Method:
// gman
// 16/2/2012
import java.util.Scanner;
public class StudentTestQ2
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
Student student1 = new Student();
Student student2 = new Student();
// student 1
// ID
System.out.println("Enter Student ID: ");
int sID1 = kb.nextInt();
student1.setStudentID(sID1);
// Name
System.out.println("Enter Student Name: ");
String sName1 = kb.nextLine();
student1.setStudentName(sName1);
// Course
System.out.println("Enter Course: ");
String sCourse1 = kb.nextLine();
student1.setCourse(sCourse1);
// student 2
//ID
System.out.println("Enter Student ID: ");
int sID2 = kb.nextInt();
student2.setStudentID(sID2);
// Name
System.out.println("Enter Student Name: ");
String sName2 = kb.nextLine();
student2.setStudentName(sName2);
// Course
System.out.println("Enter Course: ");
String sCourse2 = kb.nextLine();
student2.setCourse(sCourse2);
// Print Details
System.out.println("Student 1: \tStudent ID \t " + student1.getStudentID() + "\n \t\tName \t "
+ student1.getStudentName() + "\n \t\tCourse \t " + student1.getCourse());
System.out.println("Student 2: \tStudent ID \t " + student2.getStudentID() + "\n \t\tName \t "
+ student2.getStudentName() + "\n \t\tCourse \t " + student2.getCourse());
}
}
OutPut:
StudentJavaSkipped.JPG 45.62K
24 downloadsAnyone tell me why this is happening :confused:
Gman


Sign In
Create Account


Back to top










