Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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()`.
expand button
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
Check Mark
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);
 }
}

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