Why am I getting input mismatch Exception in Java? public class Person { private String name; private
Fantastic news! We've Found the answer you've been seeking!
Question:
Why am I getting input mismatch Exception in Java?
public class Person { private String name; private String address; private int phoneNum; public Person(String name, String address, int phoneNum) { this.name = name; this.address = address; this.phoneNum = phoneNum; } public Person(){ } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getPhoneNum() { return phoneNum; } public void setPhoneNum(int phoneNum) { this.phoneNum = phoneNum; }}
public class Customer extends Person { int CustomerNum; boolean mailingList; public Customer(int customerNum, boolean mailingList) { CustomerNum = customerNum; this.mailingList = mailingList; } public Customer(){ } public int getCustomerNum() { return CustomerNum; } public void setCustomerNum(int customerNum) { CustomerNum = customerNum; } public boolean isMailingList() { return mailingList; } public void setMailingList(boolean mailingList) { this.mailingList = mailingList; }}
import java.util.Scanner;public class CustomerDemo{ public static void main(String args[]){ //Create a Scanner object to receive user input Scanner sc = new Scanner(System.in); Customer customer1 = new Customer(); System.out.println("Enter customer Name: "); customer1.setName(sc.nextLine()); System.out.println("Enter customer Address: "); customer1.setAddress(sc.nextLine()); System.out.println("Enter customer Telephone Number: "); customer1.setPhoneNum(sc.nextInt()); System.out.println("Enter CustID: "); customer1.setCustomerNum(sc.nextInt()); //Display Customer Report System.out.println("Cust Name:" + customer1.getName()); System.out.println("CustID: " + customer1.getCustomerNum()); System.out.println("Telephone Number: " + customer1.getPhoneNum()); System.out.println("Mail List Status: " + customer1.isMailingList()); }}
Posted Date: