Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Nate Wheeler
- * Date: sept 30,2016
- * Course Number: csc220
- * Course Name: data structures
- * Problem Number: hw 3
- * Email: nate23nate23@gmail.com
- * Short Description of the Problem:
- * You are asked to write a JAVA program that
- * takes an array containing the digitized
- * picture of the night sky and locate the star(s) in it.
- */
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class StarGazer {
- private static void process(Scanner sc, String args[]) {
- int starData[][] = getStarData(sc);
- //System.out.print(" "+starData[0][0]+" ");
- //System.out.print(" "+starData[7][7]+" ");
- print(starData);
- System.out.println();
- sc.nextLine(); // IMPORTANT!! Reset Scanner
- //System.out.println("Processing " + + " ...");
- }
- //**********************************************
- private static void print(int[][] starData) {
- // TODO Auto-generated method stub
- for(int i=0;i<starData.length;i++){
- for(int j=0;j<starData[0].length;i++){
- System.out.printf("%5d", starData[i][j]);
- }
- System.out.println();
- }
- }
- private static int[][] getStarData(Scanner sc) {
- // TODO Auto-generated method stub
- int rows = sc.nextInt();
- int cols = sc.nextInt();
- int data[][]= new int[rows][cols];
- for(int i=0; i <rows; i++){
- for(int j=0; j<cols; j++){
- data[i][j]=sc.nextInt();
- }
- }
- return data;
- }
- private static boolean doThisAgain(Scanner sc, String prompt) {
- System.out.print(prompt);
- String doOver = sc.nextLine();
- return doOver.equalsIgnoreCase("Y");
- }
- //**********************************************
- public static void main(String args[]) throws FileNotFoundException {
- final String TITLE = "CSC220 Project Template";
- final String CONTINUE_PROMPT = "Do this again? [y/N] ";
- Scanner sc = new Scanner(new File("StarData.txt"));
- //System.out.println("Welcome to " + TITLE);
- do {
- process(sc, args);
- } while (doThisAgain(sc, CONTINUE_PROMPT));
- sc.close();
- System.out.println("Thank you for using " + TITLE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement