Advertisement
nate23nate23

hw3 stuck array

Oct 3rd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. /*
  2.  * Name: Nate Wheeler
  3.  * Date: sept 30,2016
  4.  * Course Number: csc220
  5.  * Course Name: data structures
  6.  * Problem Number: hw 3
  7.  * Email: nate23nate23@gmail.com
  8.  * Short Description of the Problem:
  9.  * You are asked to write a JAVA program that
  10.  * takes an array containing the digitized
  11.  * picture of the night sky and locate the star(s) in it.
  12.  */
  13.  
  14.  
  15. import java.io.File;
  16. import java.io.FileNotFoundException;
  17. import java.util.Scanner;
  18.  
  19. public class StarGazer {
  20.    
  21.     private static void process(Scanner sc, String args[]) {
  22.         int starData[][] = getStarData(sc);
  23.         //System.out.print(" "+starData[0][0]+" ");
  24.         //System.out.print(" "+starData[7][7]+" ");
  25.         print(starData);
  26.         System.out.println();
  27.         sc.nextLine();  // IMPORTANT!! Reset Scanner
  28.         //System.out.println("Processing " +  + " ...");
  29.     }
  30.    
  31.     //**********************************************
  32.    
  33.     private static void print(int[][] starData) {
  34.         // TODO Auto-generated method stub
  35.         for(int i=0;i<starData.length;i++){
  36.             for(int j=0;j<starData[0].length;i++){
  37.                 System.out.printf("%5d", starData[i][j]);
  38.             }
  39.             System.out.println();
  40.         }
  41.        
  42.     }
  43.  
  44.     private static int[][] getStarData(Scanner sc) {
  45.         // TODO Auto-generated method stub
  46.         int rows = sc.nextInt();
  47.         int cols = sc.nextInt();
  48.         int data[][]= new int[rows][cols];
  49.         for(int i=0; i <rows; i++){
  50.             for(int j=0; j<cols; j++){
  51.                 data[i][j]=sc.nextInt();
  52.             }
  53.         }
  54.         return data;
  55.     }
  56.  
  57.     private static boolean doThisAgain(Scanner sc, String prompt) {
  58.         System.out.print(prompt);
  59.         String doOver = sc.nextLine();
  60.         return doOver.equalsIgnoreCase("Y");
  61.     }
  62.    
  63.     //**********************************************
  64.    
  65.     public static void main(String args[]) throws FileNotFoundException {
  66.         final String TITLE = "CSC220 Project Template";
  67.         final String CONTINUE_PROMPT = "Do this again? [y/N] ";
  68.        
  69.         Scanner sc = new Scanner(new File("StarData.txt"));
  70.  
  71.         //System.out.println("Welcome to " + TITLE);
  72.         do {
  73.             process(sc, args);
  74.         } while (doThisAgain(sc, CONTINUE_PROMPT));
  75.         sc.close();
  76.         System.out.println("Thank you for using " + TITLE);
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement