Create a class named Course_Details that will contain get and set methods for the course name,
student numbers and lecturer. In the Course_Details class include a method called Assign Venue
that will randomly generate a Venue/Class for the course. Venues can be from 1 to 3 only. Your
main class must include a static method to handle the printing of the course report.
import java.util.Random;
public class Course_Details{
private String course_name,lecturer;
private int student_no;
public void setCourseName(String n){
course_name=n;
}
public String getCourseName(){
return course_name;
}
public void setStudentNo(int s_no){
student_no=s_no;
}
public int getStudentNo(){
return student_no;
}
public void setLecturer(String l){
lecturer=l;
}
public String getLecturer(){
return lecturer;
}
public int assignValue(){
Random rand = new Random();
int value =1+(rand.nextInt(3));
return value;
}
public static void display(){
Course_Details c1 = new Course_Details();
c1.setCourseName("Computer Science");
c1.setStudentNo(50);
c1.setLecturer("John");
System.out.println("Course name: "+c1.getCourseName());
System.out.println("Number of Students: "+c1.getStudentNo());
System.out.println("Lecturer: "+c1.getLecturer());
System.out.println("Venue: "+c1.assignValue());
}
public static void main(String[] args) {
Course_Details c1 = new Course_Details();
c1.display();
}
}
Output
Comments
Leave a comment