Ok, well now this is where I stand. I had my code working fine, but my teacher said she wanted to me to make changes. I made the changes she marked for me, and now I get a bazillion error messages when I try to compile, starting with the error saying I have an else without an if.
Below is my code as she told me it should be. What is going on here?
CODE
import java.util.*;
import java.io.*;
public class Person
{
private String name;
private String phone;
private String email;
public Person()
{
name="";
phone="";
email="";
}
public Person(String n, String p, String e)
{
name=n;
phone=p;
email=e;
}
public boolean readInput()throws IOException
{
Scanner scan=new Scanner(System.in);
boolean flag=true;
System.out.print("Please Enter the person's name or xx to quit: ");
name=scan.nextLine();
if(!name.equals("xx")){
System.out.print("Please Enter a phone number: ");
phone=scan.nextLine();
System.out.print("Please Enter an email address: ");
email=scan.nextLine();
else
flag=false;
}
return flag;
}
public void printInput(int printFileHeading)
{
if(printFileHeading==1)
System.out.println("Your person's info is below:");
System.out.println(name);
System.out.println(phone);
System.out.println(email);
}
public void printFile(PrintWriter outputFile)
{
outputFile.println(name);
outputFile.println(phone);
outputFile.println(email);
}
public void readFile(BufferedReader inputFile)throws IOException
{
name=inputFile.readLine();
while(name!=null) {
phone=inputFile.readLine();
email=inputFile.readLine();
printInput(0);
name=inputFile.readLine();
}
}
}
//NOW COMES MY DRIVER CLASS, WHICH STILL COMPILES FINE
import java.io.*;
import java.util.*;
public class PersonDriver
{
public static String getFileName()
{
Scanner scan=new Scanner(System.in);
String myFile;
System.out.print("Enter the file name and path: ");
myFile=scan.nextLine();
return myFile;
}
public static void main(String [] args)throws IOException
{
Scanner scan=new Scanner(System.in);
String myFile=getFileName();
boolean flag=true;
Person one=new Person();
FileWriter fwriter=new FileWriter(myFile);
PrintWriter outputFile=new PrintWriter(fwriter);
do{
flag=one.readInput();
if(flag==true){
one.printInput(1);
one.printFile(outputFile);
}
}while(flag==true);
outputFile.close();
FileReader freader=new FileReader(myFile);
BufferedReader inputFile=new BufferedReader(freader);
System.out.println("File Info");
one.readFile(inputFile);
inputFile.close();
}
}
Much appreciated as always!