Courses‎ > ‎AP Computer Science 2‎ > ‎Konstantinovich‎ > ‎

2017-02-16

posted Feb 16, 2017, 7:56 AM by Samuel Konstantinovich   [ updated Feb 17, 2017, 7:00 AM ]

Trip forms: print and try to get them signed and handed in by end of Monday, or end of today. The deadline is a hard deadline and if you miss it, that is your fault for waiting until the last minute!

Quiz the Wed after break. 

Extra Credit: 
 Make a folder   EC01/  on your repo.
 Place a copy of your extra credit KnightBoard.java in this folder if you would like it to be graded.
 You must have an additional public method: solveFast().
 If you do not have  EC01/KnightBoard.java , and the method is not named solveFast(), you will not get credit.
 You must find a tour using a much faster method than plain brute force. I will test on boards with sizes between 16 and 50.

Goal: Reminder: Files are useful.

Checked vs. Unchecked exceptions.



import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadFile {
  public static void main(String args[]) throws FileNotFoundException {
        //instead of a try/catch, you can throw the FileNotFoundException.
        File infile = new File("input.txt");// can be a path"/full/path/to/file.txt" 
        Scanner inf = new Scanner(text);
        int lineNumber = 1;
        while(inf.hasNextLine()){
            String line = inf.nextLine();
            System.out.println(line);
        }       
    }   
}

Place this maze into a text file, and read it into 
Maze1.txt
###################################
#   #         #   #   #     # # #E#
# # ### ######### # # # ### # # # #
# # #   #           #   #         #
# # # ### ######### ##### ### ### #
# # # # #   #     #   #     # # # #
### # # ### # # ### # # # ### # ###
#S            #   # # # # #   #   #
###################################

Read it into your program. Print it. 
Then try reading it into an array of characters, and print that.


Comments