Code with exlanataion:
package menu_Exception;
import java.util.*;
public class Main{
public static void main(String []args){
String keepGoing = "y";
Scanner scan = new Scanner(System.in);
while(keepGoing.equals("y") || keepGoing.equals("Y"))
{
System.out.println("1:Add a student");
System.out.println("2:Remove a student");
System.out.println("3:View a student record");
System.out.println("Your choice?(1/2/3) ");
//add try catch to handle exception
try{
int choice=scan.nextInt();
}
catch (InputMismatchException e)
{
//print invalid choice and call main() function
again
//to input again
System.out.print("Invalid choice.\n\n");
System.out.println("Enter your choice
again...");
main(args);
}
System.out.println("Try again? (y/n) ");
keepGoing = scan.next();
}
System.out.println("Bye");
}
}
-----------------------------------------------------------------------------------------------
Output:
![Main.java X 1 package menu_Exception; 2. 3 import java.util.*; e Console x Main (14) [Java Application] C:\Progra 1: Add a st](http://img.homeworklib.com/questions/979d3480-e6c0-11ea-a25a-933dfa34025e.png?x-oss-process=image/resize,w_560)
{ Question 15 (3 points (Bonus) Given the following statemens, it may throw Input MismatchException. Adding...
Java Im doing a binary search on an array and need to allow as many queries as possible and cannot figure out how to. The output should read something like this. Enter a number. 3 3 is a prime number. Enter another number. 4 4 is not a prime number. Enter another number. 8 Current file not large enough for 8. Enter another number. -1 Bye. My code so far looks like this. public static void main(String[] args) {...
My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...
Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...
Can you help me rearrange my code to make it look cleaner but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...
Hello, I posted the same question a little bit ago and it was answered correctly however I didn't ask it quite correctly so I wanted to post it again asking what I want correctly. Basically the idea of the assignment the user should be able to enter a single word or sentence and it will output all the vowels in the sentence so for example the sentence "I think therefore I am" should print out {1,3,3,1,0} just once, then it...
Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane { // checks customers in and assigns them a boarding pass // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers // public void reserveSeats() { int counter = 0; int section = 0; int choice = 0; String eatRest = ""; //to hold junk in input buffer String inName = ""; ...
Java code is calculating the bill wrong and not displaying currency at the end: I've highlighted the error in the cosole Southwest Power and Light Billing Statement Please enter your name > J, P Customer name:J, P Meter reading date > 2/15/16 Meter reading date:2/15/16 Electricity used: > 225 The basic rate is:22.5 The totalBill is 225.0 Calculate another bill? (Y/N)?: The correct answer should be baseline charge: $22.50 and total bill: $22.50 The Charges are based on these: 0kw...
I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static...
Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...