11. Inside class StaticMethods, create the static method menuInteger that displays a menu for the user to select 1000 , 2000 or 3000 The method returns the INTEGER( int) entered, ONLY when the user types 1000, 2000 or 3000, otherwise prints a message and stays in a loop. Test it from main().

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java Netbeans

11. Inside class StaticMethods, create the static method menuInteger that displays a menu for the
user to select 1000 , 2000 or 3000 The method returns the INTEGER( int) entered, ONLY when
the user types 1000, 2000 or 3000, otherwise prints a message and stays in a loop. Test it from
main().
Transcribed Image Text:11. Inside class StaticMethods, create the static method menuInteger that displays a menu for the user to select 1000 , 2000 or 3000 The method returns the INTEGER( int) entered, ONLY when the user types 1000, 2000 or 3000, otherwise prints a message and stays in a loop. Test it from main().
Expert Solution
Step 1

PROGRAM CODE:

// include the required libraries
import java.util.*;
class StaticMethods
{
    // start definition of menuInteger function
    public static int menuInteger()
    {
        // create object of scanne class
        Scanner scan = new Scanner(System.in);
        int ch;
        // display the Menu
        System.out.println("Menu: ");
        System.out.println("1. 1000");
        System.out.println("2. 2000");
        System.out.println("3. 3000");
        // use loop to iteration
        while(true)
        {
            System.out.println("Enter the integer from menu: ");
            // take the integer value from the user
            ch = scan.nextInt();
            // condition for valid input            
            if(ch==1000 || ch==2000 || ch==3000)
            {
                return ch;
            }
            // condition for invalid input
            else
            {
                System.out.println("Invalid choice");
                continue;
            }
        }
    }
}
public class Main
{
    // start definition of main function
 public static void main(String[] args) 
 {
     // declare the required variables
  int result;
  // create object of the required class
  StaticMethods obj = new StaticMethods();
  // call the function and store the result returned by the function
  result = obj.menuInteger();
  System.out.println("The user entered: "+result);
 }
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education