After the name, Charlie is printed out it throws the input mismatch exception and says I'm entering a string into the int scanner but it really is a number so why is it telling me it's a string?
This is my textfile that the scanner is reading from: Alice,1234567891,Priority Brandon,1987654321,Senior Charlie,7642874781,Regular Danny,5274847643,Senior
package file reading;
public class Customer {
private String name;
private int phoneNumber;
private int seatNumber;
String classification;
public Customer(String name, int phoneNumber, String classification)
{
this.name = name;
this.phoneNumber = phoneNumber;
this.classification = classification;
}
public String getName() {return name;}
public int getPhoneNumber() {return phoneNumber;}
public int getSeatNumber() {return seatNumber;}
public String getClassification() {return classification;}
public void setName(String name) {this.name = name;}
public void setPhoneNumber(int phoneNumber) {this.phoneNumber = phoneNumber;}
public void setSeatNumber(int seatNumber) {this.seatNumber = seatNumber;}
public void setClassification(String classification) {this.classification = classification;}
public String toString()
{
return "Name: " + name + "\nPhone Number: " + phoneNumber +
" \nclassification: " + classification +"\n";
}
}
package file reading;
import java.util.Scanner;
import java.io.*;
public class URLDissector
{
//-----------------------------------------------------------------
// Reads customer info from a file and prints their path components.
//-----------------------------------------------------------------
public static void main(String[] args) throws IOException
{
String customerInfo;
Scanner fileScan, infoScan;
String name = "", classification = "";
int phoneNumber = 0 ,seatNumber = 0;
try {
fileScan = new Scanner(new File("info.txt"));
while (fileScan.hasNext())
{
customerInfo = fileScan.nextLine();
System.out.println("Customer: " + customerInfo);
infoScan = new Scanner(customerInfo);
infoScan.useDelimiter(",");
// Print each part of the customer info
while (infoScan.hasNext()) {
name = infoScan.next();
//The error is hapening right here, right after printing out the name Charlie it won't
//print the phone number and stops everything.
phoneNumber = infoScan.nextInt();
classification = infoScan.next();
Customer customer = new Customer(name, phoneNumber, classification);
System.out.println("Customer " + customer);
}
System.out.println();
}
}catch (FileNotFoundException f){
System.out.println ("File not found");
}
}
Thank you for reading my question!