Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class LetterPattern{
- /*
- To hold the pattern, its features, and the letter
- it represents. If the pattern does not match any
- of the letter specifications, then the letter char
- is a blank.
- */
- int[][] grid;
- int
- massbottom,
- corners,
- tees;
- char
- letter;
- // default constructor
- // grid will be created as a 12x12 array of 0's
- // the integer data members are initialized to 0
- // by default already; letter is set to ' '
- public LetterPattern(){
- grid = new int[12][12];
- letter = ' ';
- }
- /*
- precondition: assumes sc is not null and has a least one
- more line of text in it.
- postcondition: grid is loaded with 0's and 1's according to
- the discussion in the project description, and the
- feature loaded with their correct values for the pattern,
- and if the features correspond to one of the given letters,
- letter will be assigned the one they match; if the features
- don't match any of the letters, then letter will be assigned
- the blank character.
- YOU HAVE TO CODE THIS.
- */
- public void loadPattern(Scanner sc){
- //create the new 10 array
- int [][] gridTwo = new int [10][10];
- //loop through through grid
- for (i=0; i<10; i++){
- for (j=0; j<10; j++){
- //setting the values to 0, resetting it
- grid [i][j] = 0;
- }//end loop for j
- }//end loop for i
- //while there is a next line to read
- While (sc.hasnextLine){
- //read it in
- String s = sc.nextLine()
- //save as a string
- Char[]str = s.ToArray;
- //if it reads in a dollar sign
- if (s == $){
- While(stop)//stop the loop
- }//end loop
- }
- }
- // getter functions for the massbottom, tees, corners, and
- // the matching letter
- public int getMassbottom(){ return massbottom;}
- public int getCorners(){ return corners;}
- public int getTees(){ return tees;}
- public char getLetter(){ return letter;}
- /*
- precondition: grid has been loaded and the features for it
- extracted into massbottom, corners, and tees.
- postcondition: letter is assigned to be the upper case version
- of the letter that matches the features, if there is a match,
- or the blank character, if there is no match.
- YOU HAVE TO CODE THIS.
- */
- private void assignLetter(){
- }
- /*
- This main can be used to obtain your output.
- It sets up a Scanner instance and a LetterPattern instance,
- and repeatedly loads the LetterPattern from the Scanner and
- analyzes it. It displays the results to the monitor.
- */
- public static void main(String[] args){
- Scanner src;
- LetterPattern lp = new LetterPattern();
- int
- patternNumber = 1,
- lpCorners,
- lpMassbottom,
- lpTees;
- char
- matchingLetter;
- if (args.length > 0){
- try{
- src = new Scanner(new File(args[0]));
- while (src.hasNextLine()){
- lp.loadPattern(src);
- System.out.println("Results for pattern# " +
- patternNumber);
- System.out.println("Massbottom = " + lp.getMassbottom()
- + " Num of Corners = " + lp.getCorners() +
- " Num of Tees = " + lp.getTees());
- matchingLetter = lp.getLetter();
- System.out.print("These feature values ");
- if (matchingLetter == ' ')
- System.out.println("do not match"
- + " any letter.");
- else
- System.out.println("match " + matchingLetter);
- patternNumber++;
- }
- }
- catch(NullPointerException e){
- System.out.println("The file name was a null string.\nProgram Terminating.");
- }
- catch(FileNotFoundException e){
- System.out.println("No file with the name " + args[0]
- + "\nProgram terminating.");
- }
- }
- else // args is empty
- System.out.println("You must supply the input file name on"
- + " the command line.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement