Hi
Enclosed is my Java assignment which is due Tuesday, any help would be greatly appreciated.

Program Specification:
(1) Rather than having the trainee type in the full title of his Training Module, let him choose from a
menu: the choices should be: “Forward Scanning Radar Display Repair”, “IR Beacon
Maintenance” and “SAM Detection System Replacement”. I have not shown the menu output and
user input in the example. Your program should display a menu with these three choices.
(2) Allow more than one trainee’s marks to be entered, and then print the results for each trainee at the
end of the program, rather than after each trainee’s marks have been entered.
(3) Terminate entry by entering a special code.
(4) Do not allow marks below 0, or above 100, to be entered.

Program Specification which I am having difficulty with is:
***
(2) Allow more than one trainee’s marks to be entered, and then print the results for each trainee at the
end of the program, rather than after each trainee’s marks have been entered.***

An example run would be:

Trainee Number: 5827
Family Name: Thaksin
First Name: Parvit
[Instruction Module chosen from menu: chooses Forward Scanning Radar Display]
How many quizes shall I calculate?: 3
Module Quiz mark 1: 68
Module Quiz mark 2: 76
Module Quiz mark 3: 87
Final Module Test mark: 77
Another [Y/N]: Y

Trainee Number: 6202
Family Name: Lundberg
First Name: Claes
[Instruction Module chosen from menu: chooses IR Beacon Maintenance]
How many quizes shall I calculate?: 5
Module Quiz mark 1: 64
Module Quiz mark 2: 72
Module Quiz mark 3: 76
Module Quiz mark 4: 68
Module Quiz mark 5: 84
Final Module Test mark: 62
Another [Y/N]: N

And output:

Results for Parvit Thaksin
Trainee Number 5827
Module: Forward-Scanning Radar Display Repair
Average Module Quiz: 70.3 Final Module Test: 77 Overall Mark: 75.7
Letter Grade: A

Results for Claes Lundberg
Trainee Number 6202
Module: IR Beacon Maintenance
Average Module Quiz: 72.8 Final Module Test: 62 Overall Mark: 64.0
Letter Grade: B

Also checking that entry for a trainee coursework marks for a coursework already entered, but should be tested for.

My Code is as follows and I am having difficulty start the Array - ArrayList may be the way to go, any feedback or help would be greatly appreciated:

// Assignment 2 - 2910109--CW01 - 2010/2011
import java.util.*;
class MilitaryArrays{
    public static void main(String[] args){
    Scanner input = new Scanner(System.in);

    String exit ="-999", firstName, familyName;
    int traineeNum, instModule,quizesNo;
    double totalMarks, moduleTest;
    char reply;

    System.out.println( "********* MILITARY TRAINING ORGANISATION STUDENT SYSTEM *********" );
    displayMenu();

do{

    System.out.print( "Trainee Number: ");
    traineeNum = input.nextInt();
    input.nextLine();
    exitSystemInts(traineeNum);             // Call method exitSystemInts.

    System.out.print( "Family Name: ");
    familyName = input.nextLine();
    exitSystemStrings(familyName, exit);    // Call method exitSystemString.

    System.out.print( "First Name: ");
    firstName = input.nextLine();
    exitSystemStrings(firstName, exit);     // Call method exitSystemString.

    displayMenu();

    System.out.print( "Instruction Module: ");
    instModule = input.nextInt();
    exitSystemInts(instModule);             // Call method exitSystemInts.

    System.out.print( "How many quizes shall I calculate?: ");
    quizesNo = input.nextInt(); // 15.)
    exitSystemInts(quizesNo);               // Call method exitSystemInts.

    totalMarks = 0;
    for(int counter = 1; counter < quizesNo + 1; counter++){
        System.out.print( "Module Quiz mark " + counter + ": ");
        double mark = input.nextDouble();
        exitSystemDouble(mark);             // Call method exitSystemDouble.

        while(mark < 0 || mark > 100){       // Test Marks Input (0-100).
            displayErrorMarks();            // Call method displayErrorMarks.
            System.out.print( "Module Quiz mark " + counter + ": ");
            mark=input.nextDouble();
            exitSystemDouble(mark);         // Call method exitSystemDouble.
        }

        totalMarks = addTotalMarks(totalMarks,mark);    // Call method addTotalMarks.
    }
    System.out.print( "Final Module Test mark: ");
    moduleTest = input.nextDouble();
    exitSystemDouble(moduleTest);           // Call method exitSystemDouble.


    while(moduleTest < 0 || moduleTest > 100){ // Test Final Module Test Marks.
        displayErrorMarks();            // Call method displayErrorMarks.
        System.out.print( "Final Module Test mark: ");
        moduleTest=input.nextDouble();
        exitSystemDouble(moduleTest);           // Call method exitSystemDouble.
    }

    System.out.print( "Another [Y/N]: ");
    reply = input.next().charAt(0);
    System.out.println();

}while (reply == 'y' || reply == 'Y');

    // Print out results:
    System.out.println();
    System.out.println( "Results for " + firstName + " " + familyName );
    System.out.println( "Trainee Number " + traineeNum );
    System.out.print( "Module: " );

        switch (instModule){    //Menu A
            case 1:
                System.out.println( "Forward Scanning Radar Display Repair" );
                break;
            case 2:
                System.out.println( "IR Beacon Maintenance" );
                break;
            case 3:
                System.out.println( "SAM Detection System Replacement" );
                break;
        }                       //Menu A

    double avgMark = totalMarks / quizesNo; // .)
    System.out.print( "Average Module Quiz: " + Math.round(avgMark*10.0)/10.0 + " ");
    System.out.print( "Final Module Test: " + Math.round(moduleTest*10.0)/10.0 + " ");
    double overMark = (avgMark * .2)+(moduleTest * .8);
    System.out.println( "Overall Mark: " + Math.round(overMark*10.0)/10.0);

    if(overMark >=70){
            System.out.print( "Letter Grade: A" );
        }else if (overMark >=60 && overMark <70){
            System.out.print( "Letter Grade: B" );
        }else if (overMark >=50 && overMark <60){
            System.out.print( "Letter Grade: C" );
        }else if (overMark >=40 && overMark <50){
            System.out.print( "Letter Grade: D" );
        }else if (overMark >=35 && overMark <40){
            System.out.println( "Letter Grade: E" );
        }else{
            System.out.println( "Letter Grade: ");
        }
        System.out.println("");

    }

    private static void displayMenu(){
        Scanner input = new Scanner(System.in);
        System.out.println();
        System.out.println( "tEnter Instruction Module Number ONLY" );
        System.out.println();
        System.out.println( "tCode No: 1 - Forward Scanning Radar Display Repair" );
        System.out.println( "tCode No: 2 - IR Beacon Maintenance" );
        System.out.println( "tCode No: 3 - SAM Detection System Replacement" );
        System.out.println( "tCode No: -999 - Termnate/Exit System" );
        System.out.println();
        System.out.println( "*****************************************************************" );
        System.out.println( "" );
    }

    private static double addTotalMarks(double totalMarks, double mark){
        return totalMarks + mark;
    }

    private static void exitSystemInts(int exitInt){
        if (exitInt == -999){
            System.out.println();
            System.out.println( "        *************************************************        " );
            System.out.println( "t    You have chosen to TERMINATE/EXIT system" );
            System.out.println( "        *************************************************        " );
            System.out.println();
            System.exit(0);
        }
    }

    private static void exitSystemStrings(String stringInput, String exitString){
        exitString ="-999";
        if (stringInput.equals(exitString)){
            System.out.println();
            System.out.println( "        *************************************************        " );
            System.out.println( "t    You have chosen to TERMINATE/EXIT system" );
            System.out.println( "        *************************************************        " );
            System.out.println();
            System.exit(0);
        }
    }

    private static void exitSystemDouble(double exitDouble){
        if (exitDouble == -999){
            System.out.println();
            System.out.println( "        *************************************************        " );
            System.out.println( "t    You have chosen to TERMINATE/EXIT system" );
            System.out.println( "        *************************************************        " );
            System.out.println();
            System.exit(0);
        }
    }

    private static void displayErrorMarks(){
            System.out.println( "        **********************ERROR**********************        " );
            System.out.println( "tMarks must not be LESS than 0 or HIGHER than 100!" );
            System.out.println( "        *************************************************        " );
    }

} //END OF MAIN METHOD.
Member Avatar for ztini

ArrayList is definitely the way to go b/c you don't know how many trainees the user is going to enter.

You could create a Trainee class that contains name and id. Then you could invoke an ArrayList like this:

ArrayList<Trainee> traineeList = new ArrayList<Trainee>();
...
// then from your application you gather input which you could
// pass like this:
Scanner in = new Scanner(System.in);
System.out.println("Last name");
String lastName = in.next();
// etc
...
traineeList.add(new Trainee(lastName, firstName, id));

Trainee might look like this:

public class Trainee {

	private String lastName;
	private String firstName;
	private int id;
	
	public Trainee(String inLastName, String inFirstName, int inId) {
		this.lastName = inLastName;
		this.firstName = inFirstName;
		this.id = inId;
	}
	
	public String getName() {
		return lastName + ", " + firstName;
	}
	
	public int getId() {
		return id;
	}
}

Hi
Thanks for you posting I solved my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.