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

Can anyone out there help me out and tell me why I keep getting four (4) errors

ID: 3542935 • Letter: C

Question

Can anyone out there help me out and tell me why I keep getting four (4) errors when I run my code:

/*
*  Your Header info here!!
*/

import java.util.*;
public class UseCourse {

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
        
        String labCourses = "BIO CHM CIS PHY";
        System.out.println("Please enter the course department");
        String department = input.next();
        System.out.println("Please enter the courseNumber:");
        int courseNumber = input.nextInt();
        System.out.println("Please enter the number of credits:");
        int credits = input.nextInt();
        
        if(labCourses.indexOf(department.toUpperCase())>=0){
            LabCourse course = new LabCourse(department,courseNumber,credits);
            course.display();
        } else {
            CollegeCourse course = new CollegeCourse(department,courseNumber,credits);
            course.display();
        } // end if

    } //  end main method
    
}  //end class UseCourse
class CollegeCourse {
    //class CollegeCourse code here
    /* creating class. */
    public class CollegeCourse
{
    /* variable to hold department of course */
    String department;
    /* variable to hold number of course */
    int number;
    /* variable to hold credits of course */
    int credits;
    /* variable to hold fee of course */
    int fee;
    
    /* constructor for CollegeCourse class accepting arguments */
    public CollegeCourse(String department, int number, int credits)
    {
    /* assigning values to fields */
    this.department = department;
    this.number = number;
    this.credits = credits;
    this.fee = credits * 120;
    /* end of the constructor */
    }
    }
    /* creating class. */
    public class LabCourse extends CollegeCourse
    {
    /* constructor for LabCourse class */
    public LabCourse(String department, int number, int credits)
    {
    super(department, number, credits);/* calling the super constructor with arguments */
    fee = fee + 50;/* adding 50$ to fee */
    }/* end of the constructor */
    
    /* display method to display all fields */
    public void display()
    {
    System.out.println("This course contains lab");
    System.out.println("department: " + department);
    System.out.println("number: " + number);
    System.out.println("credits: " + credits);
    
    /* display method to display all fields */
    public void display()
    {
    
    System.out.println("This course does not contain lab");
    System.out.println("department: " + department);
    System.out.println("number: " + number);
    System.out.println("credits: " + credits);
    System.out.println("fee: " + fee);
    
//End of display//
//End of class//
}
}


Explanation / Answer

Hi ,

In your classes, some methods are copied twice accidentally.

Please use the properly formatted classes like these...

They are separated into 3 files Usecourse.java, LabCourse.java and CollegeCourse.java.


Hope it Helps :)



In the file UseCourse.java



import java.util.Scanner;



public class UseCourse {


public static void main(String[] args) {

Scanner input = new Scanner(System.in);


String labCourses = "BIO CHM CIS PHY";

System.out.println("Please enter the course department");

String department = input.next();

System.out.println("Please enter the courseNumber:");

int courseNumber = input.nextInt();

System.out.println("Please enter the number of credits:");

int credits = input.nextInt();


if(labCourses.indexOf(department.toUpperCase())>=0){

LabCourse course = new LabCourse(department,courseNumber,credits);

course.display();

} else {

CollegeCourse course = new CollegeCourse(department,courseNumber,credits);

course.display();

} // end if


} // end main method


} //end class UseCourse




Similarly, in the course LabCourse.java



public class LabCourse extends CollegeCourse

{

/* constructor for LabCourse class */

public LabCourse(String department, int number, int credits)

{

super(department, number, credits);/* calling the super constructor with arguments */

fee = fee + 50;/* adding 50$ to fee */

}/* end of the constructor */


/* display method to display all fields */

public void display()

{

System.out.println("This course contains lab");

System.out.println("department: " + department);

System.out.println("number: " + number);

System.out.println("credits: " + credits);

}

}



And finally , in the CollegeCourse.java file,


public class CollegeCourse

{

/* variable to hold department of course */

String department;

/* variable to hold number of course */

int number;

/* variable to hold credits of course */

int credits;

/* variable to hold fee of course */

int fee;


/* constructor for CollegeCourse class accepting arguments */

public CollegeCourse(String department, int number, int credits)

{

/* assigning values to fields */

this.department = department;

this.number = number;

this.credits = credits;

this.fee = credits * 120;

/* end of the constructor */

}

public void display()

{


System.out.println("This course does not contain lab");

System.out.println("department: " + department);

System.out.println("number: " + number);

System.out.println("credits: " + credits);

System.out.println("fee: " + fee);


//End of display//

//End of class//

}


}