I did not make my instructions clear when I asked for help on this exer earlier
ID: 3543480 • Letter: I
Question
I did not make my instructions clear when I asked for help on this exer earlier this evening:
The CollegeCourse "display()" method output should look like: For the course ict362 with 3 credits your cost will be $360.00
For the LabCourse, the "display()" method output should look like: The course bio241 is a lab with a $50.00 lab fee. With 3 credits your total cost will be $410.00
I can't seen to get my code right: Pls Help
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
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);
}
}
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//
}
}
Explanation / Answer
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
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("The course "+department+number+" is a lab with a $50.00"
+" with " + credits + " credits your total cost will be $"+fee);
}
}
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 */
double 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("For the course "+department+number+" with "+credits+" credits your cost will be $"+fee);
}//End of display//
}//End of class//
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.