Question

Data structures in java Implement the following classes: 1. class Course that includes three instance variables:...

Data structures in java

Implement the following classes:

1. class Course that includes three instance variables: private String Name; // the course name private int ID; // the course ID private Course next; // the link

Your class should have the following:

  •  A constructor that initializes the two instance variables id and name.

  •  Set and get methods for each instance variable.

2. class Department that includes three instance variables: private String deptName;
private Course head, tail;

Your class should have the following:

  •  a constructor that initializes the department name

  •  public boolean exist(int id) that checks whether the course

    object with id passed as parameter exists in the list or not.

  •  public boolean insert(int id, String n) that creates and adds the course if the course with id passed as parameter does not exist in the list. The course must be added in ascending order. The method will

    return false if the id was a duplicate.

  •  public boolean remove(int id) that deletes a course if it exists in

    the list and returns true. The method will return false if the id was not found in the list.

  •  public String findCourse(int id) that returns a course name if the id exists in the list.

11

 public void print() that prints the department name and all the courses in the array.

Write the expected time and space complexity as a comment at the beginning of each method of your class.

3. Write a test application named Lab2Test. In the main method, do the following:

  •  Input the department name then create a department object.

  •  Display a menu to the user and asking for a choice to be entered.

    As follows:

    The program can perform the following: 1- insert a course
    2- remove a course
    3- search for a course

    4- print courses

    5- exit
    Please enter your selection:

  •  The program will perform the action selected by the user and display a proper message when necessary.

  •  The program will repeat these actions until the user terminates the program (Hint: Use a loop).

Sample Output

Please enter the name of the department: Computer Engineering

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 30 Error! Incorrect choice.

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 4
Computer Engineering department does not have any courses.

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 1
Enter the course number or -1 to stop: 300
Enter the course name: Design and Analysis of Algorithms Enter the course number or -1 to stop: 356
Enter the course name: Computer Networks I
Enter the course number or -1 to stop: 300
Enter the course name: testing duplicate
Error! duplicate ID number...
Enter the course number or -1 to stop: 325
Enter the course name: Human-Computer Interaction
Enter the course number or -1 to stop: 262
Enter the course name: Fundamentals of Digital Logic Enter the course number or -1 to stop: -1

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 4
Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic

13

2 - 300 Design and Analysis of Algorithms 3 - 325 Human-Computer Interaction
4 - 356 Computer Networks I

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 2 Enter the course number: 325 The course was removed

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 2 Enter the course number: 325 The course is not in the list

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 4
Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic

2 - 300 Design and Analysis 3 - 356 Computer Networks I

The program can perform the 1- insert a course
2- remove a course
3- search for a course

4- print courses

of Algorithms
following:

5- exit
Please enter your selection: 3
Enter the course number: 300
The id: 300 corresponds to Design and Analysis of Algorithms

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

14

5- exit
Please enter your selection: 3
Enter the course number: 325
The id: 325 does not correspond to any course in the department

The program can perform the following: 1- insert a course
2- remove a course
3- search for a course

4- print courses

5- exit
Please enter your selection: 5 Exiting the program...

Homework Answers

Answer #1

Answer number 1 : Following are the snapshot for the first above question, The user needs to write it on the java text editor and can be run by the help of java compiler.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Write a Java Program, that opens the file "students.txt" The program must read the file line...
Write a Java Program, that opens the file "students.txt" The program must read the file line by line The program parses each line that it reads For example, for this line: 1:mohamed:ali:0504123456:cs102:cs202 The program must print    >ID = 1    >First Name = Mohamed   >Last Name = Ali   >Mobie = 0504123456   >Courses = cs102, cs202 In addition, it adds the mobile phone number into an ArrayList called studentPhoneList Print the content and the size of studentPhoneList Show your results and provide...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE TABLE Student (  sid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  address VARCHAR(20) NOT NULL,  major CHAR(2)); CREATE TABLE Professor (  pid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  department VARCHAR(10) NOT NULL); CREATE TABLE Course (  cid INT PRIMARY KEY,  title VARCHAR(20) NOT NULL UNIQUE,  credits INT NOT NULL,  area VARCHAR(5) NOT NULL); CREATE TABLE Transcript (  sid INT,  cid INT,  pid INT,  semester VARCHAR(9),  year YEAR,  grade CHAR(1) NOT NULL,  PRIMARY KEY (sid, cid, semester, year),  FOREIGN KEY (sid) REFERENCES Student...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
Please make a Java program that has a menu method and includes dialog boxes. The program...
Please make a Java program that has a menu method and includes dialog boxes. The program will call the proper method, but each method will be completed later. Your program will keep track of information for a Hospital. The program will be menu-driven. Your menu is to look something like the following: UPMC Medical Center Add/Modify Patient Information Add/Modify Physician Information Add/Modify Medical Information Hospital Report Section Exit the Medical System Please Make your selection > In this first phase,...