October 18th, 2012, 06:52 PM
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,
October 18th, 2012, 08:23 PM
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,
and could be reduced to the one line
var = some value;
I bet you can get more specific answers if we could see the code you have.
do something(some value);
October 19th, 2012, 08:49 AM
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.
Originally Posted by requinix
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: ");
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: ");
October 19th, 2012, 11:31 AM
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.