Results 1 to 9 of 9
  1. #1
    weps is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default programming challenge - calculator display

    input : 1 123 // where 1 = number of "-" &"|"
    2 123 // where 123 will be the target of the generated new form
    0 0 // where 0 ends program
    output
    - -
    | | |
    - -
    | | |
    - -
    -- --
    | | |
    | | |
    -- --
    | | |
    | | |
    -- --

    problem & expl
    -until now i have been able to generate the new form but only one line of input at a time ... can't deal with multiple lines as i intented.
    -i used a master array for output
    -plz expl won't be sufficient ... if any1 could code it...

    Java Code:
    import java.util.*;
    class Trial {
    
        public static void main(String[] args) 
        {
            
            
            
            Scanner input = new Scanner(System.in);
            int x =input.nextInt();
            
            
            int w = input.nextInt(); 
            String cvt = Integer.toString(w);
            int y = cvt.length();
            int z = (2*x)+3;
            int b = x+3;
            
            String [][] div    = new String [z][y *(b)];
            String [][] array1 = new String [z][(b)]   ;
            String [][] array2 = new String [z][b]     ;
            String [][] array3 = new String [z][(b)]   ;
            String [][] array4 = new String [z][b]     ;
            String [][] array5 = new String [z][(b)]   ;
            String [][] array6 = new String [z][b]     ;
            String [][] array7 = new String [z][(b)]   ;
            String [][] array8 = new String [z][b]     ;
            String [][] array9 = new String [z][(b)]   ;
            
             
                   for(int i=0;i<z;i++)
             {
               for(int j=0;j<(b);j++)
               { 
                 String weps = " ";  
                 array1[i][j] = weps;
                array2[i][j] = weps;
               
                array3[i][j] = weps;
                array4[i][j] = weps;
                array5[i][j] = weps;
                array6[i][j] = weps;
                array7[i][j] = weps;
                array8[i][j] = weps;
                array9[i][j] = weps;
               }
             }
            
                   
                   //         //number 7  
                   
             int r2;
             for (r2=0;r2<x;r2++){
             array7[0][r2+1] = "-" ;
             } 
                   
             int u1;
             for (u1=0;u1<x;u1++){
             array7[u1+1][b-2] = "|" ;
             }    
               int u13;
             for (u13=0;u13<x;u13++){
             array7[u13+x+2][b-2] = "|" ;
             } 
              
              
                   
              
              
                     
             //number 3  
                   
             int r21;
             for (r21=0;r21<x;r21++){
             array3[0][r21+1] = "-" ;
             } 
                   
             int u16;
             for (u16=0;u16<x;u16++){
             array3[u16+1][b-2] = "|" ;
             }    
               int t2;
             for (t2=0;t2<x;t2++){
             array3[0+x+1][t2+1] = "-" ;
             } 
             
             int u17;
             for (u17=0;u17<x;u17++){
             array3[u17+x+2][b-2] = "|" ;
             } 
              
              int a1;
             for (a1=0;a1<x;a1++){
             array3[1+x+1+x][a1+1] = "-" ;
             } 
              
                   
                   
                   
                   
                   
           
             //number 1   
             int u1a;
             for (u1a=0;u1a<x;u1a++){
             array1[u1a+1][b-2] = "|" ;
             }    
              
             int u1b;
             for (u1b=0;u1b<x;u1b++){
             array1[u1b+x+2][b-2] = "|" ;
             } 
    
                   
                 
             //number 4   
              int u12;
             for (u12=0;u12<x;u12++){
             array4[u12+1][b-2] = "|" ;
             }   
             int u123;
             for (u123=0;u123<x;u123++){
             array4[u123+1][0] = "|" ;
             }  
               int t23;
             for (t23=0;t23<x;t23++){
             array4[0+x+1][t23+1] = "-" ;
             }     
             int u124;  
             for (u124=0;u124<x;u124++){
             array4[u124+x+2][b-2] = "|" ;
             }     
              
                   
                   
                   
                   
              
                     
             //number 5  
                   
             int r2a;
             for (r2a=0;r2a<x;r2a++){
             array5[0][r2a+1] = "-" ;
             } 
                   
             int u1bb;
             for (u1bb=0;u1bb<x;u1bb++){
             array5[u1bb+1][0] = "|" ;
             }    
               int t2b;
             for (t2b=0;t2b<x;t2b++){
             array5[0+x+1][t2b+1] = "-" ;
             } 
             for (u1=0;u1<x;u1++){
             array5[u1+x+2][b-2] = "|" ;
             } 
              
              int a1b;
             for (a1b=0;a1b<x;a1b++){
             array5[1+x+1+x][a1b+1] = "-" ;
             }      
                   
                   
                   
                   
                   
                   
                     
             //number 8  
                   
             int r2b;
             for (r2b=0;r2b<x;r2b++){
             array8[0][r2b+1] = "-" ;
             } 
                   
             int u1j;
             for (u1j=0;u1j<x;u1j++){
             array8[u1j+1][0] = "|" ;
             }   
             
             int u11;
             for (u11=0;u11<x;u11++){
             array8[u11+1][b-2] = "|" ;
             } 
             
               int t2j;
             for (t2j=0;t2j<x;t2j++){
             array8[0+x+1][t2j+1] = "-" ;
             } 
             
             int u1y;
             for (u1y=0;u1y<x;u1y++){
             array8[u1y+x+2][b-2] = "|" ;
             } 
              int u112;
             for (u112=0;u112<x;u112++){
             array8[u112+x+2][0] = "|" ;
             }  
             
             
              int a11;
             for (a11=0;a11<x;a11++){
             array8[1+x+1+x][a11+1] = "-" ;
             }      
                       
                     
             //number 9  
                   
             int r2k;
             for (r2k=0;r2k<x;r2k++){
             array9[0][r2k+1] = "-" ;
             } 
                   
             int u1l;
             for (u1l=0;u1l<x;u1l++){
             array9[u1l+1][0] = "|" ;
             }   
             
             int u11f;
             for (u11f=0;u11f<x;u11f++){
             array9[u11f+1][b-2] = "|" ;
             } 
             
               int t2f;
             for (t2f=0;t2f<x;t2f++){
             array9[0+x+1][t2f+1] = "-" ;
             } 
             
             int u1h;
             for (u1h=0;u1h<x;u1h++){
             array9[u1h+x+2][b-2] = "|" ;
             } 
                
             
             
              int a1r;
             for (a1r=0;a1r<x;a1r++){
             array9[1+x+1+x][a1r+1] = "-" ;
             }      
                   
                   
              
                     
             //number 6  
                   
             int r2df;
             for (r2df=0;r2df<x;r2df++){
             array6[0][r2df+1] = "-" ;
             } 
                   
             int u1fd;
             for (u1fd=0;u1fd<x;u1fd++){
             array6[u1fd+1][0] = "|" ;
             }    
               int t2df;
             for (t2df=0;t2df<x;t2df++){
             array6[0+x+1][t2df+1] = "-" ;
             } 
             
             int u1as;
             for (u1as=0;u1as<x;u1as++){
             array6[u1as+x+2][b-2] = "|" ;
             } 
             
              int u11as;
             for (u11as=0;u11as<x;u11as++){
             array6[u11as+x+2][0] = "|" ;
             }  
             
              int a1sa;
             for (a1sa=0;a1sa<x;a1sa++){
             array6[1+x+1+x][a1sa+1] = "-" ;
             }      
                   
                   
                      
                   
                   
                   
             //number 2   
             int rwer;
             for (rwer=0;rwer<x;rwer++){
             array2[0][rwer+1] = "-" ;
             } 
             
             int uwer;
             for (uwer=0;uwer<x;uwer++){
             array2[uwer+1][b-2] = "|" ;
             }    
               
             int twer;
             for (twer=0;twer<x;twer++){
             array2[0+x+1][twer+1] = "-" ;
             } 
             
               int swer;
             for (swer=0;swer<x;swer++){
             array2[swer+x+2][0] = "|" ;
             }   
             
              int awer;
             for (awer=0;awer<x;awer++){
             array2[1+x+1+x][awer+1] = "-" ;
             } 
             
      
    
        //filling container                
            
          for(int n=0;n<y;n++){   //to point to y later
             for(int i=0;i<z;i++)
             {
               for(int j=0; j<b ;j++)
               { 
                   
                    
                    
                    
                    if (cvt.charAt(n) == '1') {
            div[i][j+(n*b)] = array1[i][j];
          }
          
            
                    else if (cvt.charAt(n) == '3') {
            div[i][j+(n*b)] = array3[i][j];
          } 
                    else if (cvt.charAt(n) == '4') {
            div[i][j+(n*b)] = array4[i][j];
          } 
                    else if (cvt.charAt(n) == '5') {
            div[i][j+(n*b)] = array5[i][j];
          } 
                    else if (cvt.charAt(n) == '6') {
            div[i][j+(n*b)] = array6[i][j];
          } 
                    else if (cvt.charAt(n) == '7') {
            div[i][j+(n*b)] = array7[i][j];
          } 
                    else if (cvt.charAt(n) == '8') {
            div[i][j+(n*b)] = array8[i][j];
          } 
                    else if (cvt.charAt(n) == '9') {
            div[i][j+(n*b)] = array9[i][j];
          }       else if (cvt.charAt(n) == '2') {
            div[i][j+(n*b)] = array2[i][j];
          } 
                  
                        
          } 
          
                    }
                 
    
               }
          
          for(int i=0;i<z;i++)
             {
               for(int j=0;j< y *(b);j++)
               {
                 System.out.print(div[i][j]);
               }
               //move to new line
               System.out.print("\n");
             }
             } 
            
    }
    Last edited by sunde887; 09-16-2011 at 02:49 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,355
    Blog Entries
    7
    Rep Power
    20

    Default Re: programming challenge - calculator display

    And what is the challenge?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    weps is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: programming challenge - calculator display

    an error occured when i posted the above post its suppose to be like this(see attchment) programming challenge - calculator display-java.jpg
    Attached Thumbnails Attached Thumbnails programming challenge - calculator display-java.jpg  
    Last edited by weps; 09-16-2011 at 10:41 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: programming challenge - calculator display

    Can you explain what the problem is?

  5. #5
    weps is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: programming challenge - calculator display

    -the problem is that i only managed to accept 1 line of input at a time when the requirement is to accept input till the user input the number "0".
    -the main prob is that i used a master array for diaplay and have problem reinitialised it each time user input a new input line which is -- > 3 123 // which prints 123 with 3 "-"&"|" ... see the above picture plz...

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: programming challenge - calculator display

    the requirement is to accept input till the user input the number "0".
    That sounds like you need a loop that continues to get input from the user until he enters a "0".
    problem reinitialised it each time user input a new input line which is -- > 3 123 // which prints 123 with 3 "-"&"|"
    Can you show what you mean here?
    If the user inputs: 3 123
    what is the program supposed to do?

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  7. #7
    weps is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: programming challenge - calculator display

    programming challenge - calculator display-java.jpg here it is visually

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: programming challenge - calculator display

    If you want to allow the user to enter more data, you need to wrap your code in a loop.
    Pseudo code:
    begin loop
    get user input
    if 0 then exit loop
    display the output
    end loop

    If you want to get all of the user's input before displaying any output, you will need two loops:
    one to gather the input and save it.
    two to go through the saved input and display it
    Last edited by Norm; 09-16-2011 at 06:59 PM.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

Similar Threads

  1. Challenge!
    By pruttohutto in forum Forum Lobby
    Replies: 2
    Last Post: 04-28-2010, 04:15 PM
  2. Simple Calculator Display Problem :(
    By jimbob in forum Java Applets
    Replies: 4
    Last Post: 07-18-2009, 04:13 AM
  3. Replies: 0
    Last Post: 04-19-2009, 06:38 PM
  4. java programming challenge Number 1
    By tacosalad in forum New To Java
    Replies: 5
    Last Post: 01-16-2008, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •