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;
import java.util.Scanner;
class Course_Details
{
private String courseName;
private int studentNumbers;
private String lecturer;
private int venue;
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public int getStudentNumbers() {
return studentNumbers;
}
public void setStudentNumbers(int studentNumbers) {
this.studentNumbers = studentNumbers;
}
public String getLecturer() {
return lecturer;
}
public void setLecturer(String lecturer) {
this.lecturer = lecturer;
}
public void print()
{
System.out.println("Course name: "+getCourseName());
System.out.println("Student numbers: "+getStudentNumbers());
System.out.println("Lecturer: "+getLecturer());
System.out.println("Venue: "+getVenue());
}
public void assignVenue()
{
venue = new Random().nextInt(3)+1;
}
public int getVenue()
{
return venue;
}
}
public class Main {
public static void main(String[] args)
{
System.out.print("Enter course name: ");
String courseName = new Scanner(System.in).nextLine();
System.out.print("Enter student numbers: ");
int studentNumbers = new Scanner(System.in).nextInt();
System.out.print("Enter lecturer: ");
String lecturer = new Scanner(System.in).nextLine();
Course_Details course_details = new Course_Details();
course_details.setCourseName(courseName);
course_details.setStudentNumbers(studentNumbers);
course_details.setLecturer(lecturer);
course_details.assignVenue();
System.out.println();
course_details.print();
}
}
Comments
Leave a comment