Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Java
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());
                }
            }
        }
    }
}
    }
}
Posted
Updated 2-Nov-20 1:13am
v2
Comments
Richard MacCutchan 2-Nov-20 7:14am    
You need to extract the fee from each course entry that the student enrols in, and add them to a total. Once you have processed each course you print the total cost.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900