Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?

Read Post

Java

Moderators: zibadian
Number of threads: 6703
Number of posts: 16399

This Forum Only
Post New Thread

Report
arrays: need help ugently Posted by bsbow3 on 18 May 2008 at 2:02 AM
this is what i nees to do:

Write a text menu-based program to allow a user to continually select from the following options:
a. Store up to a maximum of 20 integers in an array. Enter numbers until the sentinel value -
99 is entered. Be sure to warn the user if they attempt to enter too many numbers. [2 marks]
b. Print out all the values in the array. [1 mark]
c. Search for a specified number in the array. If the number is found, print, “The number
<insert number> is found”, otherwise print, “The number <insert number> is not found”. [2
marks]
d. Remove a number from the array. If the number is found, print, “The number <insert
number> has been removed” and move elements to get rid of the “space” in the array. Print
out an appropriate message if the number is not found. [3 marks]
e. Set all cells in the array to contain the same user-specified number. [1 mark]
f. Calculate the average of the numbers in the array. [1 mark]
g. Quit the program. [hurdle]

import java.util.*;

public class numbers
{
 /****************************************************************/
 public static void main(String args[])
 {
 // instance variables - replace the example below with your own
      int[] numbers ;
      char choice;
      

    /**
     * Constructor for objects of class numbers
     */
    
        // initialise instance variables
        Scanner scan = new Scanner(System.in);
        numbers = new int [20];
        
        
        System.out.println("---------------------------------MENU----------------------------------");
        System.out.println("                             [1] store                                 ");
        System.out.println("                             [2] print                                 ");
        System.out.println("                             [3] search                                ");
        System.out.println("                             [4] remove                                ");
        System.out.println("                             [5] set                                   ");
        System.out.println("                             [6] calculate                             ");
        System.out.println("                             [7] qiut                                  ");
        System.out.println("-----------------------------------menu--------------------------------");
        System.out.print("Enter your Choice:");
        choice = scan.next().charAt(0);
        
           if (choice == '1')
                          {
                            
                            System.out.println("enter the numbers");
                             int number = scan.nextInt();
                               for (int i = 0; i <numbers.length; i++) {
                                       //System.out.println("  - " + numbers[i]);
                                      }
                             
                            
                            
                            }  
                         else if (choice == '2')
                        {
                            
                           System.out.print("Original contents: "); 
                           //System.out.println("  - " + numbers[i]);                
                            
                            }
                         else if (choice == '3')
                        {
                           
                           
                            }
                         else if (choice == '4')
                        {
                            
                             
                            }
                         else if (choice == '5')
                        {
                           
                           
                            }
                         else if (choice == '6')
                        {
                            
                            
                             
                            }
                         else if (choice == '7')
                               
                           {                                                        
                                     
                             System.out.println('\t' + "Thanx , have a lovely day");      
                           System.exit(0);             
                                                         
                            }
                                                                                                            
                       

        
    }

    
}

Reply
Report
Re: arrays: need help ugently Posted by zibadian on 19 May 2008 at 1:23 PM
: this is what i nees to do:
:
: Write a text menu-based program to allow a user to continually
: select from the following options:
: a. Store up to a maximum of 20 integers in an array. Enter numbers
: until the sentinel value -
: 99 is entered. Be sure to warn the user if they attempt to enter too
: many numbers. [2 marks]
: b. Print out all the values in the array. [1 mark]
: c. Search for a specified number in the array. If the number is
: found, print, “The number
: <insert number> is found”, otherwise print, “The number <insert
: number> is not found”. [2
: marks]
: d. Remove a number from the array. If the number is found, print,
: “The number <insert
: number> has been removed” and move elements to get rid of the
: “space” in the array. Print
: out an appropriate message if the number is not found. [3 marks]
: e. Set all cells in the array to contain the same user-specified
: number. [1 mark]
: f. Calculate the average of the numbers in the array. [1 mark]
: g. Quit the program. [hurdle]
:
:
: import java.util.*;
: 
: public class numbers
: {
:  /****************************************************************/
:  public static void main(String args[])
:  {
:  // instance variables - replace the example below with your own
:       int[] numbers ;
:       char choice;
:       
: 
:     /**
:      * Constructor for objects of class numbers
:      */
:     
:         // initialise instance variables
:         Scanner scan = new Scanner(System.in);
:         numbers = new int [20];
:         
:         
:         System.out.println("---------------------------------MENU----------------------------------");
:         System.out.println("                             [1] store                                 ");
:         System.out.println("                             [2] print                                 ");
:         System.out.println("                             [3] search                                ");
:         System.out.println("                             [4] remove                                ");
:         System.out.println("                             [5] set                                   ");
:         System.out.println("                             [6] calculate                             ");
:         System.out.println("                             [7] qiut                                  ");
:         System.out.println("-----------------------------------menu--------------------------------");
:         System.out.print("Enter your Choice:");
:         choice = scan.next().charAt(0);
:         
:            if (choice == '1')
:                           {
:                             
:                             System.out.println("enter the numbers");
:                              int number = scan.nextInt();
:                                for (int i = 0; i <numbers.length; i++) {
:                                        //System.out.println("  - " + numbers[i]);
:                                       }
:                              
:                             
:                             
:                             }  
:                          else if (choice == '2')
:                         {
:                             
:                            System.out.print("Original contents: "); 
:                            //System.out.println("  - " + numbers[i]);                
:                             
:                             }
:                          else if (choice == '3')
:                         {
:                            
:                            
:                             }
:                          else if (choice == '4')
:                         {
:                             
:                              
:                             }
:                          else if (choice == '5')
:                         {
:                            
:                            
:                             }
:                          else if (choice == '6')
:                         {
:                             
:                             
:                              
:                             }
:                          else if (choice == '7')
:                                
:                            {                                                        
:                                      
:                              System.out.println('\t' + "Thanx , have a lovely day");      
:                            System.exit(0);             
:                                                          
:                             }
:                                                                                                             
:                        
: 
:         
:     }
: 
:     
: }
: 
:
:
No-one is going to make your assignments for you. Please show some code to show that you have worked on it. Also ask more specific questions based on the code you wrote and have problems with.
Reply




corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.