Question

package Lab09; public class Lab09Driver { public static void main(String[] args) { new Lab09Driver(); } public...

package Lab09;
public class Lab09Driver {
    public static void main(String[] args) {
        new Lab09Driver();
    }
    public Lab09Driver() {
        Scanner input = new Scanner(System.in);
        System.out.println("Would you like to load a previous file? (Y/N)");
        String.choice = input.nextLine().trim().toUpperCase();

        if (choice.charAt(0) == 'Y') {
            System.out.println("Enter the name of the file that you want to load:");
            String.fileName = input.nextLine();
            try {
                Scanner fileInput = new Scanner(new File(fileName));
                while(fileInput.hasNextLine()){
                    String answer = fileInput.nextLine();
                    System.out.println(answer);
                }fileInput.close();

            } catch (FileNotFoundException e) {
                System.out.println("Could not find the file, and the program is exiting");
                System.exit(0);
            }
        } else {
            String[] questions = {
                    "How old are you?",
                    "What city were you born in?",
                    "What is your favorite pets name?",
                    "What color are your eyes?",
                    "What is your mother's first name?",
                    "What is your favorite sport?",
                    "Do you have any siblings?"};
            PrintStream pStream = null;
            try {
                File outFile = new File("myFile.txt");
                FileOutputStrem fos = new FileOutputStream(outFile);
                pStream = new PrintStream(fos);
                for (String.question : questions) {
                    System.out.println(question);
                String answer = input.nextLine();
                pStrem.println(answer);
            }
            }catch (FileNotFounderException e) {
                e.printStackTrack();
            } finally {
                pStream.close();
            }
            }
        }
    }

What I have to do to fix this program
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Lab09Driver {
    public static void main(String[] args) {
        new Lab09Driver();
    }

    public Lab09Driver() {
        Scanner input = new Scanner(System.in);
        System.out.println("Would you like to load a previous file? (Y/N)");
        String choice = input.nextLine().trim().toUpperCase();

        if (choice.charAt(0) == 'Y') {
            System.out.println("Enter the name of the file that you want to load:");
            String fileName = input.nextLine();
            try {
                Scanner fileInput = new Scanner(new File(fileName));
                while (fileInput.hasNextLine()) {
                    String answer = fileInput.nextLine();
                    System.out.println(answer);
                }
                fileInput.close();

            } catch (FileNotFoundException e) {
                System.out.println("Could not find the file, and the program is exiting");
                System.exit(0);
            }
        } else {
            String[] questions = {
                    "How old are you?",
                    "What city were you born in?",
                    "What is your favorite pets name?",
                    "What color are your eyes?",
                    "What is your mother's first name?",
                    "What is your favorite sport?",
                    "Do you have any siblings?"};
            PrintStream pStream = null;
            try {
                File outFile = new File("myFile.txt");
                FileOutputStream fos = new FileOutputStream(outFile);
                pStream = new PrintStream(fos);
                for (String question : questions) {
                    System.out.println(question);
                    String answer = input.nextLine();
                    pStream.println(answer);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                pStream.close();
            }
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
package Lab09; public class Lab09Driver { public static void main(String[] args) { new Lab09Driver(); } public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem: Use the code I have provided to start writing a program that accepts a large...

    Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {...

    import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {        String name;        String answer;        int correct = 0;        int incorrect = 0;        Scanner phantom = new Scanner(System.in);        System.out.println("Hello, What is your name?");        name = phantom.nextLine();        System.out.println("Welcome " + name + "!\n");        System.out.println("My name is Danielle Brandt. "            +"This is a quiz program that...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25);...

    import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5);    Scanner keyboard = new Scanner(System.in);    int i = 0; int total = 0;    while(true){    i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue();    dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • import java.io.*; import java.util.Scanner; public class CrimeStats { private static final String INPUT_FILE = "seattle-crime-stats-by-1990-census-tract-1996-2007.csv"; private...

    import java.io.*; import java.util.Scanner; public class CrimeStats { private static final String INPUT_FILE = "seattle-crime-stats-by-1990-census-tract-1996-2007.csv"; private static final String OUTPUT_FILE = "crimes.txt"; public static void main(String[] args) { int totalCrimes = 0; // read all the rows from the csv file and add the total count in the totalCrimes variable try { Scanner fileScanner = new Scanner(new File(INPUT_FILE)); String line = fileScanner.nextLine(); // skip first line while (fileScanner.hasNext()) { String[] tokens = fileScanner.nextLine().split(","); if (tokens.length == 4) { totalCrimes +=...

  • make this program run import java.util.Scanner; public class PetDemo { public static void main (String []...

    make this program run import java.util.Scanner; public class PetDemo { public static void main (String [] args) { Pet yourPet = new Pet ("Jane Doe"); System.out.println ("My records on your pet are inaccurate."); System.out.println ("Here is what they currently say:"); yourPet.writeOutput (); Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the correct pet name:"); String correctName = keyboard.nextLine (); yourPet.setName (correctName); System.out.println ("Please enter the correct pet age:"); int correctAge = keyboard.nextInt (); yourPet.setAge (correctAge); System.out.println ("Please enter the...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • public class SquareTest {    public static void main(String[] args) {               System.out.println("Number...

    public class SquareTest {    public static void main(String[] args) {               System.out.println("Number of sides is " + Square.NUM_OF_SIDES);                      Square s1 = new Square(-5.7f);               System.out.println(s1);               s1.setLength(0.001f);        System.out.println(s1.getLength());               s1.setLength(-9999);        System.out.println(s1.getLength());               System.out.println("Number of sides is " + s1.NUM_OF_SIDES);               s1.calculateArea();                            } }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT