Results 1 to 12 of 12
  1. #1
    doxycycline is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Exclamation need help with java project

    hi. this is an assignment for java.
    what im required to do is write a program to tabulate marks for trainees
    what is required is more or less already done.
    im only stuck with this part where it requires more than 1 trainee to enter the marks, then say if 2 trainees entered their marks, it should print out after they told the program to print.

    heres what i've done so far:

    Java Code:
    // section 1 - code below imports packages from both utilities package and math package
    import java.util.*;
    import java.math.*;
    class MarksTabulation
    {   public static void main ( String [] args)
        {   Scanner in = new Scanner(System.in);
            //section 2 - variable declarations
            char enterAnother = 'Y';
            int [] traineeNo = new int [20];
            // note for self - allow 20 trainees
            int keyedNumberOfQuiz = 0;
            double [] noOfQuiz; 
            double [] modTestMark = new double [20];
            double [] averageMark = new double [20];
            double [] overallMark = new double [20];
            String [] familyName = new String [20];
            String [] firstName = new String [20];
            String [] moduleName = new String [20];
            
            repeat:
            for (int noOfTrainees = 0; noOfTrainees < 20; noOfTrainees ++)
            {   //section 3 - prints prompts for user to key in input
                System.out.print("Trainee Number: ");
                traineeNo [noOfTrainees] = in.nextInt();
                //traineeNo limiter
                while (traineeNo [noOfTrainees] < 1000 || traineeNo [noOfTrainees] > 9999)
                {   System.out.print("Invalid Trainee Number. Please key in a valid Trainee number: ");
                    traineeNo [noOfTrainees] = in.nextInt();
                }
                //continuation of section 3
                System.out.print("Family Name: ");
                familyName [noOfTrainees] = in.next();
                System.out.print("First Name: ");
                firstName [noOfTrainees] = in.next();
                System.out.print("Instruction Module: \n 1. Forward Scanning Radar Display Repair\n 2. IR Beacon Maintenance\n 3. SAM Detection System Replacement\nEnter Module No.: ");
                int module = in.nextInt();
                while (module > 3 || module < 1)
                {   System.out.print("Invalid module number. Please key in a valid module number: ");
                    module = in.nextInt();
                } 
                switch (module)
                {   case 1: moduleName [noOfTrainees] = "Forward Scanning Radar Display Repair"; break;
                    case 2: moduleName [noOfTrainees] = "IR Beacon Maintenance"; break;
                    case 3: moduleName [noOfTrainees] = "SAM Detection System Replacement"; break;
                }    
                System.out.print("How many quizes shall I calculate?: ");
                keyedNumberOfQuiz = in.nextInt();
                //"number of quizzes" limiter
                while (keyedNumberOfQuiz < 1 || keyedNumberOfQuiz > 8)
                {   System.out.print("Invalid number of quizes. Please key in a valid number: ");
                    keyedNumberOfQuiz = in.nextInt();
                }
                //section 4 - create an array
                noOfQuiz = new double [keyedNumberOfQuiz];
        
                averageMark [noOfTrainees] = tabulateModuleMarks(noOfQuiz);        
                System.out.print("Final Module Test mark: ");
                modTestMark [noOfTrainees] = in.nextDouble();
                while (modTestMark [noOfTrainees] < 0 || modTestMark [noOfTrainees] > 100)
                {   System.out.print("Invalid Final Module score. Please key in a valid score: ");
                    modTestMark [noOfTrainees] = in.nextDouble();
                }
                overallMark [noOfTrainees] = getOverallMark(averageMark [noOfTrainees],modTestMark [noOfTrainees]);
                System.out.println("\n");
                averageMark [noOfTrainees] = roundingOff1Decimal(averageMark [noOfTrainees]);
                overallMark [noOfTrainees] = roundingOff1Decimal(overallMark [noOfTrainees]);
                
                System.out.print("Another [Y/N]: ");
                enterAnother = in.next().charAt(0);   
                if (enterAnother == 'N')
                {   break repeat;
                }
            }
           
            
            //section 5 - print results
            for (int noOfTrainees = 0; noOfTrainees < 20; noOfTrainees ++)
            {   printResults(traineeNo [noOfTrainees] ,firstName [noOfTrainees],familyName [noOfTrainees],moduleName [noOfTrainees],averageMark [noOfTrainees],modTestMark [noOfTrainees],overallMark [noOfTrainees]);
            }    
        }
        //section 6 - my own methods and their purposes
        static void printResults (int traineeNo, String familyName, String firstName, String moduleName, double averageMark, double modTestMark, double overallMark)
        {   System.out.println("Results for " + familyName + " " + firstName);
            System.out.println("Trainee Number" + " " + traineeNo);
            System.out.println("Module: " + moduleName);
            System.out.print("Average Module Quiz: " + averageMark + " ");
            System.out.print("Final Module Test: " + modTestMark + " ");
            System.out.println("Overall mark: " + overallMark + " ");
            
            if ( overallMark >= 70 )
            {   System.out.println("Letter Grade: A");
            }
            else if (overallMark >= 60 && overallMark < 70)
            {   System.out.println("Letter Grade: B");
            }
            else if (overallMark >= 50 && overallMark < 60)
            {   System.out.println("Letter Grade: C");
            }
            else if (overallMark >= 40 && overallMark < 50)
            {   System.out.println("Letter Grade: D");
            }
            else if (overallMark >= 35 && overallMark < 40)
            {   System.out.println("Letter Grade: E");   
            }
         }
        static double tabulateModuleMarks (double [] noOfQuiz)
        {   Scanner in = new Scanner(System.in);
            double sum = 0;
            for (int x = 0; x < noOfQuiz.length; x++)
            {   System.out.print("Module "+(x+1)+" Quiz Mark: ");
                noOfQuiz [x] = in.nextDouble();
                    while (noOfQuiz [x] < 0 || noOfQuiz [x] > 100)
                {   System.out.print("Invalid module " + (x+1) + " score. Please key in a valid score(1-100): ");
                    noOfQuiz [x] = in.nextDouble();
                }
                sum = sum + noOfQuiz [x];
            }
            return sum/(noOfQuiz.length);
        }
        static double getOverallMark (double averageMark, double modTestMark)
        {   double modQuizWeighting;
            double modTestWeighting;
            double overallMark;
            
            modQuizWeighting = averageMark/100 *20;
            modTestWeighting = modTestMark/100 *80;
            return (modQuizWeighting + modTestWeighting);
            
        } 
        static double roundingOff1Decimal (double decimal)
        {   decimal = decimal * 10;
            return Math.rint(decimal) / 10;
        }    
    }
    what is troubling me is when i try to print out the results, it shows null for string fields like names, and 0 for integer or double fields.
    hope im posting it right. if not pls let me know how. and thanks for any kind help provided.
    Last edited by doxycycline; 02-07-2011 at 04:03 PM. Reason: added code tag

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, please use code tags next time when you are posting code segments in the forum. Unformatted codes are really hard to read.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Regarding your question, as you said you can workout with a one user. Then think about that how you keep those data.

    Then if you want to do the same process again, with different user details, work around with loops.

  4. #4
    doxycycline is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    yea. i have a loop to collect the inputs in arrays. then i have a for loop to print them out. but when i printed them out, the string inputs become nulls and the integer or double inputs become 0s.
    i tried printing 1 or 2 sets of inputs without the for loop and it works. but if the for loop is there it doesnt work already.

    n sorry about the code tag.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Before that here,

    Java Code:
    if (enterAnother == 'N') {
                    break repeat;
                }
    what happen if a user enter 'n', rather 'N' ?

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Carefully look at the following code segment,

    Java Code:
    //section 5 - print results
            for (int noOfTrainees = 0; noOfTrainees < 20; noOfTrainees++) {
                printResults(traineeNo[noOfTrainees], firstName[noOfTrainees], familyName[noOfTrainees], moduleName[noOfTrainees], averageMark[noOfTrainees], modTestMark[noOfTrainees], overallMark[noOfTrainees]);
            }
    Look at the loop validation. You always expecting 20 entries, and if you enter only one record you can see last 19 records with default values, such as null and all as you said.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  8. #8
    doxycycline is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    oh yes thanks. because of that i cannot see the top 10 entries in BlueJ. in fact my code has no error. its because BlueJ didnt display the top 10 entries. I hav set a counter in the loop which gets inputs, and let the for loop refer to the counter. so it will only print out the number of entries.

    as for your previous question, if u enter N or n, it should break the main for loop which gets inputs. but i only know how to set it to break the loop with N or n, and not both. erm. do u hav any hints to it?

    thanks a lot for your help.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    For the terminating part you can use logical OR with the both combination. But it's not the best way.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    For the for loop thing, never user constant values unless you can configure values. You should validate with updated values. Actually with arrays you cannot do that, with ArrayList you can handle dynamic updates, users in your case.

  11. #11
    doxycycline is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    thanks a lot =) i have managed to settle that problem using else if. thanks again for your help.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Help with Java Project
    By j@v@ in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 05:37 AM
  2. Need a little help with a java project.
    By JustJava in forum New To Java
    Replies: 5
    Last Post: 10-21-2009, 06:39 AM
  3. Use Java 2 Project in different IDE
    By ramzansadiq in forum Eclipse
    Replies: 8
    Last Post: 02-15-2009, 05:33 PM
  4. java project
    By gvdn in forum Advanced Java
    Replies: 4
    Last Post: 07-13-2008, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •