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

You are to develop a .txt file of the code below (in the format you determine be

ID: 3576222 • Letter: Y

Question

You are to develop a .txt file of the code below (in the format you determine best for your program). Name your file: CourseListing.txt.

You are to revise the following code:

/*
You are to revise/complete the code below as per the comments below
*/

import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.File;
import java.io.FileReader;

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

Scanner keyboard = new Scanner(System.in);   

Scanner inputStream = null;
try
{
inputStream = new Scanner(new FileReader("courseListing.txt"));
}//end try

catch(FileNotFoundException e)
{
System.out.println("File not found, program will close.");
System.exit(0);
}//end catch

/*
//YOUR CODE MUST READ INFORMATION FROM A FILE AND CREATE AND
//POPULATE AN ARRAY (which must be named mySchedule
//OF INSTANCES OF THE CLASS COURSE
//THE FORMAT OF THE FILE WHICH MUST BE NAMED
//courseListing.txt (and be provided with your submission)
//IS UP TO YOU TO DESIGN THE FORMAT OF THE FILE courseListing.txt
//WHICH WILL DETERMINE HOW YOU DESIGN YOUR PROGRAM
//SO THE CODE ABOVE WILL TAKE THE PLACE OF THE CODE BELOW


Course mySchedule[] = { new Course("Adv Java", "CTIM168", 13, 444),
new Course("App Design", "CTIM139", 333, 41),
new Course("Intro C++", "CTIM371", 23, 478),
new Course("Security", "CTIM180", 31, 3),
new Course("Python", "CTIM285", 3, 14)};
  

*/
int selection, position, keyInt;
String keyString;
  
printMySchedule(mySchedule);

do
{
System.out.println("Enter your selection:");
System.out.println("Enter 1 to list your schedule:");
System.out.println("Enter 2 to sort my name:");
System.out.println("Enter 3 to sort by ID:");
System.out.println("Enter 4 to sort by credits:");
System.out.println("Enter 5 to sort by contact hours:");
System.out.println("Enter 6 to search my name:");
System.out.println("Enter 7 to search by ID:");
System.out.println("Enter 8 to search by credits:");
System.out.println("Enter 9 to search by contact hours:");
System.out.println("Enter 0 to exit:");
selection = keyboard.nextInt();

switch(selection)
{
case 0:
System.out.println("Thank you for using Schedule Finder.");
break;
case 1:
printMySchedule(mySchedule);
break;
case 2:
sortByCourseName(mySchedule);
break;
case 3:
sortByDeptID(mySchedule);
break;   
case 4:
sortByCreditHours(mySchedule);
break;
case 5:
sortByContactHours(mySchedule);
break;
case 6:
sortByCourseName(mySchedule);   
System.out.println("Please enter the name to search for: ");
keyString = keyboard.nextLine();
position = binarySearchCourseName(mySchedule, 0, mySchedule.length, keyString);
if(position < 0)
{
System.out.println("Course with that name was not found.");
break;
}
else
{
System.out.println(mySchedule[position].toString());
break;
}
case 7:
sortByDeptID(mySchedule);   
System.out.println("Please enter the Dept ID to search for: ");
keyString = keyboard.nextLine();
position = binarySearchDeptID(mySchedule, 0, mySchedule.length, keyString);
if(position < 0)
{
System.out.println("Course with that Dept ID was not found.");
break;
}
else
{
System.out.println(mySchedule[position].toString());
break;
}
case 8:
sortByCreditHours(mySchedule);   
//int key;
System.out.println("Please enter the credit hours to search for: ");
keyInt = keyboard.nextInt();
position = binarySearchCreditHours(mySchedule, 0, mySchedule.length, keyInt);
if(position < 0)
{
System.out.println("Course with that number of credit hours was not found.");
break;
}
else
{
System.out.println(mySchedule[position].toString());
break;
}
case 9:
sortByContactHours(mySchedule);   
System.out.println("Please enter the contact hours to searh for: ");
keyInt = keyboard.nextInt();
position = binarySearchContactHours(mySchedule, 0, mySchedule.length, keyInt);
if(position < 0)
{
System.out.println("Course with that number of contact hours was not found.");
break;
}
else
{
System.out.println(mySchedule[position].toString());
break;
}
default:
System.out.println("Entered invalid number, must be 0 - 9.");
break;   
}//end switch

}while(selection != 0);//end loop
}//end main


//////SEARCHING METHODS

public static int binarySearchDeptID
(Course[] sortedArrayPassed, int first, int upto, String key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key.compareTo(sortedArrayPassed[mid].getDeptID()) < 0)
{
upto = mid;
}//end if
else if(key.compareTo(sortedArrayPassed[mid].getDeptID()) > 0)
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method


public static int binarySearchCourseName
(Course[] sortedArrayPassed, int first, int upto, String key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key.compareTo(sortedArrayPassed[mid].getCourseName()) < 0)
{
upto = mid;
}//end if
else if(key.compareTo(sortedArrayPassed[mid].getCourseName()) > 0)
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours

/**
Method binarySearchContactHours assumes that array passed has
been sorted by contactHours before passing to method
*/

public static int binarySearchCreditHours
(Course[] sortedArrayPassed, int first, int upto, int key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key < sortedArrayPassed[mid].getNumCredits())
{
upto = mid;
}//end if
else if(key > sortedArrayPassed[mid].getNumCredits())
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours

/**
Method binarySearchContactHours assumes that array passed has
been sorted by contactHours before passing to method
*/

public static int binarySearchContactHours
(Course[] sortedArrayPassed, int first, int upto, int key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key < sortedArrayPassed[mid].getNumContactHoursPerWeek())
{
upto = mid;
}//end if
else if(key > sortedArrayPassed[mid].getNumContactHoursPerWeek())
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours


/////SORTING METHODS

public static void sortByCourseName(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;

for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getCourseName().compareTo
(arrayPassed[j + 1].getCourseName()) > 0)
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method

public static void sortByDeptID(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;

for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getDeptID().compareTo
(arrayPassed[j + 1].getDeptID()) > 0)
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method


public static void sortByContactHours(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;

for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getNumContactHoursPerWeek() >
arrayPassed[j + 1].getNumContactHoursPerWeek())
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method

public static void sortByCreditHours(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;

for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getNumCredits() > arrayPassed[j + 1].getNumCredits())
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method


public static void printMySchedule(Course[] mySchedulePassed)
{
for(int i = 0; i < mySchedulePassed.length; ++i)
{
System.out.println(mySchedulePassed[i].toString());
}
}//end method


public static void populateSchedule(Course[] mySchedulePassed)
{
for(int i = 0; i < mySchedulePassed.length; ++i)
{
mySchedulePassed[i] = new Course();
}
}//
}//end class

-----------------------

You don't need to revise the following code but it goes with the program:

import java.util.Scanner;

public class Course
{
//Scanner keyboard = new Scanner(System.in);

//instance variables
private String courseName;
private String deptID;
private int numCredits;
private int numContactHoursPerWeek;
//Scanner keyboard;

//constructors
//default constructor
public Course()
{
setCourseName("Not yet assigned");
setDeptID("Not yet assigned");
setNumCredits(0);
setNumContactHoursPerWeek(0);
}//end default constructor

//non-default constructor
public Course(String courseNamePassed, String deptIDPassed,
int numCreditsPassed, int numContactHoursPerWeekPassed)
{
setCourseName(courseNamePassed);
setDeptID(deptIDPassed);
setNumCredits(numCreditsPassed);
setNumContactHoursPerWeek(numContactHoursPerWeekPassed);
}//end default constructor

//getters
public String getCourseName()
{
return this.courseName;
}//end getCourseName

public String getDeptID()
{
return this.deptID;
}//end getDeptID

public int getNumCredits()
{
return this.numCredits;
}//end getNumCredits

public int getNumContactHoursPerWeek()
{
return this.numContactHoursPerWeek;
}//end getNumContactHoursPerWeek

//setters
public void setCourseName(String courseNamePassed)
{
if(courseNamePassed.length() < 1 ||
(int)courseNamePassed.charAt(0) == 32)
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the course name:");
courseNamePassed = keyboard.nextLine();
}while(courseNamePassed.length() < 1 ||
(int)courseNamePassed.charAt(0) == 32 );
}//end if

this.courseName = courseNamePassed;   
}//end method setCourseName

public void setDeptID(String deptIDPassed)
{
if(deptIDPassed.length() < 1 ||
(int)deptIDPassed.charAt(0) == 32)
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the course ID:");
deptIDPassed = keyboard.nextLine();
}while(deptIDPassed.length() < 1 ||
(int)deptIDPassed.charAt(0) == 32 );
}//end if

this.deptID = deptIDPassed;   
}//end method setDeptID

public void setNumCredits(int numCreditsPassed)
{
if(numCreditsPassed < 0 )
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the number of credits:");
numCreditsPassed = keyboard.nextInt();
keyboard.nextLine();
}while(numCreditsPassed < 0);
}//end if

this.numCredits = numCreditsPassed;   
}//end method setNumCredits

public void setNumContactHoursPerWeek(int numContactHoursPerWeekPassed)
{
if(numContactHoursPerWeekPassed < 0 )
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the number of contact hour per week:");
numContactHoursPerWeekPassed = keyboard.nextInt();
keyboard.nextLine();
}while(numContactHoursPerWeekPassed < 0);
}//end if

this.numContactHoursPerWeek = numContactHoursPerWeekPassed;   
}//end method setNumContactHoursPerWeekPassed

public String toString()
{
return
"CourseName: " + courseName +
" Department ID: " + deptID +
" Number Of Credits: " + numCredits +
" Number Contact Hours Per Week: " + numContactHoursPerWeek + " ";
}//end method toString


public boolean equals(Course coursePassed)
{
return
this.courseName.equals(coursePassed.courseName)
&&
this.deptID.equals(coursePassed.deptID)
&&
this.numCredits == coursePassed.numCredits
&&
this.numContactHoursPerWeek == coursePassed.numContactHoursPerWeek;
}//end method

}//end class

Explanation / Answer

//this is courseListing.txt .records are space formatted.we can give any spaces between the phrases .if you want ,separated values in between the records put comma(,) between the phrases and change split method regex expression comma(,).i don,t revise total code if you want i revise and i will correct the code test it.

CourseListing.txt

AdvanceJava CTIM168 13 444
AppDesign CTIM139 333 41
IntroC++ CTIM371 23 478
Security CTIM180 31 3
Python CTIM285 3 14

import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class MCCSchedule_PopulateFromFile
{
   Course mySchedule[]=new Course[100];
   int count=0;
public static void main(String[] args) throws IOException
{
   try{
   MCCSchedule_PopulateFromFile popfile=new MCCSchedule_PopulateFromFile();
Scanner keyboard = new Scanner(System.in);   
try
{
File file=new File("D:\courseListing.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line=reader.readLine();
while(line!=null)
{

//this split method split the words based on any spaces between the words.if you want put comma(,) in between the quotes.if you put comma must and should in courseListing.txt the records fields are comma separated values
   String[] words=line.split("\s+");
       String coursename=words[0];
       String deptId=words[1];
   int numCredits=Integer.parseInt(words[2]);
   int numcontactperweek=Integer.parseInt(words[3]);
  
   Course course=new Course(coursename, deptId, numCredits, numcontactperweek);
   popfile.mySchedule[popfile.count]=course;
   popfile.count++;
  
   line=reader.readLine();
}

}//end try
catch(FileNotFoundException e)
{
System.out.println("File not found, program will close.");
System.exit(0);
}//end catch
/*
//YOUR CODE MUST READ INFORMATION FROM A FILE AND CREATE AND
//POPULATE AN ARRAY (which must be named mySchedule
//OF INSTANCES OF THE CLASS COURSE
//THE FORMAT OF THE FILE WHICH MUST BE NAMED
//courseListing.txt (and be provided with your submission)
//IS UP TO YOU TO DESIGN THE FORMAT OF THE FILE courseListing.txt
//WHICH WILL DETERMINE HOW YOU DESIGN YOUR PROGRAM
//SO THE CODE ABOVE WILL TAKE THE PLACE OF THE CODE BELOW
*/


/*Course mySchedule[] = { new Course("Adv Java", "CTIM168", 13, 444),
new Course("App Design", "CTIM139", 333, 41),
new Course("Intro C++", "CTIM371", 23, 478),
new Course("Security", "CTIM180", 31, 3),
new Course("Python", "CTIM285", 3, 14)};
*/

System.out.println("enter your selection");
System.out.println("Enter your selection:");
System.out.println("Enter 1 to list your schedule:");
System.out.println("Enter 2 to sort my name:");
System.out.println("Enter 3 to sort by ID:");
System.out.println("Enter 4 to sort by credits:");
System.out.println("Enter 5 to sort by contact hours:");
System.out.println("Enter 6 to search my name:");
System.out.println("Enter 7 to search by ID:");
System.out.println("Enter 8 to search by credits:");
System.out.println("Enter 9 to search by contact hours:");
System.out.println("Enter 0 to exit:");

int selection=keyboard.nextInt();
int position=0, keyInt=0;
String keyString=null;
  
//printMySchedule(popfile.mySchedule);


switch(selection)
{
case 0:
System.out.println("Thank you for using Schedule Finder.");
break;
case 1:
printMySchedule(popfile.mySchedule);
break;
case 2:
sortByCourseName(popfile.mySchedule);
break;
case 3:
sortByDeptID(popfile.mySchedule);
break;   
case 4:
sortByCreditHours(popfile.mySchedule);
break;
case 5:
sortByContactHours(popfile.mySchedule);
break;
case 6:
sortByCourseName(popfile.mySchedule);   
System.out.println("Please enter the name to search for: ");
keyString = keyboard.nextLine();
position = binarySearchCourseName(popfile.mySchedule, 0, popfile.mySchedule.length, keyString);
if(position < 0)
{
System.out.println("Course with that name was not found.");
break;
}
else
{
System.out.println(popfile.mySchedule[position].toString());
break;
}
case 7:
sortByDeptID(popfile.mySchedule);   
System.out.println("Please enter the Dept ID to search for: ");
keyString = keyboard.nextLine();
position = binarySearchDeptID(popfile.mySchedule, 0, popfile.mySchedule.length, keyString);
if(position < 0)
{
System.out.println("Course with that Dept ID was not found.");
break;
}
else
{
System.out.println(popfile.mySchedule[position].toString());
break;
}
case 8:
sortByCreditHours(popfile.mySchedule);   
//int key;
System.out.println("Please enter the credit hours to search for: ");
keyInt = keyboard.nextInt();
position = binarySearchCreditHours(popfile.mySchedule, 0,popfile. mySchedule.length, keyInt);
if(position < 0)
{
System.out.println("Course with that number of credit hours was not found.");
break;
}
else
{
System.out.println(popfile.mySchedule[position].toString());
break;
}
case 9:
sortByContactHours(popfile.mySchedule);   
System.out.println("Please enter the contact hours to searh for: ");
keyInt = keyboard.nextInt();
position = binarySearchContactHours(popfile.mySchedule, 0,popfile. mySchedule.length, keyInt);
if(position < 0)
{
System.out.println("Course with that number of contact hours was not found.");
break;
}
else
{
System.out.println(popfile.mySchedule[position].toString());
break;
}
default:
System.out.println("Entered invalid number, must be 0 - 9.");
break;   
}//end switch
   }catch(Exception e)
   {
       System.out.println("the operations are aborted");
   }
}//end main

//////SEARCHING METHODS
public static int binarySearchDeptID
(Course[] sortedArrayPassed, int first, int upto, String key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key.compareTo(sortedArrayPassed[mid].getDeptID()) < 0)
{
upto = mid;
}//end if
else if(key.compareTo(sortedArrayPassed[mid].getDeptID()) > 0)
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method

public static int binarySearchCourseName
(Course[] sortedArrayPassed, int first, int upto, String key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key.compareTo(sortedArrayPassed[mid].getCourseName()) < 0)
{
upto = mid;
}//end if
else if(key.compareTo(sortedArrayPassed[mid].getCourseName()) > 0)
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours
/**
Method binarySearchContactHours assumes that array passed has
been sorted by contactHours before passing to method
*/
public static int binarySearchCreditHours
(Course[] sortedArrayPassed, int first, int upto, int key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key < sortedArrayPassed[mid].getNumCredits())
{
upto = mid;
}//end if
else if(key > sortedArrayPassed[mid].getNumCredits())
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours
/**
Method binarySearchContactHours assumes that array passed has
been sorted by contactHours before passing to method
*/
public static int binarySearchContactHours
(Course[] sortedArrayPassed, int first, int upto, int key)
{
while(first < upto)
{
int mid = (first + upto)/2;
if(key < sortedArrayPassed[mid].getNumContactHoursPerWeek())
{
upto = mid;
}//end if
else if(key > sortedArrayPassed[mid].getNumContactHoursPerWeek())
{
first = mid + 1;
}//end if
else //found it
{
return mid;
}//end else
}//end while
return -1;
}//end method binarySearchContactHours

/////SORTING METHODS
public static void sortByCourseName(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;
for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getCourseName().compareTo
(arrayPassed[j + 1].getCourseName()) > 0)
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method
public static void sortByDeptID(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;
for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getDeptID().compareTo
(arrayPassed[j + 1].getDeptID()) > 0)
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method

public static void sortByContactHours(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;
for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getNumContactHoursPerWeek() >
arrayPassed[j + 1].getNumContactHoursPerWeek())
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method
public static void sortByCreditHours(Course[] arrayPassed)
{
int n = arrayPassed.length;
Course temp;
for(int i = 1; i < n; ++i)
{
for(int j = 0; j < n - i; ++j)
{
if(arrayPassed[j].getNumCredits() > arrayPassed[j + 1].getNumCredits())
{
temp = arrayPassed[j];
arrayPassed[j] = arrayPassed[j + 1];
arrayPassed[j + 1] = temp;
}//end if
}//end inner loop
}//end outer loop
}//end method

public static void printMySchedule(Course[] mySchedulePassed)
{
for(int i = 0; i < mySchedulePassed.length; ++i)
{
System.out.println(mySchedulePassed[i].toString());
}
}//end method

public static void populateSchedule(Course[] mySchedulePassed)
{
for(int i = 0; i < mySchedulePassed.length; ++i)
{
mySchedulePassed[i] = new Course();
}
}//
}//end class

----------------------------------

import java.util.Scanner;
public class Course
{
//Scanner keyboard = new Scanner(System.in);
//instance variables
private String courseName;
private String deptID;
private int numCredits;
private int numContactHoursPerWeek;
//Scanner keyboard;
//constructors
//default constructor
public Course()
{
setCourseName("Not yet assigned");
setDeptID("Not yet assigned");
setNumCredits(0);
setNumContactHoursPerWeek(0);
}//end default constructor
//non-default constructor
public Course(String courseNamePassed, String deptIDPassed,
int numCreditsPassed, int numContactHoursPerWeekPassed)
{
setCourseName(courseNamePassed);
setDeptID(deptIDPassed);
setNumCredits(numCreditsPassed);
setNumContactHoursPerWeek(numContactHoursPerWeekPassed);
}//end default constructor
//getters
public String getCourseName()
{
return this.courseName;
}//end getCourseName
public String getDeptID()
{
return this.deptID;
}//end getDeptID
public int getNumCredits()
{
return this.numCredits;
}//end getNumCredits
public int getNumContactHoursPerWeek()
{
return this.numContactHoursPerWeek;
}//end getNumContactHoursPerWeek
//setters
public void setCourseName(String courseNamePassed)
{
if(courseNamePassed.length() < 1 ||
(int)courseNamePassed.charAt(0) == 32)
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the course name:");
courseNamePassed = keyboard.nextLine();
}while(courseNamePassed.length() < 1 ||
(int)courseNamePassed.charAt(0) == 32 );
}//end if

this.courseName = courseNamePassed;   
}//end method setCourseName
public void setDeptID(String deptIDPassed)
{
if(deptIDPassed.length() < 1 ||
(int)deptIDPassed.charAt(0) == 32)
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the course ID:");
deptIDPassed = keyboard.nextLine();
}while(deptIDPassed.length() < 1 ||
(int)deptIDPassed.charAt(0) == 32 );
}//end if

this.deptID = deptIDPassed;   
}//end method setDeptID
public void setNumCredits(int numCreditsPassed)
{
if(numCreditsPassed < 0 )
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the number of credits:");
numCreditsPassed = keyboard.nextInt();
keyboard.nextLine();
}while(numCreditsPassed < 0);
}//end if

this.numCredits = numCreditsPassed;   
}//end method setNumCredits
public void setNumContactHoursPerWeek(int numContactHoursPerWeekPassed)
{
if(numContactHoursPerWeekPassed < 0 )
{
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println("Enter the number of contact hour per week:");
numContactHoursPerWeekPassed = keyboard.nextInt();
keyboard.nextLine();
}while(numContactHoursPerWeekPassed < 0);
}//end if

this.numContactHoursPerWeek = numContactHoursPerWeekPassed;   
}//end method setNumContactHoursPerWeekPassed
public String toString()
{
return
"CourseName: " + courseName +
" Department ID: " + deptID +
" Number Of Credits: " + numCredits +
" Number Contact Hours Per Week: " + numContactHoursPerWeek + " ";
}//end method toString

public boolean equals(Course coursePassed)
{
return
this.courseName.equals(coursePassed.courseName)
&&
this.deptID.equals(coursePassed.deptID)
&&
this.numCredits == coursePassed.numCredits
&&
this.numContactHoursPerWeek == coursePassed.numContactHoursPerWeek;
}//end method
}//end class

output

Enter your selection:
Enter 1 to list your schedule:
Enter 2 to sort my name:
Enter 3 to sort by ID:
Enter 4 to sort by credits:
Enter 5 to sort by contact hours:
Enter 6 to search my name:
Enter 7 to search by ID:
Enter 8 to search by credits:
Enter 9 to search by contact hours:
Enter 0 to exit:
1
CourseName: AdvanceJava
Department ID: CTIM168
Number Of Credits: 13
Number Contact Hours Per Week: 444

CourseName: AppDesign
Department ID: CTIM139
Number Of Credits: 333
Number Contact Hours Per Week: 41

CourseName: IntroC++
Department ID: CTIM371
Number Of Credits: 23
Number Contact Hours Per Week: 478

CourseName: Security
Department ID: CTIM180
Number Of Credits: 31
Number Contact Hours Per Week: 3

CourseName: Python
Department ID: CTIM285
Number Of Credits: 3
Number Contact Hours Per Week: 14

the operations are aborted

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote