Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.41 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class LetterPattern{
  4. /*
  5.  
  6.     To hold the pattern, its features, and the letter
  7.     it represents.  If the pattern does not match any
  8.     of the letter specifications, then the letter char
  9.     is a blank.
  10.  
  11.  
  12. */
  13.  
  14.    int[][] grid;
  15.    int
  16.       massbottom,
  17.       corners,
  18.       tees;
  19.    char
  20.       letter;
  21.  
  22.    // default constructor
  23.    // grid will be created as a 12x12 array of 0's
  24.    // the integer data members are initialized to 0
  25.    // by default already; letter is set to ' '
  26.    public LetterPattern(){
  27.       grid = new int[12][12];
  28.       letter = ' ';
  29.    }
  30.  
  31.    /*
  32.        precondition: assumes sc is not null and has a least one
  33.           more line of text in it.
  34.  
  35.        postcondition: grid is loaded with 0's and 1's according to
  36.           the discussion in the project description, and the
  37.           feature loaded with their correct values for the pattern,
  38.           and if the features correspond to one of the given letters,
  39.           letter will be assigned the one they match; if the features
  40.           don't match any of the letters, then letter will be assigned
  41.           the blank character.
  42.  
  43.        YOU HAVE TO CODE THIS.
  44.    */
  45.    public void loadPattern(Scanner sc){
  46.    
  47.        //create the new 10 array
  48.        int [][] gridTwo = new int [10][10];
  49.                                
  50.        //loop through through grid
  51.        for (i=0; i<10; i++){
  52.            for (j=0; j<10; j++){
  53.     //setting the values to 0, resetting it
  54.                grid [i][j] = 0;
  55.            
  56.            }//end loop for j
  57.        }//end loop for i
  58.        
  59.        //while there is a next line to read
  60.        While (sc.hasnextLine){
  61.            //read it in
  62.            String s = sc.nextLine()
  63.            //save as a string
  64.            Char[]str = s.ToArray;
  65.            //if it reads in a dollar sign
  66.            if (s == $){
  67.                While(stop)//stop the loop
  68.                
  69.            }//end loop
  70.            
  71.            
  72.            
  73.            
  74.        }
  75.        
  76.        
  77.        
  78.        
  79.        
  80.    
  81.    }
  82.    
  83.    
  84.  
  85.    // getter functions for the massbottom, tees, corners, and
  86.    // the matching letter
  87.    public int getMassbottom(){ return massbottom;}
  88.    public int getCorners(){ return corners;}
  89.    public int getTees(){ return tees;}
  90.    public char getLetter(){ return letter;}
  91.  
  92.    /*
  93.       precondition: grid has been loaded and the features for it
  94.          extracted into massbottom, corners, and tees.
  95.       postcondition: letter is assigned to be the upper case version
  96.         of the letter that matches the features, if there is a match,
  97.         or the blank character, if there is no match.
  98.  
  99.       YOU HAVE TO CODE THIS.
  100.    */
  101.    private void assignLetter(){
  102.    
  103.    
  104.    
  105.    }
  106.  
  107.    /*
  108.       This main can be used to obtain your output.
  109.  
  110.       It sets up a Scanner instance and a LetterPattern instance,
  111.       and repeatedly loads the LetterPattern from the Scanner and
  112.       analyzes it.  It displays the results to the monitor.
  113.    */
  114.    public static void main(String[] args){
  115.  
  116.       Scanner src;
  117.       LetterPattern lp = new LetterPattern();
  118.       int
  119.          patternNumber = 1,
  120.          lpCorners,
  121.          lpMassbottom,
  122.          lpTees;
  123.       char
  124.          matchingLetter;
  125.  
  126.       if (args.length > 0){
  127.          try{
  128.  
  129.             src = new Scanner(new File(args[0]));
  130.  
  131.             while (src.hasNextLine()){
  132.                lp.loadPattern(src);
  133.                
  134.                System.out.println("Results for pattern# " +
  135.                patternNumber);
  136.                System.out.println("Massbottom = " + lp.getMassbottom()
  137.                + " Num of Corners = " + lp.getCorners() +
  138.                " Num of Tees = " + lp.getTees());
  139.                matchingLetter = lp.getLetter();
  140.  
  141.                System.out.print("These feature values ");
  142.                if (matchingLetter == ' ')
  143.                   System.out.println("do not match"
  144.                   + " any letter.");
  145.                else
  146.                   System.out.println("match " + matchingLetter);
  147.  
  148.                patternNumber++;
  149.             }
  150.          }
  151.          catch(NullPointerException e){
  152.             System.out.println("The file name was a null string.\nProgram Terminating.");
  153.          }
  154.          catch(FileNotFoundException e){
  155.             System.out.println("No file with the name " + args[0]
  156.             + "\nProgram terminating.");
  157.          }
  158.       }
  159.       else // args is empty
  160.          System.out.println("You must supply the input file name on"
  161.          + " the command line.");
  162.    }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement