Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
JavaMenuApplication/menu.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
116 lines (98 sloc)
3.35 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class menu { | |
public void printheader() { | |
//Prints first menu display | |
System.out.println("|-------------------------------------|"); | |
System.out.println("| Welcome To My |"); | |
System.out.println("| Menu Application |"); | |
System.out.println("|-------------------------------------|"); | |
System.out.println(); | |
System.out.print("Please press the ENTER key to navigate through the program unless instructed otherwise!"); | |
} | |
public void printoptions() { | |
//Prints available menu options | |
int a; | |
menu menu = new menu(); | |
do { | |
//Do-While loop for repeated return to the option menu | |
System.out.println("1. Use option 1 to determine the accuracy of option 2 & 3."); | |
System.out.println(); | |
System.out.println("2. Use option 2 to solve a quadratic equation."); | |
System.out.println(); | |
System.out.println("3. Use option 3 to solve a linear equation."); | |
System.out.println(); | |
System.out.println("3. Use option 4 to bubble sort your student ID number."); | |
System.out.println(); | |
System.out.println("4. Use option 5 to convert seconds into hours, minutes, seconds."); | |
System.out.println(); | |
System.out.println("5. Use option 6 to exit the program."); | |
Scanner input = new Scanner(System.in); | |
//User to input their option choice | |
System.out.println(); | |
System.out.print("Please choose an option: "); | |
a = input.nextInt(); | |
System.out.println(); | |
optionMethods function = new optionMethods(); | |
switch(a) { | |
//Switch to call different methods depending on user option input | |
case 1: | |
System.out.println("You have picked option 1."); | |
System.out.println(); | |
function.accuracy(); | |
break; | |
case 2: | |
System.out.println("You have picked option 2."); | |
System.out.println(); | |
function.equation(); | |
break; | |
case 3: | |
System.out.println("You have picked option 3."); | |
System.out.println(); | |
function.linerEquation(); | |
break; | |
case 4: | |
System.out.println("You have picked option 4."); | |
System.out.println(); | |
function.bubblesort(); | |
break; | |
case 5: | |
System.out.println("You have picked option 5."); | |
System.out.println(); | |
function.seconds(); | |
break; | |
case 6: | |
function.exit(); | |
break; | |
default: | |
//Error message when user inputs invalid option choice | |
System.out.println("ERROR - This is not a valid entry, please use the navigation to try again."); | |
menu.showNextStep(); | |
menu.printoptions(); | |
} | |
System.out.println(); | |
System.out.println("Please use the navigation to return to the menu"); | |
menu.showNextStep(); | |
//instructions on how to return to option menu | |
} while(a < 6); | |
//Close of loop with condition | |
} | |
public void showNextStep() { | |
// Method used to navigate to next section using the ENTER key | |
Scanner input = new Scanner(System.in); | |
Boolean validNavigation = false; | |
//declaring boolean to be used to create condition for do-while loop | |
do { | |
String space = input.nextLine(); | |
String answer = " "; | |
if(0 < space.length()) { | |
System.out.println(); | |
System.out.println("ERROR - You need to use the ENTER Key for navigation, please try again."); | |
validNavigation = false; | |
//Using if statement to set condition for error message to executed | |
} | |
else | |
validNavigation = true; | |
//Changing value of boolean to terminate loop | |
} while(!validNavigation); | |
} | |
} | |