Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OK im having a problem i am trying to let a user imput information and i want th

ID: 3641201 • Letter: O

Question

OK im having a problem i am trying to let a user imput information and i want the , to be a delimiter.
Seems like the program just keeps running if i have it scan.useDelimiter(", "); It just does not end

The problem is in the Driver I think i have my class setup right.

How do you do it for this code:
---------------------------------
Class:

/* File name: Person2.java
* Name:
* Date:
* Version 1.2
* Class for AddressBook driver. Sets up a name to be used
* Addes on to the 8.8 by adding address, city, state, and phone number
*/

import java.text.*;

class Person2
{
//Variables
public String fname;
public String lname;
public String address;
public String city;
public String state;
public int zip;
public long phoneNum;
private static DecimalFormat form = new DecimalFormat ("00000");

//Constructor
public Person2()
{
fname = "";
lname = "";
address = "";
city = "";
state = "";
zip = 0;
phoneNum = 0;
}
}



=====================================================

Driver:


/* File name: AddressBook2.java
* Name:
* Date:
* Version 1.5
* Asks user for a name and zip then adds it to a list and when done prints out everyone
* Addes on to the 8.8 by adding address, city, state, and phone number
*/

import java.io.*;
import java.util.*;

public class AddressBook2
{
public static void main(String[] args)
{
String input;
int i = 0;

// Array to hold up to 25 people information
Person2[] people = new Person2[25];

Scanner scan = new Scanner(System.in);

// Some termination of input needs to be given
// I will assume that the input will end with a -1, but this can change if you'd like it to.

System.out.println("Please enter first name, last name, address, city, state, zip, " +
"and phone number, or -1 to end: ");

input = scan.next();
//scan.useDelimiter(", ");

while (!input.equalsIgnoreCase("-1"))
{
people[i] = new Person2();
people[i].fname = input;
people[i].lname = scan.next();
people[i].address = scan.next();
people[i].city = scan.next();
people[i].state = scan.next();
people[i].zip = scan.nextInt();
people[i].phoneNum = scan.nextLong();

i++;
if (i >= 25)
break; // exit loop if we're past 25 people - they won't fit in our array
System.out.println("Please enter first name, last name, address, city, state, zip, " +
"and phone number, or -1 to end: ");
input = scan.next();
}

// Now print all the data - i items
for (int j = 0; j < i; j++)
{
System.out.println("Person " + (j+1));
System.out.println("Name : " + people[j].lname + ", " + people[j].fname);
System.out.println("Address : " + people[j].address);
System.out.println("Location: " + people[j].city + ", " + people[j].state);
System.out.println("Zip : " + people[j].zip);
System.out.println("Phone # : " + people[j].phoneNum);
System.out.println("------------------------------");
}
}
}

Explanation / Answer

The reason why it isn't using the comma as a delimiter is because you commented off the statement scan.useDelimiter(", "); Take away the // and it should work.