Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have my course.java code and period.java code. Inside my course.java, I have a

ID: 3690153 • Letter: I

Question

I have my course.java code and period.java code. Inside my course.java, I have a method public Period getPeriod() but I don't know how do I implement my Period.java code in that method. Can someone help me out!

Course.java

class Course{

int department;
int courseNum;
String name;
char day;
int timeSlot;
int credits;
Student students[] = new Student[20];
  

  


public Course(int department, int courseNum, String name, char day, int timeSlot, int credits) {
this.department = department;
this.courseNum = courseNum;
this.name = name;
this.day = day;
this.timeSlot = timeSlot;
this.credits = credits;
}

public int getDepartment() {
return department;
}

public int getCourseNumber() {
return courseNum;
}

public String getName() {
return name;
}

public Period getPeriod() {
//I want to return period here.
}

public int getCredits() {
return credits;
}

public Student[] getRoster() {
return students;
}

public String toString(){
return ""+this.department+":"+this.courseNum+" " +"["+this.name+"]"+" "+this.periods +" " + "credits:"+this.credits;
}

public boolean equals(Course other){
return courseNum==other.courseNum && department==other.department;
}

}

Period.java

public class Period{
  
   private char day;
   private int timeSlot;
  
   public static void main(String[] args){
      
       Period p1 = new Period('M', 2);
Period p2 = new Period('M', 2);
Period p3 = new Period('F', 4);
int status = p1.compareTo(p2);
if(status == 0){
System.out.println(p1 + " is equal to " + p2);
}
else if(status == -1){
System.out.println(p1 + " comes before " + p2);
}
else{
System.out.println(p1 + " comes after " + p2);
}
status = p1.compareTo(p3);
if(status == 0){
System.out.println(p1 + " is equal to " + p3);
}
else if(status == -1){
System.out.println(p1 + " comes before " + p3);
}
else{
System.out.println(p1 + " comes after " + p3);
}
}
      
      
  
  
   public Period(char day, int timeSlot){
       if(day >= 'a' && day <= 'z'){
day = (char) (day + (int)'A' - (int)'a'); // converting to uppercase here
}
       this.day = day;
       this.timeSlot = timeSlot;
      
   }
  
   public char getDay(){
       return this.day;
   }
  
   public int getTimeSlot(){
       return this.timeSlot;
   }
  
   public String toString(){
      
       return ""+this.day + this.timeSlot;
   }
  
   public boolean equals(Period p){
return day == p.day && timeSlot == p.timeSlot;
}
  
   public int compareTo(Period other){
if(equals(other)){
return 0;
}
else{
if(other.day == day){
if(timeSlot < other.timeSlot){
return -1;
}
else{
return 1;
}
}
else{
String days = "SMTWF";
int ind1 = days.indexOf(day);
int ind2 = days.indexOf(other.day);
if(ind1 < ind2){
return -1;
}
else{
return 1;
}
}
}
}
      
      
  
  
   public void setTimeSlot(char newSlot){
       int count = 1;
       while (count !=0){
           if ((newSlot < 1) || (newSlot > 9)){
               System.out.println("Time Slot must be between 1-9");
           }
           else {
               this.timeSlot = newSlot;
               count = 0;
           }
       }
      
      
   }

}

Explanation / Answer

I hope this will help:

public Period getPeriod() {
   Period p=new Period(day,timeSlot);
   return p;
}