Person Name: John Doe
Person Birth Year: 1960
Person Name: Emily Zhang
Person Birth Year: 2007
Student Major: Finance
Person Name: Paul zhang
Person Birth Year: 1970
Instructor Salary: $50,000.00
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at PersonTest.main(PersonTest.java:47)
import java.util.Scanner;
public class PersonTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Person Name: ");
String student_name = scan.nextLine();
System.out.print("Person Birth Year: ");
int student_yearOfBirth = scan.nextInt();
Person p = new Person(student_name, student_yearOfBirth);
scan.nextLine();
System.out.print("Person Name: ");
student_name = scan.nextLine();
System.out.print("Person Birth Year: ");
student_yearOfBirth = scan.nextInt();
scan.nextLine();
System.out.print("Student Major: ");
String student_major = scan.nextLine();
Student s = new Student(student_name, student_yearOfBirth, student_major);
System.out.print("Person Name: ");
String instructor_name = scan.nextLine();
System.out.print("Person Birth Year: ");
int instructor_yearOfBirth = scan.nextInt();
System.out.print("Instructor Salary: ");
int instructor_salary = scan.nextInt();
Instructor i = new Instructor(instructor_name, instructor_yearOfBirth, instructor_salary);
System.out.println(s.toString());
System.out.println(i.toString());
}
}
I do not have your instructor and student classes, So i can not
run and test the code.. But i can explain why you are getting the
error.
The Scanner's class nextInt method expects an integer to be read,
to contain only digits.. no comma and dollar signs.. As you gave
the input as
$50,000.00, it
failed.. What you should do is to give it only digits as the
input.. and it will work fine..
In case, you still want to input the salary with dollar and comma sign, you then need to read it as string first, remove the dollar and comma sign your self, then using Integer.parseInt method, you can convert the string to integer.
hope it helps! let me know if any issues.
Person Name: John Doe Person Birth Year: 1960 Person Name: Emily Zhang Person Birth Year: 2007...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...
How do I record every user Input and then display all of it in the scream. In my code i ask the user for a series of food item, then i ask for the toppings. I need to display every input of food and toppings the user enters. The output must look like this Here is your order <name> Appetizer: [ Wings, Blue cheese, Ranch ] Main Course: [ Hamburger: mushrooms , Advocado ] Dessert: [ Pie: Powder Sugar, Scoop...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in term of its internal structure without changing its external behavior. In this particular example, we have three classes Course, Student, Instructor in addition to Main. All classes are well documented. Read through them to understand their structure. In brief, Course models a course that has a title, max capacity an instructor and students. Instructor models a course instructor who...
1. Import file ReadingData.zip into NetBeans. Also, please
download the input.txt file and store it into an appropriate folder
in your drive.
a) Go through the codes then run the file and write the output
with screenshot (please make sure that you change the location of
the file) (20 points)
b) Write additional Java code that will show the average of all
numbers in input.txt file (10 points)
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.io.*; 1- * @author mdkabir...
write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...
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...