Support Forums

Full Version: Java Problem for real java programmer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hey guys ive been working for this code to run for about 7 hours,.. actually it was been half a year after i stop java but now im trying to do this peice of program,..

here is the deal:

MENU:
1. Push(when you enter 1 you should input a single number and and then automatically go back to the , to the menu and then display under the menu the number you input , you can input up to 10 numbers and when you reach 10 it should display that "cannot enter anymore 10 units was already reach")
2.Pop(when you enter 2, the last number you did enter will automatically be delete and then automatically go back again to the menu. )
3. Exit(this is the only time you can exit the program because when you press 1 or 2 it will only go back to the menu after each transaction. )

this is how the menu looks like

1.Push
2.Pop
3.Exit
Input Display:
9
2
6

note: the 9,2, and 6 was just example that if you press 1 then you input 6 and go back to the menu, press 1 again and input 2 go back to the menu again, and then press1 and input 9 and go to menu again

then if you press 2 the 9 will be deleted
and automatically back to the menu and should look like this:

1.Push
2.Pop
3.Exit
Input Display:
2
6

i hope you guys can help me with this,..
.... what? You should re-read what you posted.. and maybe structure your question a little better. I can't make heads or tails of what you're trying to do.
(12-14-2009, 10:35 AM)n00bSaibot Wrote: [ -> ].... what? You should re-read what you posted.. and maybe structure your question a little better. I can't make heads or tails of what you're trying to do.

no need pal, i already did this 3 hours after i post this^_^,..

its just i am thinking to use new functions without thinking that its not that complicated,..

all i need is a do while^_^
In the future be clear about what it is exactly that you want and posting the source never hurts(or parts of it if you want to keep it private). No one can possibly help you when you post threads like this one.
Code:
import javax.swing.JOptionPane;

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

        String inp;
        int cho, input, index;
        int [] number = new int [10];
                input=index=0;            
      
      
      
    do
    {              
              
    inp=JOptionPane.showInputDialog(" Choose number: \n1. Push    \n2. Pop\n 3. Display\n 4. Exit ");
    cho =Integer.parseInt(inp);

    if (cho == 1)
        {
            if (input<10)
            {  
              
                inp=JOptionPane.showInputDialog("Index "+ (input)+(" of 9:"),"");
                number[input]=Integer.parseInt(inp);
                input++;  
              
                JOptionPane.showMessageDialog(null,"                Updated!","Update Message",JOptionPane.INFORMATION_MESSAGE);              
            }
            else
            {
                JOptionPane.showMessageDialog(null," Full\n ","Overflow",JOptionPane.ERROR_MESSAGE);
            }
                  
                              
          
                  
        }
      
    else if (cho==2)
        {
            if (number [0]==0)
            {
                JOptionPane.showMessageDialog(null,"        Input at least 1 first before pressing 2","No Stack",JOptionPane.ERROR_MESSAGE);
            }
      

            else
            {
                number[input-1]=0;
                input--;
              
                JOptionPane.showMessageDialog(null,"                Updated!","Update Message",JOptionPane.INFORMATION_MESSAGE);              
            }
        }  
  
    else if (cho==3)
        {
                    System.out.print("STACK: ");  
      
        for (index=0; index<=9; index++)
            {
              
          
                System.out.print("||"+number[index]+"|| ");
          
          
            }
          
          
                System.out.print("\n");
                System.out.print("INDEX: ");
          
        for (index=0;index<=9;index++)
            {
                System.out.print("||"+index+"|| ");
            }
          
            System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
        }
  
    else if (cho==4)
        {
            JOptionPane.showMessageDialog(null,"                Exit!");
        }
  
  
    else
        {
            JOptionPane.showMessageDialog(null,"               Invalid Input!");
        }  
      
      
                System.out.print("S T A C K:\n");  
      
        for (index=0; index<=9; index++)
            {
                System.out.print("||  "+number[index]+"  \n");
            }
          
              
                System.out.print("\n");
          
          
                System.out.print("I N D E X:\n");  
      
        for (index=0; index<=9; index++)
            {              
            System.out.print("||  "+index+"\n");
            }
          
            System.out.print("\n");
          
      
    }
  
    while(cho!=4);
          
    }
}
this is the code,... before,. but in the last day at the school i do some modification here, like removing some text to make it clean,..
Put it in a code box bro, stops the page from becoming so damn long.

type ["code] at begining of code and ["/code] at the end. Remove the inverted commas ("")
(12-26-2009, 06:06 PM)Extasey Wrote: [ -> ]Put it in a code box bro, stops the page from becoming so damn long.

type ["code] at begining of code and ["/code] at the end. Remove the inverted commas ("")

hahah thanks^_^ actually im in rush when i did that^_^,.. sorry^_^,..
No worries. Just annoying having to scroll for two years, thats all.
(01-01-2010, 02:41 AM)Extasey Wrote: [ -> ]No worries. Just annoying having to scroll for two years, thats all.

lol!!!^_^,..
Judging by the date this was last bumped and the fact it is still on the front page... it seems the Java threads have been quite inactive o_o
Pages: 1 2