| | |
I need some help here!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 17
Reputation:
Solved Threads: 0
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.*;
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.*;
Java Syntax (Toggle Plain Text)
public class ToyoradaII { public static void main(String []lyn) throws IOException { String choice; InputStreamReader stream=new InputStreamReader(System.in); BufferedReader read=new BufferedReader(stream); int grades[]=new int[10]; int num=1; String str; do{ System.out.println("+-----------------------------------+"); System.out.println("|NOTE 1:NO GRADES BELOW 50 0R HIGHER|\n|\t\tTHAN 100 SHALL BE ENTERED! |"); System.out.println("+-----------------------------------+"); System.out.println("+---------------------------------------+"); System.out.println("THIS PROGRAM ACCEPTS ONLY WHOLE NUMBERS!|"); System.out.println("+---------------------------------------+"); int x=0; while(x<10) { do{ System.out.println("\n"); System.out.print("Student "+num+":"); str=read.readLine(); grades[x]=Integer.parseInt(str); if(grades[x]<50) { System.out.println("GRADE BELOW 50 NOT ALLOWED! \n\tEnter another. . . "); } if(grades[x]>100) { System.out.println("OVERWHELMING GRADE!\n\tEnter another. . ."); } } while(grades[x]<50||grades[x]>100); num++; x++; } System.out.println("+------------------+"); int Hi_Grade; int y=0; while(y<grades.length-1) { if(grades[y]>grades[y+1]) { Hi_Grade=grades[y]; grades[y]=grades[y+1]; grades[y+1]=Hi_Grade; } y++; } System.out.println("\n\nHIGHEST GRADE: "+grades[9]); int Low_Grade; int z=0; while(z<grades.length-1) { if(grades[z]<grades[z+1]){ Low_Grade=grades[z]; grades[z]=grades[z+1]; grades[z+1]=Low_Grade; } z++; } System.out.println("\nLOWEST GRADE: "+grades[9]); int Average=0; int ave=0; while(ave<grades.length) { Average+=grades[ave]; ave++; } Average=Average/10; System.out.println("\nAVERAGE GRADE: "+Average); System.out.println("\n\nGRADE DISTRIBUTION: "); int dist1=0; int a=0; while(a<grades.length) { if(grades[a]>=50&&grades[a]<=60) { dist1++; }a++; } System.out.print("\n50-60 : "); int b=0; while(b<dist1) { System.out.print("*"); b++; } int dist2=0; int c=0; while(c<grades.length) { if(grades[c]>=61&&grades[c]<=70) { dist2++; }c++; } System.out.print("\n61-70 : "); int d=0; while(d<dist2) { System.out.print("*"); d++; } int dist3=0; int e=0; while(e<grades.length) { if(grades[e]>=71&&grades[e]<=80) { dist3++; }e++; } System.out.print("\n71-80 : "); int f=0; while(f<dist3) { System.out.print("*"); f++; } int dist4=0; int g=0; while(g<grades.length) { if(grades[g]>=81&&grades[g]<=90) { dist4++; }g++; } System.out.print("\n81-90 : "); int h=0; while(h<dist4) { System.out.print("*"); h++; } int dist5=0; int i=0; while(i<grades.length) { if(grades[i]>=91&&grades[i]<=100) { dist5++; }i++; } System.out.print("\n91-100: "); int j=0; while(j<dist5) { System.out.print("*"); j++; } System.out.println("\n+------------------------------+"); System.out.print("|WANT TO DO IT AGAIN? [YES][NO]|"); System.out.println("\n+------------------------------+"); choice=read.readLine(); if(choice.equalsIgnoreCase("yes")) num=1; }while(choice.equalsIgnoreCase("yes")); } }
Last edited by Ancient Dragon; Jul 30th, 2008 at 10:21 am. Reason: snip email and add code tags
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
@hny_lyn
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
- Read the rules, no request for homework solutions to be send over by email or PM
- "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
- a code that has exception attached to main method is one of the worst things and we do not like to see 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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jul 2008
Posts: 17
Reputation:
Solved Threads: 0
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!!
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!!
•
•
Join Date: Jul 2008
Posts: 17
Reputation:
Solved Threads: 0
sir peter_budo;
sorry for using such statements!! to show you that i have learned something in java.... it have made this code...
///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!!!
sorry for using such statements!! to show you that i have learned something in java.... it have made this code...
Java Syntax (Toggle Plain Text)
public class Grade{ public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str; String grad; int student[][]=new int[10][3]; String prelim; String midterm; String finals; int mj=1; int lowest=0; int highest=0; int average=0; for(int rw=0; rw<10; rw++){ for(int col=0; col<3; col++){ do{ grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } grad=JOptionPane.showInputDialog("Student Finals["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } }while(student[rw][col]<50||student[rw][col]>100); mj++; if() } } } }
>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
Java Syntax (Toggle Plain Text)
for(int rw=0; rw<10; rw++){ for(int col=0; col<3; col++){ do{ grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } grad=JOptionPane.showInputDialog("Student Finals["+mj+"]"); student[rw][col]=Integer.parseInt(grad); if(student[rw][col]<50||student[rw][col]>100){ JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!"); } }while(student[rw][col]<50||student[rw][col]>100); mj++;
Let's talk about your code:
You don't need 2 for loops. This is what you wrote:
Java Syntax (Toggle Plain Text)
grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]"); student[rw][col]=Integer.parseInt(grad); grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]"); student[rw][col]=Integer.parseInt(grad); grad=JOptionPane.showInputDialog("Student Finals["+mj+"]"); student[rw][col]=Integer.parseInt(grad);
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:
Java Syntax (Toggle Plain Text)
for (int i=0;i<10;i++) { grad=JOptionPane.showInputDialog("Student Prelim["+i+"]"); student[i][0]=Integer.parseInt(grad); grad=JOptionPane.showInputDialog("Student Midterm["+i+"]"); student[i][1]=Integer.parseInt(grad); grad=JOptionPane.showInputDialog("Student Finals["+i+"]"); student[i][2]=Integer.parseInt(grad); }
[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:
Java Syntax (Toggle Plain Text)
for (int i=0;i<10;i++) { boolean ok = false; while (!ok) { prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]"); midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]"); finals=JOptionPane.showInputDialog("Student Finals["+i+"]"); if (/* check the above values. if they are ok*/) { ok=true; //put them in the array as showed above } } }
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
Another version using YOUR do while loop is this:
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:
Java Syntax (Toggle Plain Text)
for (int i=0;i<10;i++) { do{ prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]"); midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]"); finals=JOptionPane.showInputDialog("Student Finals["+i+"]"); boolean bPrelim =(prelim<50) || (prelim>100) ; boolean bMidterm =(midterm<50) || (midterm>100) ; boolean bFinals =(finals<50) || (finals>100) ; if (bPrelim ) { //print the appropriate error message } if (bMidterm) { //print the appropriate error message } if (bMidterm) { //print the appropriate error message } student[i][0]=Integer.parseInt(prelim); student[i][1]=Integer.parseInt(midterm); student[i][2]=Integer.parseInt(finals); } while( bPrelim || bMidterm || bMidterm); }
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:
Java Syntax (Toggle Plain Text)
for (int i=0;i<10;i++) { do{ prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]"); midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]"); finals=JOptionPane.showInputDialog("Student Finals["+i+"]"); boolean bPrelim =(prelim<50) || (prelim>100) ; boolean bMidterm =(midterm<50) || (midterm>100) ; boolean bFinals =(finals<50) || (finals>100) ; if (bPrelim ) { //print the appropriate error message } if (bMidterm) { //print the appropriate error message } if (bMidterm) { //print the appropriate error message } } while( bPrelim || bMidterm || bMidterm); student[i][0]=Integer.parseInt(prelim); student[i][1]=Integer.parseInt(midterm); student[i][2]=Integer.parseInt(finals); }
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Other Threads in the Java Forum
- Previous Thread: Help on getting 2 lowest values in an array.
- Next Thread: xml to object and vice versa
Views: 1046 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for Java
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component database derby design draw eclipse encryption error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jmf jni jpanel julia linux list loop map method methods midlethttpconnection mobile multithreading netbeans newbie nullpointerexception number object oracle print printing problem program programming project recursion reference remove ria scanner screen server set size sms socket sort sourcelabs sql stop string swing test threads time transfer tree ui unicode validation windows






