I need some help here!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 17
Reputation: hny_lyn is an unknown quantity at this point 
Solved Threads: 0
hny_lyn hny_lyn is offline Offline
Newbie Poster

I need some help here!

 
0
  #1
Jul 29th, 2008
hello sir!!!

i need the answer as soon as possible!! can you change this code and execute it using the JOptionPane... Please help me!!! You may send your answers to this address... <snip email>
Thanks a lot!!!

import java.io.*;
  1. public class ToyoradaII
  2. {
  3. public static void main(String []lyn)
  4. throws IOException
  5. {
  6. String choice;
  7. InputStreamReader stream=new InputStreamReader(System.in);
  8. BufferedReader read=new BufferedReader(stream);
  9.  
  10. int grades[]=new int[10];
  11. int num=1;
  12.  
  13. String str;
  14. do{
  15. System.out.println("+-----------------------------------+");
  16. System.out.println("|NOTE 1:NO GRADES BELOW 50 0R HIGHER|\n|\t\tTHAN 100 SHALL BE ENTERED! |");
  17. System.out.println("+-----------------------------------+");
  18. System.out.println("+---------------------------------------+");
  19. System.out.println("THIS PROGRAM ACCEPTS ONLY WHOLE NUMBERS!|");
  20. System.out.println("+---------------------------------------+");
  21.  
  22. int x=0;
  23. while(x<10)
  24. {
  25. do{
  26. System.out.println("\n");
  27.  
  28. System.out.print("Student "+num+":");
  29. str=read.readLine();
  30. grades[x]=Integer.parseInt(str);
  31.  
  32. if(grades[x]<50)
  33. {
  34. System.out.println("GRADE BELOW 50 NOT ALLOWED! \n\tEnter another. . . ");
  35. }
  36.  
  37. if(grades[x]>100)
  38. {
  39. System.out.println("OVERWHELMING GRADE!\n\tEnter another. . .");
  40. }
  41.  
  42. }
  43. while(grades[x]<50||grades[x]>100);
  44. num++;
  45. x++;
  46. }
  47.  
  48.  
  49. System.out.println("+------------------+");
  50.  
  51. int Hi_Grade;
  52. int y=0;
  53. while(y<grades.length-1)
  54.  
  55. {
  56. if(grades[y]>grades[y+1])
  57. {
  58. Hi_Grade=grades[y];
  59. grades[y]=grades[y+1];
  60. grades[y+1]=Hi_Grade;
  61. }
  62. y++;
  63. }
  64.  
  65. System.out.println("\n\nHIGHEST GRADE: "+grades[9]);
  66.  
  67.  
  68. int Low_Grade;
  69. int z=0;
  70. while(z<grades.length-1)
  71.  
  72. {
  73. if(grades[z]<grades[z+1]){
  74. Low_Grade=grades[z];
  75. grades[z]=grades[z+1];
  76. grades[z+1]=Low_Grade;
  77. }
  78. z++;
  79. }
  80.  
  81. System.out.println("\nLOWEST GRADE: "+grades[9]);
  82.  
  83.  
  84. int Average=0;
  85. int ave=0;
  86. while(ave<grades.length)
  87.  
  88. {
  89. Average+=grades[ave];
  90. ave++;
  91. }
  92.  
  93.  
  94. Average=Average/10;
  95. System.out.println("\nAVERAGE GRADE: "+Average);
  96.  
  97.  
  98.  
  99.  
  100. System.out.println("\n\nGRADE DISTRIBUTION: ");
  101. int dist1=0;
  102. int a=0;
  103. while(a<grades.length)
  104. {
  105. if(grades[a]>=50&&grades[a]<=60)
  106. {
  107.  
  108. dist1++;
  109.  
  110. }a++;
  111. }
  112. System.out.print("\n50-60 : ");
  113. int b=0;
  114. while(b<dist1)
  115.  
  116. {
  117. System.out.print("*");
  118. b++;
  119. }
  120.  
  121.  
  122. int dist2=0;
  123. int c=0;
  124. while(c<grades.length)
  125. {
  126. if(grades[c]>=61&&grades[c]<=70)
  127. {
  128. dist2++;
  129.  
  130. }c++;
  131. }
  132. System.out.print("\n61-70 : ");
  133. int d=0;
  134. while(d<dist2)
  135.  
  136. {
  137. System.out.print("*");
  138. d++;
  139. }
  140.  
  141.  
  142.  
  143. int dist3=0;
  144. int e=0;
  145. while(e<grades.length)
  146. {
  147. if(grades[e]>=71&&grades[e]<=80)
  148. {
  149. dist3++;
  150.  
  151. }e++;
  152. }
  153. System.out.print("\n71-80 : ");
  154. int f=0;
  155. while(f<dist3)
  156.  
  157. {
  158. System.out.print("*");
  159. f++;
  160. }
  161.  
  162.  
  163. int dist4=0;
  164. int g=0;
  165. while(g<grades.length)
  166. {
  167. if(grades[g]>=81&&grades[g]<=90)
  168. {
  169. dist4++;
  170.  
  171. }g++;
  172. }
  173. System.out.print("\n81-90 : ");
  174. int h=0;
  175. while(h<dist4)
  176.  
  177. {
  178. System.out.print("*");
  179. h++;
  180. }
  181.  
  182. int dist5=0;
  183. int i=0;
  184. while(i<grades.length)
  185. {
  186. if(grades[i]>=91&&grades[i]<=100)
  187. {
  188. dist5++;
  189.  
  190. }i++;
  191. }
  192. System.out.print("\n91-100: ");
  193. int j=0;
  194. while(j<dist5)
  195.  
  196. {
  197. System.out.print("*");
  198. j++;
  199. }
  200.  
  201.  
  202. System.out.println("\n+------------------------------+");
  203. System.out.print("|WANT TO DO IT AGAIN? [YES][NO]|");
  204. System.out.println("\n+------------------------------+");
  205. choice=read.readLine();
  206.  
  207. if(choice.equalsIgnoreCase("yes"))
  208. num=1;
  209.  
  210. }while(choice.equalsIgnoreCase("yes"));
  211. }
  212. }
Last edited by Ancient Dragon; Jul 30th, 2008 at 10:21 am. Reason: snip email and add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: I need some help here!

 
0
  #2
Jul 29th, 2008
Do you know which part of the code needs to be replaced with JOptionPane? If you don't that probably means that you didn't write it. Tell us what you don't understand and we will help, but no one is going to email you the solution
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2
Reputation: sugan_gurung is an unknown quantity at this point 
Solved Threads: 1
sugan_gurung sugan_gurung is offline Offline
Newbie Poster

Re: I need some help here!

 
0
  #3
Jul 29th, 2008
if you want it in JFrame then i've done it. Let me know if you still need it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,267
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: I need some help here!

 
0
  #4
Jul 30th, 2008
@hny_lyn
  1. Read the rules, no request for homework solutions to be send over by email or PM
  2. "i need the answer as soon as possible!!" is rude thing to say, we will help when we want, it doesn't matter to us that when you need to submit this home work
  3. a code that has exception attached to main method is one of the worst things and we do not like to see it

Originally Posted by sugan_gurung View Post
if you want it in JFrame then i've done it. Let me know if you still need it.
If you think you helping him, you are mistaken. By giving the code, hny_lyn will learn nothing. Copy & paste is not a solution when you learning
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 17
Reputation: hny_lyn is an unknown quantity at this point 
Solved Threads: 0
hny_lyn hny_lyn is offline Offline
Newbie Poster

Re: I need some help here!

 
0
  #5
Jul 30th, 2008
hello sir!!!

i really do learn something about java!! its just that its too hard for me as a beginner!!!
actually, our project is about a 2-dimensional array using JOptionPane!! i have made that code<the one posted> last week...,<i really made it! swear!!>

i just wanted to have an idea on how to do it with JOption!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 17
Reputation: hny_lyn is an unknown quantity at this point 
Solved Threads: 0
hny_lyn hny_lyn is offline Offline
Newbie Poster

Re: I need some help here!

 
0
  #6
Jul 30th, 2008
sir peter_budo;

sorry for using such statements!! to show you that i have learned something in java.... it have made this code...

  1. public class Grade{
  2. public static void main (String[] args) throws IOException {
  3. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  4.  
  5. String str;
  6. String grad;
  7. int student[][]=new int[10][3];
  8. String prelim;
  9. String midterm;
  10. String finals;
  11. int mj=1;
  12. int lowest=0;
  13. int highest=0;
  14. int average=0;
  15.  
  16. for(int rw=0; rw<10; rw++){
  17. for(int col=0; col<3; col++){
  18. do{
  19. grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
  20. student[rw][col]=Integer.parseInt(grad);
  21. if(student[rw][col]<50||student[rw][col]>100){
  22. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  23. }
  24. grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
  25. student[rw][col]=Integer.parseInt(grad);
  26. if(student[rw][col]<50||student[rw][col]>100){
  27. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  28. }
  29. grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
  30. student[rw][col]=Integer.parseInt(grad);
  31. if(student[rw][col]<50||student[rw][col]>100){
  32. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  33. }
  34. }while(student[rw][col]<50||student[rw][col]>100);
  35. mj++;
  36. if()
  37.  
  38.  
  39. }
  40. }
  41. }
  42. }
///the problem now sir, is that im hanging in this state...its about 2-dimensional arrays!!
>i have to get the lowest grade, the highest and the average.... one thing i know on how to get this is by means of sorting......SORTING 2-dimensional arrays is my problem now!!! the output is just similar to my first posted thread!!!
Last edited by Tekmaven; Jul 30th, 2008 at 9:49 am. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 17
Reputation: hny_lyn is an unknown quantity at this point 
Solved Threads: 0
hny_lyn hny_lyn is offline Offline
Newbie Poster

Re: I need some help here!

 
0
  #7
Jul 30th, 2008
hello sir!!!

i made the code!!
i swear!!!

i just dont have enough idea about the JOption thing!!!

Sorry!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: I need some help here!

 
0
  #8
Jul 30th, 2008
  1. for(int rw=0; rw<10; rw++){
  2. for(int col=0; col<3; col++){
  3. do{
  4. grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
  5. student[rw][col]=Integer.parseInt(grad);
  6. if(student[rw][col]<50||student[rw][col]>100){
  7. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  8. }
  9. grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
  10. student[rw][col]=Integer.parseInt(grad);
  11. if(student[rw][col]<50||student[rw][col]>100){
  12. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  13. }
  14. grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
  15. student[rw][col]=Integer.parseInt(grad);
  16. if(student[rw][col]<50||student[rw][col]>100){
  17. JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
  18. }
  19. }while(student[rw][col]<50||student[rw][col]>100);
  20. mj++;

Let's talk about your code:

You don't need 2 for loops. This is what you wrote:
  1. grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
  2. student[rw][col]=Integer.parseInt(grad);
  3. grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
  4. student[rw][col]=Integer.parseInt(grad);
  5. grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
  6. student[rw][col]=Integer.parseInt(grad);
You will put 3 different values:
1) JOptionPane.showInputDialog("Student Prelim["+mj+"]") ;
2) JOptionPane.showInputDialog("Student Midterm["+mj+"]")
3) grad=JOptionPane.showInputDialog("Student Finals["+mj+"]")
At the same location: student[rw][col]

You might want to try this:

  1. for (int i=0;i<10;i++) {
  2.  
  3. grad=JOptionPane.showInputDialog("Student Prelim["+i+"]");
  4. student[i][0]=Integer.parseInt(grad);
  5.  
  6. grad=JOptionPane.showInputDialog("Student Midterm["+i+"]");
  7. student[i][1]=Integer.parseInt(grad);
  8.  
  9. grad=JOptionPane.showInputDialog("Student Finals["+i+"]");
  10. student[i][2]=Integer.parseInt(grad);
  11. }
Assuming that at the location:
[i][0] there will be the Preilim
[i][1] there will be the Midterm
[i][2] there will be the Finals

As for the check I would suggest first to take all the values, check them all and then put them in the array:

  1. for (int i=0;i<10;i++) {
  2.  
  3. boolean ok = false;
  4. while (!ok) {
  5. prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
  6. midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
  7. finals=JOptionPane.showInputDialog("Student Finals["+i+"]");
  8.  
  9. if (/* check the above values. if they are ok*/) {
  10. ok=true;
  11.  
  12. //put them in the array as showed above
  13. }
  14.  
  15. }
  16.  
  17. }
The first time the check will be made, ok will be false and you will go in the while. If the values are valid, ok will be turned into true. So the while statement (!ok) will be false, and you will exit the while, and you will continue at the next for loop. If the values are wrong then the ok variable will not change and you will repeat the while.
Last edited by javaAddict; Jul 30th, 2008 at 6:17 am.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 17
Reputation: hny_lyn is an unknown quantity at this point 
Solved Threads: 0
hny_lyn hny_lyn is offline Offline
Newbie Poster

Re: I need some help here!

 
0
  #9
Jul 30th, 2008
sir!

thank you for this!!

i'll share this with my other classmates..., same with me...having troubles dealing with this JOptionPane!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: I need some help here!

 
0
  #10
Jul 30th, 2008
Another version using YOUR do while loop is this:

  1. for (int i=0;i<10;i++) {
  2.  
  3. do{
  4. prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
  5. midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
  6. finals=JOptionPane.showInputDialog("Student Finals["+i+"]");
  7.  
  8. boolean bPrelim =(prelim<50) || (prelim>100) ;
  9. boolean bMidterm =(midterm<50) || (midterm>100) ;
  10. boolean bFinals =(finals<50) || (finals>100) ;
  11.  
  12. if (bPrelim ) {
  13. //print the appropriate error message
  14. }
  15. if (bMidterm) {
  16. //print the appropriate error message
  17. }
  18. if (bMidterm) {
  19. //print the appropriate error message
  20. }
  21.  
  22. student[i][0]=Integer.parseInt(prelim);
  23. student[i][1]=Integer.parseInt(midterm);
  24. student[i][2]=Integer.parseInt(finals);
  25.  
  26. } while( bPrelim || bMidterm || bMidterm);
  27.  
  28. }

If any of the boolean variables are true, that means that the values are wrong. So the while will repeat and ask for the values again. The <i> will not chang since you are inside the same for loop. If all the boolean values are false, means that all the values are correct and the while will be false, so you will continue with the next for loop.

You could also try this:

  1. for (int i=0;i<10;i++) {
  2.  
  3. do{
  4. prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
  5. midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
  6. finals=JOptionPane.showInputDialog("Student Finals["+i+"]");
  7.  
  8. boolean bPrelim =(prelim<50) || (prelim>100) ;
  9. boolean bMidterm =(midterm<50) || (midterm>100) ;
  10. boolean bFinals =(finals<50) || (finals>100) ;
  11.  
  12. if (bPrelim ) {
  13. //print the appropriate error message
  14. }
  15. if (bMidterm) {
  16. //print the appropriate error message
  17. }
  18. if (bMidterm) {
  19. //print the appropriate error message
  20. }
  21. } while( bPrelim || bMidterm || bMidterm);
  22.  
  23. student[i][0]=Integer.parseInt(prelim);
  24. student[i][1]=Integer.parseInt(midterm);
  25. student[i][2]=Integer.parseInt(finals);
  26. }
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 1046 | Replies: 15
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC