Question: Now, create a new public class. Add both the methods from 6.1 and 6.2 into this file. Write the main method which calls getUserChoice and

 Now, create a new public class. Add both the methods from
6.1 and 6.2 into this file. Write the main method which calls Now, create a new public class. Add both the methods from 6.1 and 6.2 into this file. Write the main method which calls getUserChoice and then also calls getTwoFloats one after another.
Note: Create the scanner and float array in main method, and pass scanner to getUserChoice, and pass same scanner and the array to getTwoFloats. After the getTwoFloats is called the array will have two floats and can be used to display the data like this:
Welcome to sorting program
1. Title
2. Rank
3. Date
4. Stars
5. Like
Enter your choice between 1 and 5 only: ;f af afa
You have entered an invalid choice. Try again.
Enter your choice between 1 and 5 only: 4
You entered valid choice 4
Thank you for giving your choice
Welcome to bonus get two floats program
Enter two floats separated by a space: as fas fas fa You have entered an invalid input. Try again.
Enter two floats separated by a space: 12 2
You entered 12.00 and 2.00 successfully!
Press enter key to continue ...

GetUserChoiceandTwofloats. avat a r Choice Javado Declaration gewoo n getUserChoiceStatieve le import java.util.Scanner; 2 import java.util. Input MisnatchException; 4 public class GetUserChoiceandTwoFloats { 6e public static int getUserChoice() { int choice: Scanner in new Scanner(System.in); System.out.println("Welcome to sorting programin 1. Title " 2. Rankin 3. Date . 4. Stars " + 5. Like "); while (true) try System.out.print("Enter your choice between 1 and 5 choice = in.nextInt(); if (choice > 1M choice o 5) break; only: "); } catch (Exception e) { in.nextLine(); System.out.println("You have entered an invalid choice. Try again."); System.out.println(" You entered valid choicechoice); System.out.println("Thank you for giving your choice"); return choice! public static void main(String llargs) { getUserChoice(); 3. public static floatll get TwoFloats() { Scanner read Input = new Scanner(System.in); float myFloat1 @.@f; float myFloat2 of: System.out.print(" Welcome to get two floats program "); do { // loop until we have correct input System.out.print("Enter two floats separated by space : "); myFloati readInput.nextFloat(); Il waits for user input myFloat2 = readInput.nextFloat(); try Console minated UserChoiceandwefloats Java Application Library Cava/JavaVirtual Machinesdk-13.0.1.dk/Contents/Home/binyjava (Feb 18, 2020, 8-33-21 PM getUserChoice(): Thinn mi public static float(l get TwoFloats() { Scanner readinput = new Scanner(System.in); float myFloat1 = 0.0f; float myFloat2 = 0.0f; System.out.print(" Welcome to get two floats program "); do { // loop until we have correct input System.out.print("Enter two floats separated by space : "); try { myFloat1 = read Input.nextFloat(); // waits for user input myFloat2 = read Input.nextFloat(); // waits for user input break: } catch (final InputMismatchException e) { System.out.println("You have entered an invalid input. Try again."); readInput.nextLine(); //discard non float input continue; // keep looping until you found right one } while (true); return new float [] {myFloati, myFloat2): n n 59 60 61 63 64 public static void main(String[] args) { float ll data getTwoFloats(); float myFloat1 = data[@: float myFloat2 = data[1]: System.out.println(" You enter two valid floats: " + myFloat1 + " and " + myFloat2); System.out.println("Thank you for giving two floats"); 67 69 70 71 72 Console x terminated GetUserChoiceandTwoFloats (Java Application/Library/Java/Java Virtual Machines/jdk-13.0.1.dk/Contents/Home/birjava (Feb 18, 2020, 8:33:21 PM) welcome to get two floats program Enter two floats separated by space : 2.4 2.6 114M of 256MB

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!