Wednesday, January 16, 2008

Answers for Question C

Haha... at last, my turn to give answer......

Actually not hard one... just follow the steps :

STEP 1 : Analyze the Problem

This is a "find" problem.

Unknowns - GPA
Data - course grade, course credit hours,
Conditions - GPA must be in between 0 and 4
Credit hours must not be 0

STEP 2 : Devise a solution plan

As Prof. Yazid said, we need to know each word well. Therefore, we need to know the definition on some terms.

To make it simple, I don't want to copy all words from wikipedia lah, I use my own words ah... (got a bit cacat la... I sure you all oso dun want to see all the words from wikipedia rite? )

GPA = GRADE POINT AVERAGE = AVERAGE OF THE SUM OF GRADE POINTS = (SUM OF GRADE POINTS) / SUM OF CREDIT HOURS

GRADE POINTS = GRADE * CREDIT HOUR OF THE GRADE

OK, enough of definition. Now we need a sub-conclusion on this part, which is :

To calculate GPA, we need :
1) SUM OF credit hours
2) SUM OF grade point

and to find grade point we need :
1) grade
2) credit hour OF the grade

Step 3 : Code & run the program

WHOA!!!!!!!! This is the part where I will be clapping my hands XD...
Its JAVA PROGRAMMING TIME!!!!!!

Erm, should I paste the coding here or what?
Like this la, I paste it here first, then if you all feel not suitable, we open a webFolder account k, then we paste there.

=== CODING STARTS ===

import javax.swing.JOptionPane ;
public class gpaCalculator {

public static void main ( String[] args ) {

String tempParser ;
int subjectCount, tempUSE ;
double totalGP , totalCHour, tempGP, tempCHour, GPA ;
totalGP = 0 ;
totalCHour = 0 ;

tempParser = JOptionPane.showInputDialog("Please enter the total number of subjects : ") ;
subjectCount = Integer.parseInt(tempParser) ;

for ( int x = 0 ; x < subjectCount ; x ++ ) {

tempParser = JOptionPane.showInputDialog("Please enter the grade awarded for subject " + (x+1) + " according to the menu below.\n(1) A\n(2) A-\n(3) B+\n(4) B\n(5) B-\n(6) C+\n(7) C\n(8) C-\n(9) D+\n(10) D\n(11) D-\n(12) Fail") ;
tempUSE = Integer.parseInt(tempParser) ;
tempGP = findPoint(tempUSE) ;

tempParser = JOptionPane.showInputDialog("Please enter the credit hours associaated to subject " + (x+1) + ".") ;
tempUSE = Integer.parseInt(tempParser) ;
tempCHour = tempUSE ;
totalCHour = totalCHour + tempCHour ;

totalGP = totalGP + (tempGP * tempCHour) ;

}

GPA = totalGP / totalCHour ;

JOptionPane.showMessageDialog(null,"Your GPA is " + GPA + "." ) ;
System.exit(0) ;

}

public static double findPoint(int x){

if (x == 1)
return 4.0 ;
if (x == 2)
return 3.7 ;
if (x == 3)
return 3.3 ;
if (x == 4)
return 3.0 ;
if (x == 5)
return 2.7 ;
if (x == 6)
return 2.3 ;
if (x == 7)
return 2.0 ;
if (x == 8)
return 1.7 ;
if (x == 9)
return 1.3 ;
if (x == 10)
return 1.0 ;
if (x == 11)
return 0.7 ;
if (x == 12)
return 0.0 ;
else
return 0.0 ;

}

}

=== CODING ENDS ===

So? Just put whatever data required and then the calculator calculates for you. Easy right?

So?? Chaoz=== Cheerz!

2 comments:

-悦音- said...

Oh ya, I forgot to mention...

Please don;t comment the coding in this program k, we are learning the concept, not coding. I know my coding very cacat k, but... duh... just ignore it k...

Cheerz!

ryanne said...

mayb we'd rather c those wording from wiki-wiki den ur long long coding