#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    GPA Program - Theoretical Formatting Question


    Hi there whomever is reading this,

    I was tasked with making a GPA Program. The program is supposed to be able to calculate Grade Point Average on a weighted scale. It must be able to input user data, calculate the GPA score based on a weighted scale based on ranges of values for each score, and, after doing this 7 times and taking the average of all 7 inputs, output the overall GPA. Here's where I ran into my problem. I was able to make a successful program, but it had exceeded the size requirements. My program had utilized an array along with multiple if statements to determine the un-weighted GPA value, and using some math calculations, output the weighted GPA. The program was roughly 280 lines of code, exceeding the limit of 200. So my question for you is this: How would you format this program so that it could run under the limitation? I'm not asking for somebody to do my homework for me, I'm just asking for how it should run, as in, the basic format I should use. I'm only starting Java, so it would help if your answer would be a simple one.

    Thanks for your time,

    Raj
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Well, start with what you have and see if there's anything that can be removed or compressed. Like maybe you have a few temporary variables that are only used once,
    Code:
    var = some value;
    do something(var);
    and could be reduced to the one line
    Code:
    do something(some value);
    I bet you can get more specific answers if we could see the code you have.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    Well, start with what you have and see if there's anything that can be removed or compressed. Like maybe you have a few temporary variables that are only used once,
    Code:
    var = some value;
    do something(var);
    and could be reduced to the one line
    Code:
    do something(some value);
    I bet you can get more specific answers if we could see the code you have.
    Good Point, here's a sample of the code I used, it pretty much follows this pattern, with an else statement that says "Invalid Input" corresponding to each if. Note: I used an array here.

    //Input Area
    if(scano1.hasNextLong())
    {
    int r1 = (int)(scano1.nextLong());
    double x1 = (double)(g[r1]);
    Scanner scano2 = new Scanner(System.in);
    System.out.print("Please enter second class percentage grade for calculation: ");

    if(scano2.hasNextLong())
    {
    int r2 = (int)(scano2.nextLong());
    double x2 = (double)(g[r2]);
    Scanner scano3 = new Scanner(System.in);
    System.out.print("Please enter third class percentage grade for calculation: ");

    if(scano3.hasNextLong())
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Well you don't need to create a new Scanner every time, there's -6 lines. I'm not sure why you have the x* variables when you already have the values in the g array. And it seems like that array is some big thing mapping all percentages to GPAs? That can surely be eliminated in favor of some math.

IMN logo majestic logo threadwatch logo seochat tools logo