• Create a class named student. Add new data fields that are String name, String student_ID and double num_of_subject. This class will store the information from the main class using set and get method.
• Create a class named Fee. This class will calculate the fees for a particular student. The fee for per subject is RM250. The calculation is fee = num_of_subject x 250.
• Create a main class which will ask the user to enter the following data: student Name, student ID and number of subject taken for particular semester using Scanner technique. This program must be able to display back all the data entered by the user and student fee.
public String toString() { return "Student "+name+"|| Student Id: "+student_ID+ "|| Number of subject: "+num_of_subject+". Student fee: "+f.calc(num_of_subject)+"."; } }
// Main.java import java.util.Scanner;
public class Main {
public static void main(String[] args) { Scanner in = new Scanner(System.in); String name; String student_id; double num_of_subject; while (true) { System.out.println("Enter name of student"); name = in.next(); System.out.println("Enter id of student"); student_id = in.next(); System.out.println("Enter number of subject"); num_of_subject = in.nextInt(); Student student = new Student(name, student_id, num_of_subject);
System.out.println("To see information of student - enter '1'"); System.out.println("Continue - enter '0'"); int enter = in.nextInt();
Comments
Leave a comment