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

Create a class named CollegeCourse that includes data fields that hold the depar

ID: 3673681 • Letter: C

Question

Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Also create a program that displays the course data. Use Constructors. Save the files as CollegeCourse.java

Explanation / Answer

PROGRAM:

import java.io.*;
import java.util.Scanner;
public class CollegeCourse {
String department;
int courseNumber;
int credits;
double fee;
CollegeCourse(String department,
int courseNumber,
int credits)
{
this.department=department;
this.courseNumber=courseNumber;
this.credits=credits;
}
double getFee()
{
fee=120*this.credits;
return fee;
}
void display()
{
System.out.println(department+" "+courseNumber+" "+credits+" "+getFee());
}
public static void main(String []args)throws IOException
{
System.out.println("Enter how many courses you to enter:");
Scanner scan=new Scanner(System.in);
int size=scan.nextInt();
CollegeCourse []c=new CollegeCourse[size];
for(int i=0;i<size;i++)
{
System.out.println("Enter Course:");
String course=scan.next();
System.out.println("Enter CourseNumber:");
int courseNO=scan.nextInt();
System.out.println("Enter Credits:");
int credits=scan.nextInt();
c[i]=new CollegeCourse(course,courseNO,credits);
}
for(int i=0;i<size;i++)
{
c[i].display();
}
}
}
  
}

OUTPUT:

run:
Enter how many courses you to enter:
4
Enter Course:
ENG
Enter CourseNumber:
0125
Enter Credits:
3
Enter Course:
EEE
Enter CourseNumber:
0126
Enter Credits:
4
Enter Course:
CSE
Enter CourseNumber:
0127
Enter Credits:
5
Enter Course:
IT
Enter CourseNumber:
0128
Enter Credits:
6
ENG 125 3 360.0
EEE 126 4 480.0
CSE 127 5 600.0
IT 128 6 720.0
BUILD SUCCESSFUL (total time: 1 minute 1 second)

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