Question

In: Computer Science

Java problem Implement class Course containing: String name, enumeration Type (Foundamental, Specialization, Discipline), enumeration Stream (English,...

Java problem

Implement class Course containing: String name, enumeration Type (Foundamental, Specialization, Discipline), enumeration Stream (English, French, German), int creditPoints.

 Class Contract has an array of courses with methods addCourse(Course), deleteCourse(type, stream, name) sort(), display().

 Courses are sorted by stream, type, name.

 If 2 courses are equal raise a custom exception in method sort().

 Make Contract implement Storable.

Solutions

Expert Solution

//Course.java

package test2;

public class Course {

   private String name;
   private enum Type {
       Foundamental, Specialization, Discipline;
   }
   private Type type;
  
   private enum Stream {
       English, French, German;
   }
   private Stream stream;
  
   private int creditPoints;

   public Course(){
       this.name = "Not set";
       this.type = Type.Discipline;
       this.stream = Stream.English;
       this.creditPoints = 0;
   }
  
   public Course(String name, String type, String stream, int creditPoints){
       this.name = name;
       this.type = Type.valueOf(type);
       this.stream = Stream.valueOf(stream);
       this.creditPoints = creditPoints;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getType() {
       return type.name();
   }

   public void setType(String type) {
       this.type = Type.valueOf(type);
   }

   public String getStream() {
       return stream.name();
   }

   public void setStream(String stream) {
       this.stream = Stream.valueOf(stream);
   }

   public int getCreditPoints() {
       return creditPoints;
   }

   public void setCreditPoints(int creditPoints) {
       this.creditPoints = creditPoints;
   }
  
   public String toString(){
       return "Name: " + this.name + "\n"
               + "Type: " + this.type.name() + "\n"
               + "Stream: " + this.stream.name() + "\n"
               + "Credit Points: " + this.creditPoints + "\n";
   }
}

//test.java
package test2;
public class test {
   public static void main(String[] args) {
       Course c1 = new Course("b","Discipline","English",5);
       Course c2 = new Course("a","Discipline","German",5);
       Course c3 = new Course("d","Foundamental","French",5);
       Course c4 = new Course("c","Discipline","English",5);
       Course c6 = new Course("f","Specialization","French",5);
       Contract obj = new Contract();
       obj.add(c1);
       obj.add(c2);
       obj.add(c3);
       obj.add(c4);
       obj.add(c6);
       obj.display();
       obj.sortByName();
       System.out.println("\nAfter sorting by Name\n");
       obj.display();
       obj.sortByType();
       System.out.println("\nAfter sorting by Type\n");
       obj.display();
       obj.sortByStream();
       System.out.println("\nAfter sorting by Stream\n");
       obj.display();
       Course c5 = new Course("c","Discipline","English",5);
       obj.add(c5);
       System.out.println("\nDuplicate value exception\n");
       obj.sortByName();
   }

}


Related Solutions

java NetBeans Class Entry: Implement the class Entry that has a name (String), phoneNumber (String), and...
java NetBeans Class Entry: Implement the class Entry that has a name (String), phoneNumber (String), and address (String). Implement the initialization constructor . Implement the setters and getters for all attributes. Implement the toString() method to display all attributes. Implement the equals (Entry other) to determine if two entries are equal to each other. Two entries are considered equal if they have the same name, phoneNumber, and address. Implement the compareTo (Entry other) method that returns 0 if the two...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's name • idNumber: an int representing the employee's ID number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked The class should also have the following methods: • Constructor: takes the employee's name and ID number as arguments • Accessors: allow access to all of the fields of the Payroll...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
(Java Problem) Create a Produce class that have an instance variable of type String for the...
(Java Problem) Create a Produce class that have an instance variable of type String for the name, appropriate constructors, appropriate accessor and mutator methods, and a public toString() method. Then create a Fruit and a Vegetable class that are derived from Produce. These classes should have constructors that take the name as a String, the price (this is the price per box) as a double, the quantity as an integer, and invoke the appropriate constructor from the base class to...
Define and implement class Course. This class should contain the following fields: course name, course description,...
Define and implement class Course. This class should contain the following fields: course name, course description, department, time the course starts, weekday the course is held on (for simplicity, let us assume the course only meets once a week). This class should contain getters and setters for all its attributes. This class also needs at least one constructor. Save this class and its definition into a file named Course.java. Define and implement class Student. This class should contain the following...
Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of...
Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of the account holder. a method, getBalance, that returns a double corresponding to the account balance. a method withdraw that accepts a double, and deducts the amount from the account balance. Write a class definition for a subclass, CheckingAccount, that contains: a boolean instance variable, overdraft. (Having overdraft for a checking account allows one to write checks larger than the current balance). a constructor that...
Write the following classes: Class Entry: 1. Implement the class Entry that has a name (String),...
Write the following classes: Class Entry: 1. Implement the class Entry that has a name (String), phoneNumber (String), and address (String). 2. Implement the initialization constructor . 3. Implement the setters and getters for all attributes. 4. Implement the toString() method to display all attributes. 5. Implement the equals (Entry other) to determine if two entries are equal to each other. Two entries are considered equal if they have the same name, phoneNumber, and address. 6. Implement the compareTo (Entry...
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
Java Question I have a Queue containing String type taking in a text file with an...
Java Question I have a Queue containing String type taking in a text file with an iterator. I need to use ArrayList and HashMap for freqHowMany to get a frequency table in descending order by the highest frequency words in the text. Any help would be much appreciated and thanks! final Iterator input = new Scanner(System.in).useDelimiter("(?U)[^\\p{Alpha}0-9']+"); final Queue queueFinal = new CircularFifoQueue<>(wordsLast); while (input.hasNext()) { final String queueWord = input.next(); if (queueWord.length() > minimumLength) { queueFinal.add(queueWord); // the oldest item...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT