Hey guyz
I am a java beginner and I have problem with part of the code.
The thing that I don't know how to do it in this code is how to show the user that he/she has input an invalid input
In my code the valid input will be anything except 1 to 7
and I hope that your answers will be as simple way as ever coz i am just a beginner, thanks
This is the code:
/**
* @(#)Araaypro.java
*
*
* @author
* @version 1.00 2008/5/13
*/
import java.io.*;
import javax.swing.*;
public class Araaypro
{
public static void main(String args[])
{
int op,i=0,s=0;
int Num[] = new int [20];
String out;
int total = 0;
int average = 0;
do{
out="**********MENU **********\n1. for Store\n2. for Print\n3. for Search\n4. for Remove\n5. for Set\n6. for Calculate\n7. for Quite";
op= Integer.parseInt(JOptionPane.showInputDialog(out+" \n"+"Enter Your Option:"));
switch(op){
case 1:
do{
if(i==20)
{ out=" You Exeed the array size";
JOptionPane.showMessageDialog(null,out);
break;
}
op= Integer.parseInt(JOptionPane.showInputDialog("Ente r "+(i+1)+" Integer Number or -99 for stop="));
Num[i]=op;
i++;
}while(op!=-99);
s=i-1;
break;
case 2:
out="";
for(int j=0; j<s; j++)
out+=(j+1)+" Number = "+Num[j]+"\n";
JOptionPane.showMessageDialog(null,out);
break;
case 3:
op= Integer.parseInt(JOptionPane.showInputDialog("Ente r search Number="));
int f=1;
for(int j=0; j<s; j++){
if(Num[j]==op)
f=0;
}
if(f==0)
out="search <"+op+"> Number Found "+"\n";
else
out="search <"+op+"> Number NOT Found "+"\n";
JOptionPane.showMessageDialog(null,out);
break;
case 4:
op= Integer.parseInt(JOptionPane.showInputDialog("Ente r Remove Number="));
int f1=1,k=0;
for(int j=0; j<s; j++){
if(Num[j]==op){
k=j;
f1=0;
}
}
if(f1==0)
{
out="search <"+op+"> has been removed "+"\n";
JOptionPane.showMessageDialog(null,out);
for(int j1=k; j1<=s-2; j1++)
Num[j1]=Num[j1+1];
s=s-1;
break;
}
else
{
out="search <"+op+"> Number NOT Found "+"\n";
JOptionPane.showMessageDialog(null,out);
}
break;
case 5:
op= Integer.parseInt(JOptionPane.showInputDialog("Ente r A Number to set into thr array="));
for (int i1 = 0;i1<Num.length;i1++)
Num[i1] = op;
s=Num.length;
break;
case 6:
for(int i2=0; i2<s; i2++)
total =total + Num[i2];
average = total /s;
out="Total = "+total+"\nAverage Number ="+average;
JOptionPane.showMessageDialog(null,out);
break;
case 7:
break;
default: out=" Wrong option enter 1 to 7 only";
JOptionPane.showMessageDialog(null,out);
}
out="";
op= Integer.parseInt(JOptionPane.showInputDialog("Ente r 0 to Exit, or 1 to go to menu="));
}while(op!=0);
}
}
Also there is another problem i have faced: how i can make it quite the program as soon as i chose:
7. for Quite
Without asking me to enter 0 to exit or 1 to go to menu?
Thank you very much
Hope to get your solution soon and thank you