I am trying to get user to input course ID, match it with array list and display it's price. user can only enrol in 2 classes at max and if he wants to Enrol in 2 classes then the output should add both the prices and print total.
below the first array is student TOM with his studentID, name, and bunch of scores and grade. (Don't worry about the scores). the unit array (course ID, name, feeA, feeB). Only worry about feeA please don't worry about feeb. this is my code so far, not sure how to add price after user enrol. Any idea?
What I have tried:
import java.io.*;
import java.util.*;
public class course
{
public course()
{
}
public void courses() {
Scanner u = new Scanner(System.in);
List<student> Stu = new ArrayList<>();
Stu.add(new Student("u123","Tom", 48 , 52, 53, 48, 38, 47.5, "F"));
List<unit> units = new ArrayList<>();
units.add(new Unit(4483, "Maths", 1000, 1200));
units.add(new Unit(4485, "Biology", 1580, 1780));
units.add(new Unit(4486, "Informative Technology", 1580, 1780));
units.add(new Unit(4487, "Painting", 1580, 1780));
units.add(new Unit(4488, "History", 1000, 1200));
units.add(new Unit(4489, "Ecology", 1000, 1200));
units.add(new Unit(4473, "Accounting", 1000, 1200));
units.add(new Unit(4472, "Chief", 1580, 1780));
units.add(new Unit(4471, "Spanish", 1200, 1200));
System.out.print("\u000c");
System.out.print("How Many Units Would You Like To Enrol : *MAX 4* ");
int Num = u.nextInt();
if(Num <= 2){
for (int i = 0; i< Num; i++)
{
System.out.println("Enter the Unit Code Please");
int courseId = u.nextInt();
for(Student s : Stu){
for(Unit c : units){
if(c.getunitCode() == courseId){
System.out.println("Enrolled " + s.getStudentID() + " " + s.getName() + " Into " + c.getunitName());
}
}
}
}
}
}
}