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

An online institute would like you to develop a Java program to determine the ch

ID: 3641915 • Letter: A

Question

An online institute would like you to develop a Java program to determine the charge
payable by its students. A student may enroll in one or more courses. The following are
the fees charged to the students based on the types of courses taken: .



Course Type
Electrical Eng. (E)
Mechanical Eng. (M)
Petroleum Eng. (P)
ICT(I)


Fees Per Course
850.50
895.00
210.00
132.75



Your job is to write a program to read in a student's id (integer). After entering the id for
a student, your program should read in the course type (single character) followed by the
number of courses of that course type. The student might be enrolled in more than one
course type. Your program should therefore ask if there are any more inputs for this
student. If the response is Y (for Yes), then your procedure should ask for the name of the
next course type followed by the number of courses taken in that course type. This
process should continue until the response is N, indicating that there are no more courses
that the student is enrolled in.

After processing all the inputs for a given student, your procedure should output the student's id along with the total amount payable.
After processing all the data for one student, your program should ask if there are any
more students to be processed. Continue the above process as long as the response to this
question is Y.
Your program should validate all responses to questions as well as the course type.

Explanation / Answer

import java.io.*;
import java.util.Scanner;
import java.util.*;
class CourseType
{
private char ct;
private int n;
private double fee;
public void setdata(char ctype,int num)
{
ct=ctype;
n=num;
if(ct=='M') fee=850.50;
else if(ct=='E') fee=895.00;
else if(ct=='P') fee=210.00;
else if(ct=='I') fee=132.75;
else System.out.println("enter valid course type character");
}
public char getCtype(){ return ct; }
public int getNum(){ return n; }
public double getFee(){ return fee; }


};
class Student
{
private String id;
private ArrayList ccc=new ArrayList();
int n;
public Student()
{
n=0;
}
public void setdata(CourseType c1, String id1)
{
ccc.add(c1);
id=id1;

n++;
}
public void display()
{
System.out.println("student id is :"+id);
double sum=0;
CourseType x;

for(int i=0;i {
x=ccc.get(i);
sum=sum+(double)(x.getNum()*x.getFee());
}

System.out.println("amount paid by the student is "+sum);
}

};

public class Course {

public static void main(String args[]) throws IOException
{

char ch1='n',ch2='n';
String id;
char ct;
int n=0;
int i=0;
Scanner sc=new Scanner(System.in);
BufferedInputStream bin=new BufferedInputStream(System.in);

do
{
Student st=new Student();
System.out.println("enter student id ");
id=sc.nextLine();

do
{
CourseType c1=new CourseType();
System.out.println("enter course type 'M' or 'E' or 'P' or 'I'");

ct=(char)bin.read();
bin.skip(1);

System.out.println("enter no of courses joined in the course type");

n=sc.nextInt();
sc.skip("[ ]");

c1.setdata(ct, n);

st.setdata(c1,id);
System.out.println("do you want to enter another course for same studnet press 'y' or 'n'");

ch1=(char)bin.read();
bin.skip(1);

}while(ch1=='y');


st.display();
System.out.println("do you want to continue for another studnet then press 'y' or 'n'");

ch2=(char)bin.read();
bin.skip(1);

i++;
}while(ch2=='y' || ch2=='Y');
}

}