Answer to Question #240899 in Java | JSP | JSF for sim

Question #240899

Program 7 - Rooms

You are required to assist with the development of a system to manage venues and computer labs at CPUT. Write the JAVA classes.

UML class diagram of two base classes

RunVenues

Code the class RunVenues. The outline of the class is as follows:

public class RunVenues { public static void main(String[] args) {

//Add code 1 here //Add code 2 here

}

}

1 Create an object of the type VenueControlClass..

2 Call the menuControl() in the VenueControlClass class by using the object.




1
Expert's answer
2021-09-22T23:49:17-0400

The answer provided here is a CPUT Lecture management system. one can add lectures, delete a lecture, update a lecture and print all the lectures. Each lecture has got several attributes, it has the course code, course title, the venue of the lecture which is one of the Computer labs available, the lecturer and lecture time.


import java.util.ArrayList;
import java.util.Scanner;

class VenueControlClass
{

    private String Course_code;
    private String Course_title;
    private String venue_comp_lab;
    private String lecturer_name;
    private String lecture_time;

    // the constructor
    public VenueControlClass() {
        this.Course_code = "";
        this.Course_title = "";
        this.venue_comp_lab = "";
        this.lecturer_name = "";
        this.lecture_time = "";
    }
    public VenueControlClass(String Course_code, String Course_title, String venue_comp_lab, String lecturer_name, String lecture_time) {
        this.Course_code = Course_code;
        this.Course_title = Course_title;
        this.venue_comp_lab = venue_comp_lab;
        this.lecturer_name = lecturer_name;
        this.lecture_time = lecture_time;
    }

    public static void add(VenueControlClass new_lecture) {
    }

    //setters and getter methods
    public String get_course_Code() {
        return Course_code;
    }

    public void set_course_Code(String Course_code) {
        this.Course_code = Course_code;
    }

    public String getCourse_title() {
        return Course_title;
    }

    public void setCourse_title(String Course_title) {
        this.Course_title = Course_title;
    }

    public String getVenue_comp_lab() {
        return venue_comp_lab;
    }

    public void setVenue_comp_lab(String venue_comp_lab) {
        this.venue_comp_lab = venue_comp_lab;
    }

    public String getLecturer_name() {
        return lecturer_name;
    }

    public void setLecturer_name(String lecturer_name) {
        this.lecturer_name = lecturer_name;
    }

    public String getLecture_time() {
        return lecture_time;
    }

    public void setLecture_time(String lecture_time) {
        this.lecture_time = lecture_time;
    }

    @Override
    public String toString() {
        return "Course code: " + this.Course_code + "\n" + "Course Title: " + this.Course_title + "\n"
                + "Lecture Venue: " + this.venue_comp_lab + "\n"+ "Lecture Name: " + this.lecturer_name + "\n"
                + "Lecture Time: " + this.lecture_time + "\n";
    }
}

public class RunVenues{

    //Now we create an array that will store the data for all lectures
    private static int get_venue_By_Course_Code(ArrayList<VenueControlClass> Lectures, String Course_code) {

        for (int i = 0; i < Lectures.size(); i++) {
            if (Lectures.get(i).get_course_Code().compareTo(Course_code) == 0) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<VenueControlClass> Lectures = new ArrayList<VenueControlClass>();
        String Course_code;
        String Course_title;
        String venue_comp_lab;
        String lecturer_name;
        String lecture_time;
        int terminate_condition = 1;
        System.out.println("CPUT venues and computer labs Management system.");
        while (terminate_condition == 1) {
            System.out.println("1. Add new lecture.");
            System.out.println("2. Update a lecture.");
            System.out.println("3. Delete a lecture.");
            System.out.println("4. Print the all lectures.");
            System.out.println("Enter the option for operation to perform:");
            int option = sc.nextInt();
            if (option == 1) {
                sc.nextLine();
                System.out.print("Enter the Course code: ");
                Course_code = sc.nextLine();
                System.out.print("Enter the Course Title: ");
                Course_title = sc.nextLine();
                System.out.print("Enter the venue(one of the computer labs): ");
                venue_comp_lab = sc.nextLine();
                System.out.print("Enter Lecturer name: ");
                lecturer_name = sc.nextLine();
                System.out.print("Enter lecture time: ");
                lecture_time = sc.nextLine();
                VenueControlClass new_Lecture = new VenueControlClass(Course_code, Course_title, venue_comp_lab, lecturer_name, lecture_time);
                Lectures.add(new_Lecture);
                System.out.println("\nLecture has been added.\n");
            }
            else if (option == 2)
            {
                sc.nextLine();
                System.out.print("Enter product code to edit: ");
                Course_code = sc.nextLine();
                int index = get_venue_By_Course_Code(Lectures, Course_code);
                if (index != -1) {
                    System.out.print("Enter the course Title: ");
                    Course_title = sc.nextLine();
                    System.out.print("Enter a new Venue: ");
                    venue_comp_lab = sc.nextLine();
                    System.out.print("Enter a new lecturer: ");
                    lecturer_name = sc.nextLine();
                    System.out.print("Enter a new lecture time: ");
                    lecture_time = sc.nextLine();
                    VenueControlClass new_Lecture = new VenueControlClass(Course_code, Course_title, venue_comp_lab, lecturer_name,lecture_time);
                            Lectures.remove(index);
                    Lectures.add(index, new_Lecture);
                    System.out.println("\nThe lecture has been updated.\n");
                }
                //IN the case where the Id is not in the array of Lectures
                else {
                    System.out.println("\nWrong Course Code.\n");
                }
            }
            else if (option == 3)
            {
                sc.nextLine();
                System.out.print("Enter Course code for lecture to delete: ");
                Course_code = sc.nextLine();
                int index = get_venue_By_Course_Code(Lectures, Course_code);
                if (index != -1) {
                    Lectures.remove(index);
                    System.out.println("\nThe Lecture has been deleted.\n");
                } else {
                    System.out.println("\nWrong Course Code.\n");
                }
            }
            else if (option == 4)
            {
                System.out.println("CPUT Lecture venues in the various computer labs ");
                int count = 1;
                for (int i = 0; i < Lectures.size(); i++) {
                    System.out.print(count);
                    System.out.println(".\t"+Lectures.get(i).toString() + "\n");
                    count = count+1;
                }
            }
            else {
                System.out.println("Invalid option please try again");
            }
            System.out.print("1. To perform another operation or any other key to exit: ");
            int my_option = sc.nextInt();
            terminate_condition = my_option;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS