My assignment is to create a program that accepts a list of exam scores (ranges from 0-100) and output the total number of grades and then the number of each in letter grade..

but my problem in the beginning of doing my program is:

public class Grades {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

 int grade= 0;
 int nega= 0;
 

 do{
 
	 
	 
 grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:")); 
	
	
 
 
 
 
 
 
 
 }while (grade >0);
 
 if (grade>0)
 {
 JOptionPane.showMessageDialog(null,"The Input Numbers are:"+ grade+"");
 }
 
 

 
 
 
 
 
 
 }

}

instead of the grades the i have inputted should be the output, the negative number that i have inputted is the one who's become my output, the negative number should serve as my sentinal value, it should not show on the output.


please help thanks

My assignment is to create a program that accepts a list of exam scores (ranges from 0-100) and output the total number of grades and then the number of each in letter grade..

but my problem in the beginning of doing my program is:

public class Grades {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

 int grade= 0;
 int nega= 0;
 

 do{
 
	 
	 
 grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:")); 
	
	
 
 
 
 
 
 
 
 }while (grade >0);
 
 if (grade>0)
 {
 JOptionPane.showMessageDialog(null,"The Input Numbers are:"+ grade+"");
 }
 
 

 
 
 
 
 
 
 }

}

instead of the grades the i have inputted should be the output, the negative number that i have inputted is the one who's become my output, the negative number should serve as my sentinal value, it should not show on the output.


please help thanks

well your grades are only being saved one at a time in the do while loop and once the do while loop has ended.. which you would haave to type in a negative then only will the execution stop and your next line is if(grade>0) so i dont understand how this is working. shouldnt you initialize your values in an array of size 100 and wait after 100 grades are entered by keeping a counter of how many are entered and adding them to the array of grades respectively, then only can you get all your output.

Edited 4 Years Ago by DavidKroukamp: n/a

well your grades are only being saved one at a time in the do while loop and once the do while loop has ended.. which you would haave to type in a negative then only will the execution stop and your next line is if(grade>0) so i dont understand how this is working. shouldnt you initialize your values in an array and wait after 100 grades are entered by keeping a counter of how many are entered then only can you get all your output

yep thats right my grades are only saved one at a time, i still cant use arrays because we are not yet there, we are still in a beginner lesson, is there other way to show the grades without using array.?

yes.
you want for each letter (A, B, C) how many times a grade has been entered, so:

int total = total+grade;
if ( grade == AValue ) a+= 1;
else if ( grade == BValue ) b+= 1;

a bit like the above suggestion would do

yes.
you want for each letter (A, B, C) how many times a grade has been entered, so:

int total = total+grade;
if ( grade == AValue ) a+= 1;
else if ( grade == BValue ) b+= 1;

a bit like the above suggestion would do

does that mean that i will have to make an "if-else inside the do while statement, or outside?

does that mean that i will have to make an "if-else inside the do while statement, or outside?

yeah stultuske does have a good way though... but is this just going to be used to output the grades or will you it to preform individual calculations on the marks?

Edited 4 Years Ago by DavidKroukamp: n/a

yeah stultuske does have a good way though... but is this just going to be used to output the grades or will you it to preform individual calculations on the marks?

both!!

this is the sample :


(our teacher gave us this:
90-100= A
80-89= B
70-79 =C
60-69=d
0=59=F)

i will enter grades:
98
87
86
87
98
-1
-once i have reached that -1,it will stop accepting grade and will show this window:

The input NUmbers are: 98 87 86 87 98
The total number of grades: 5

NUmber of A's:2
Number of B's:3


..something like that..

:)

both!!

this is the sample :


(our teacher gave us this:
90-100= A
80-89= B
70-79 =C
60-69=d
0=59=F)

i will enter grades:
98
87
86
87
98
-1
-once i have reached that -1,it will stop accepting grade and will show this window:

The input NUmbers are: 98 87 86 87 98
The total number of grades: 5

NUmber of A's:2
Number of B's:3


..something like that..

:)

Oh okay no then all is fine and dandy :)

Edited 4 Years Ago by DavidKroukamp: n/a

inside. you only have the value of each grade itself within that if-statement

thank you i followed the code that u instructed and i think that its right but i still dont have the codes for the Avalue, Bvalue Cvalue.. and this is what i am thinking about to to:

if (grade >=90 )
  {
	Agrade+=grade;  

  }

but..i think its wrong because the grade is greater than 90 and equals to one hundred but i dont know how to do that

Oh okay no then all is fine and dandy :)

why'd u edited the message im trying to read it over and over again so that i can get some ideas.. :( haha

thank you i followed the code that u instructed and i think that its right but i still dont have the codes for the Avalue, Bvalue Cvalue.. and this is what i am thinking about to to:

if (grade >=90 )
  {
	Agrade+=grade;  

  }

but..i think its wrong because the grade is greater than 90 and equals to one hundred but i dont know how to do that

then you would use the && operator like this:

if(grade>90&&grade<=100) { 
//increment counter for all A values-to show at the end how many A's B's etc, print out the mark etc
}

The codes for A B values etc which just need 5 counters which will be incremented in the appropriate if statement i.e the A grade value counter will be incremented in you if statement where you check if the mark is 90 and greater but less then or equal too 100

Edited 4 Years Ago by DavidKroukamp: n/a

why'd u edited the message im trying to read it over and over again so that i can get some ideas.. :( haha

Thought the information i had given wasnt really understandable :P

Thought the information i had given wasnt really understandable :P

no .. everything that u have written here are very helpful to me, i just need to do it little by little since im a beginner i did what u told me:

do{
 
	 
	 
 grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:")); 
	
  if (grade >=90 && grade <=100 )
  {
	Agrade+=grade;  

  }
 
  else if (grade >=80 && grade <=89 )
  {
	  Bgrade+=grade;
  }
 
 
 }while (grade >0);
 

 
 JOptionPane.showMessageDialog(null,"The Input Numbers are:"+ Agrade+""+""+Bgrade);

but why is that the grades that i have inputted are not the ones that are showing, its a different thing.. :(

no .. everything that u have written here are very helpful to me, i just need to do it little by little since im a beginner i did what u told me:

do{
 
	 
	 
 grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:")); 
	
  if (grade >=90 && grade <=100 )
  {
	Agrade+=grade;  

  }
 
  else if (grade >=80 && grade <=89 )
  {
	  Bgrade+=grade;
  }
 
 
 }while (grade >0);
 

 
 JOptionPane.showMessageDialog(null,"The Input Numbers are:"+ Agrade+""+""+Bgrade);

but why is that the grades that i have inputted are not the ones that are showing, its a different thing.. :(

Look at stultuske's post. what you are adding now is the actual grade mark i.e 80 out of 100. what you want to be adding is 1. just to increment(increase) the counter each time a certain branch of the if statement is taken thus showing you the amount of times there was an A grade B grades etc. You would print the number inputed here:

grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:")); 
	System.out.println("Grade: "+ grade);//will print each grade
  if (grade >=90 && grade <=100 )
  {
	Agrade+=1;  

  }

Edited 4 Years Ago by DavidKroukamp: n/a

Look at stultuske's post. what you are adding now is the actual grade mark i.e 80 out of 100. what you want to be adding is 1. just to increment(increase) the counter each time a certain branch of the if statement is taken thus showing you the amount of times there was an A grade B grades etc

does that mean that i will have to do something like... a for loop?

something like this

for (x=1;x>=100;x++

something like that?

does that mean that i will have to do something like... a for loop?

something like this

for (x=1;x>=100;x++

something like that?

see my edited post above

see my edited post above

yes thts wight, but im using JOptionPane.showMessage, and my output should not show one at a time, all of them should come out in one time only :)

yes thts wight, but im using JOptionPane.showMessage, and my output should not show one at a time, all of them should come out in one time only :)

now thats unfortunately where arrays are awesome but you are not allowed? so you'll have to declare values for all marks up to 100 i.e mark1,mark2 etc

now thats unfortunately where arrays are awesome but you are not allowed? so you'll have to declare values for all marks up to 100 i.e mark1,mark2 etc

well yeah, thts what i created at frst, but u know that wont work out for me..haha!

well yeah, thts what i created at frst, but u know that wont work out for me..haha!

I dont know if this will be allowed but why not just use a string an save each mark to the string separated by a white space, this will allow you to use all the marks in a joptionpane later to print?

and as for printing lines in a JOptionPane, you can "format" your String by "/n" to start a new line.
if you do have to print all given numbers and are not allowed to put them into a String, I think you will be needing an array, List or Collection.

and as for printing lines in a JOptionPane, you can "format" your String by "/n" to start a new line.
if you do have to print all given numbers and are not allowed to put them into a String, I think you will be needing an array, List or Collection.

"\n"

;)

(and you may quote me on this ... )
:P :D

sorry for the late reply, our internet is not working properly, yes..thats what im trying to do, use "\n"

but i dont know how..my classmate already finished doing that program..but i dont think he likes to help his classmates lol!

sorry for the late reply, our internet is not working properly, yes..thats what im trying to do, use "\n"

but i dont know how..my classmate already finished doing that program..but i dont think he likes to help his classmates lol!

So what are you having problems with?

sorry for the late reply, our internet is not working properly, yes..thats what im trying to do, use "\n"

but i dont know how..my classmate already finished doing that program..but i dont think he likes to help his classmates lol!

well ... check Philippe Lahaie's post. that's how to use it:

String output = "I'm going to start a new line after this.\nSee?";
System.out.println(output);

well ... check Philippe Lahaie's post. that's how to use it:

String output = "I'm going to start a new line after this.\nSee?";
System.out.println(output);
import javax.swing.JOptionPane;


public class Grades {

	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int grade=0;
		
	

 String ans="y";
 
do{
	String inputs= "";
    int Agrade=0;
    int Bgrade=0;
    int Cgrade=0;
    int Dgrade=0;
    int Fgrade=0;
    int count=0;
		do{
 
	 
	 
			grade=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Grade:"));

			if(grade>=0){
				//if its a negative integer, do not include in the inputs
				inputs = inputs +" "+ grade;
				count++;
			}
			
			if (grade >=90 && grade <=100 ) Agrade++;
			else if (grade >=80 && grade <=89 ) Bgrade++;
			else if (grade >=70 && grade <=79 ) Cgrade++;
			else if (grade >=60 && grade <=69 ) Dgrade++;
			else if (grade >=0 && grade <=59 ) Fgrade++;
			
			
  
		}while (grade >=0);
  
		JOptionPane.showMessageDialog(null,"The input numbers are"+inputs+"\nTotal number of grades:"+count+"\nNUmber of A's:"+Agrade+"\nNUmber of B's:"+Bgrade+"\nNUmber of C's:"+Cgrade+"\nNUmber of D's:"+Dgrade+"\nNUmber of F's:"+Fgrade);
       String Ainput="";
       String Binput="";
       String Cinput="";
       String Dinput="";
       String Finput="";
		for(int i=0;i<Agrade;i++){
			Ainput=Ainput+"*";
		}
		for(int i=0;i<Bgrade;i++){
			Binput=Binput+"*";
		}
		for(int i=0;i<Cgrade;i++){
			Cinput=Cinput+"*";
		}
		for(int i=0;i<Dgrade;i++){
			Dinput=Dinput+"*";
		}
		for(int i=0;i<Fgrade;i++){
			Finput=Finput+"*";
		}
		JOptionPane.showMessageDialog(null, "A - "+Ainput+"\nB-"+Binput+"\nC-"+Cinput+"\nD-"+Dinput+"\nF-"+Finput,"Letter Grade Graph",JOptionPane.PLAIN_MESSAGE);
	
		
		ans = JOptionPane.showInputDialog(null,"Another Input?");
 }while(ans.equalsIgnoreCase("Y"));	
		
		}//end of main
}//end of class

look !! i did it!!! thank you! hahah i have a new problem! ill be doing a new thread thanks you guys!

Edited 4 Years Ago by wallet123: n/a

This question has already been answered. Start a new discussion instead.