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 getUserChoice and then also calls getTwoFloats one after another.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
Get step-by-step solutions from verified subject matter experts
