12 Replies - 3783 Views - Last Post: 02 October 2012 - 08:52 PM Rate Topic: ***** 1 Votes

#1 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Grading System using arrays and loops

Posted 02 October 2012 - 07:34 PM

I have some problems on my output...
this should be the output....


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SCNCE 90 90 90 90 90 PASSED
FIL 90 90 90 90 90 PASSED


while this is MY PROBLEM and this is what the result of my output....

When the average and remarks "PASSED" appeared more than once, the title of subj,prelim,midterm,prefinal,final also appear.


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
SCNCE 90 90 90 90 90 PASSED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
FIL 90 90 90 90 90 PASSED


THESE ARE MY CODES:


import javax.swing.*;
import java.io.*;
import java.util.*;

public class Array
{
public static void main (String [] args)
{

String subj[];
int pre[];
int mid [];
int prefin[];
int fin[];

subj = new String [4];
pre = new int [4];
mid = new int [4];
prefin = new int [4];
fin = new int [4];

String name, course;
int ave = 0, gwa = 0;

name = JOptionPane.showInputDialog(null, "ENter Name: ");
course = JOptionPane.showInputDialog("Enter Course: ");

System.out.println("==========================================");
System.out.println("Name: " +name + "\t\t" + "Course: " +course);
System.out.println("==========================================");

for (int i=0; i<subj.length; i++)
{
subj[i] = JOptionPane.showInputDialog("Enter Subject");
pre[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Prelim Grade"));
mid[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Midterm Grade"));
prefin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Pre-Final Grade"));
fin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Final Grade"));

ave = ((pre[i] + mid [i] + prefin [i] + fin [i]) / 4);

if (ave>=75)
{
System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks");

System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" + "PASSED");
}
else
{

System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" + "FAILED");

}
}

gwa = gwa+ave/4;

System.out.println( "\n\n" +"\t\t\t" + "GWA: " + "\t\t" + gwa);
}
}

:helpsmilie: Pls help me or teach me how to correct my problem... Thanks in advance :001_icon16:

Is This A Good Question/Topic? 0
  • +

Replies To: Grading System using arrays and loops

#2 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 07:39 PM

I forgot to tell about GWA... get the sum of all average then divide into 4....
THanks for all the help
Was This Post Helpful? 0
  • +
  • -

#3 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

Re: Grading System using arrays and loops

Posted 02 October 2012 - 07:44 PM

Could you please edit your post and put your code inside the code tags?

Could this be what you want? Put your printing of the headers subject, prelim, etc above the if block.
Was This Post Helpful? 1
  • +
  • -

#4 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:03 PM

I have some problems on my output...
this should be the output....


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SCNCE 90 90 90 90 90 PASSED
FIL 90 90 90 90 90 PASSED


while this is MY PROBLEM and this is what the result of my output....

When the average and remarks "PASSED" appeared more than once, the title of subj,prelim,midterm,prefinal,final also appear.
I wanted those grades appear without their title if the AVERAGE and REMARKS "PASSED" appeared more than once, like in my sample output above.


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
SCNCE 90 90 90 90 90 PASSED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
FIL 90 90 90 90 90 PASSED


THESE ARE MY CODES:


import javax.swing.*;
import java.io.*;
import java.util.*;

public class Array 
{
public static void main (String [] args)
{	
	
String subj[];
int pre[];
int mid [];
int prefin[];
int fin[];

subj = new String [4];
pre = new int [4];
mid = new int [4];
prefin = new int [4];
fin = new int [4];

String name, course;
int ave = 0, gwa = 0;

name = JOptionPane.showInputDialog(null, "ENter Name: ");
course = JOptionPane.showInputDialog("Enter Course: ");

System.out.println("==========================================");
System.out.println("Name: " +name + "\t\t" + "Course: " +course);
System.out.println("==========================================");

for (int i=0; i<subj.length; i++)
{
	subj[i] = JOptionPane.showInputDialog("Enter Subject");
	pre[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Prelim Grade"));
	mid[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Midterm Grade"));
	prefin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Pre-Final Grade"));
	fin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Final Grade"));

	ave = ((pre[i] + mid [i] + prefin [i] + fin [i]) / 4);
	
if (ave>=75)
{
	System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks");

	System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "PASSED");
}
else
{

System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "FAILED");

}
}

gwa = gwa+ave/4;

System.out.println( "\n\n" +"\t\t\t" + "GWA: " + "\t\t" + gwa);
}
}


:helpsmilie: Pls help me or teach me how to correct my problem... Thanks in advance :001_icon16:
Was This Post Helpful? 0
  • +
  • -

#5 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:09 PM

Yep, then definitely follow my suggestion above. Put line 44 outside the if - else block.
Was This Post Helpful? 0
  • +
  • -

#6 lilVaratep  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 207
  • Joined: 09-October 11

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:11 PM

View Postpeenai, on 02 October 2012 - 08:03 PM, said:

I have some problems on my output...
this should be the output....


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SCNCE 90 90 90 90 90 PASSED
FIL 90 90 90 90 90 PASSED


while this is MY PROBLEM and this is what the result of my output....

When the average and remarks "PASSED" appeared more than once, the title of subj,prelim,midterm,prefinal,final also appear.
I wanted those grades appear without their title if the AVERAGE and REMARKS "PASSED" appeared more than once, like in my sample output above.


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
SCNCE 90 90 90 90 90 PASSED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
FIL 90 90 90 90 90 PASSED


THESE ARE MY CODES:


import javax.swing.*;
import java.io.*;
import java.util.*;

public class Array 
{
public static void main (String [] args)
{	
	
String subj[];
int pre[];
int mid [];
int prefin[];
int fin[];

subj = new String [4];
pre = new int [4];
mid = new int [4];
prefin = new int [4];
fin = new int [4];

String name, course;
int ave = 0, gwa = 0;

name = JOptionPane.showInputDialog(null, "ENter Name: ");
course = JOptionPane.showInputDialog("Enter Course: ");

System.out.println("==========================================");
System.out.println("Name: " +name + "\t\t" + "Course: " +course);
System.out.println("==========================================");

for (int i=0; i<subj.length; i++)
{
	subj[i] = JOptionPane.showInputDialog("Enter Subject");
	pre[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Prelim Grade"));
	mid[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Midterm Grade"));
	prefin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Pre-Final Grade"));
	fin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Final Grade"));

	ave = ((pre[i] + mid [i] + prefin [i] + fin [i]) / 4);
	
if (ave>=75)
{
	System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks");

	System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "PASSED");
}
else
{

System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "FAILED");

}
}

gwa = gwa+ave/4;

System.out.println( "\n\n" +"\t\t\t" + "GWA: " + "\t\t" + gwa);
}
}


:helpsmilie: Pls help me or teach me how to correct my problem... Thanks in advance :001_icon16:



No reason to be printing System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks"); every single time if the average is greater than 75. Why not just print it ONCE before you even output the scores?
Was This Post Helpful? 1
  • +
  • -

#7 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:13 PM

For the GWA, do this:
Declare a GWA variable and a counter set them both to zero
Increment GWA with the current subject grade + GWA and the counter for each subject
At the end GWA = GWA / counter


Good luck!
Was This Post Helpful? 1
  • +
  • -

#8 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:16 PM

View PostfromTheSprawl, on 02 October 2012 - 08:09 PM, said:

Yep, then definitely follow my suggestion above. Put line 44 outside the if - else block.


Thanks for the reply, but it also print the title together with their scores even the Average and Remarks is "Failed" / "Passed". :( please :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#9 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:23 PM

View PostlilVaratep, on 02 October 2012 - 08:11 PM, said:

View Postpeenai, on 02 October 2012 - 08:03 PM, said:

I have some problems on my output...
this should be the output....


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SCNCE 90 90 90 90 90 PASSED
FIL 90 90 90 90 90 PASSED


while this is MY PROBLEM and this is what the result of my output....

When the average and remarks "PASSED" appeared more than once, the title of subj,prelim,midterm,prefinal,final also appear.
I wanted those grades appear without their title if the AVERAGE and REMARKS "PASSED" appeared more than once, like in my sample output above.


==========================================
Name: Course:
==========================================

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
MATH 90 90 90 90 90 PASSED
ALGBRA 73 73 73 73 73 FAILED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
SCNCE 90 90 90 90 90 PASSED
SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS
FIL 90 90 90 90 90 PASSED


THESE ARE MY CODES:


import javax.swing.*;
import java.io.*;
import java.util.*;

public class Array 
{
public static void main (String [] args)
{	
	
String subj[];
int pre[];
int mid [];
int prefin[];
int fin[];

subj = new String [4];
pre = new int [4];
mid = new int [4];
prefin = new int [4];
fin = new int [4];

String name, course;
int ave = 0, gwa = 0;

name = JOptionPane.showInputDialog(null, "ENter Name: ");
course = JOptionPane.showInputDialog("Enter Course: ");

System.out.println("==========================================");
System.out.println("Name: " +name + "\t\t" + "Course: " +course);
System.out.println("==========================================");

for (int i=0; i<subj.length; i++)
{
	subj[i] = JOptionPane.showInputDialog("Enter Subject");
	pre[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Prelim Grade"));
	mid[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Midterm Grade"));
	prefin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Pre-Final Grade"));
	fin[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter Final Grade"));

	ave = ((pre[i] + mid [i] + prefin [i] + fin [i]) / 4);
	
if (ave>=75)
{
	System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks");

	System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "PASSED");
}
else
{

System.out.println(" " + subj[i] + "\t\t" + " " + pre[i] + "\t\t" + " " + mid[i] + "\t\t" + " " + prefin[i] + "\t\t\t" + " " + fin[i] + "\t\t" + " " + ave + "\t\t" +  "FAILED");

}
}

gwa = gwa+ave/4;

System.out.println( "\n\n" +"\t\t\t" + "GWA: " + "\t\t" + gwa);
}
}


:helpsmilie: Pls help me or teach me how to correct my problem... Thanks in advance :001_icon16:



No reason to be printing System.out.println("Subject" + "\t\t" + "Prelim" + "\t\t" + "Midterm" + "\t\t" + "Pre-Final" + "\t\t" + "Final" + "\t\t" + "Average" + "\t\t" + "Remarks"); every single time if the average is greater than 75. Why not just print it ONCE before you even output the scores?


OH WOW YOU ARE SO RIGHT... THANKS FOR THE HELP IT WORKS NOW! :bananaman:

View PostfromTheSprawl, on 02 October 2012 - 08:13 PM, said:

For the GWA, do this:
Declare a GWA variable and a counter set them both to zero
Increment GWA with the current subject grade + GWA and the counter for each subject
At the end GWA = GWA / counter


Good luck!


YOU ARE THE BEST! THANKS FOR HELPING... IT WORKS! :bananaman:
Was This Post Helpful? 0
  • +
  • -

#10 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:27 PM

Wrong call, put line 44 outside your for loop. Also I see you have your GWA computer in place.

Also, you don't need to quote your original post every time, we will look for it if we need to. ^^
Was This Post Helpful? 0
  • +
  • -

#11 xriBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:39 PM

for the printing of the titles

SUBJECT PRELIM MIDTERM PRE-FINAL FINAL AVERAGE REMARKS

follow fromTheSprawl's Suggestion..
Was This Post Helpful? 0
  • +
  • -

#12 peenai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-October 12

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:43 PM

Sorry fromTheSprawl I am newbie in this blogging thing, will be better in posting next time :001_icon16:
Was This Post Helpful? 0
  • +
  • -

#13 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

Re: Grading System using arrays and loops

Posted 02 October 2012 - 08:52 PM

Haha, okay then. ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1