0

SO I need to make a program to display monthly sales from a file. the files have 10 rows and 8 columns. I created a class that has a constructor that creates a table, merely of the files exact set up. :

public SalesTable(String fileName) {
    Scanner theFile = null;
    try {
        theFile = new Scanner(new File(fileName));
    }
    catch (FileNotFoundException e) {
        System.out.println("File " + fileName + " not found.\n");
        System.exit(1);
    }

    // get variables
    myRows = theFile.nextInt();
    myCols = theFile.nextInt();

    // make table
    table = new int[myRows][myCols];

    for(int r = 0; r < myRows; r++) {
        for(int c = 0; c < myCols; c++) {
            table[r][c] = 0;
        }
    }

    for(int r = 0; r < myRows; r++) {
        for(int c = 0; c < myCols; c++) {
            table[r][c] = theFile.nextInt();
        }
    }
}

Then in main I call it by SalesTable table = new SalesTable(inFile);

My problem is, is that I need to have it display exactly what was created in the table, but I cannot get it to print the actually digits in the array inside the table.

Any idea what I am doing wrong? thank you in advance!

Jose Da Silva Gomes
  • 3,814
  • 3
  • 24
  • 34
Jesse
  • 1
  • So what's your problem? Getting the actual values into the array, or printing them out? – Robby Cornelissen Mar 27 '18 at 02:03
  • Can you please share what is the exact issue you are facing?Is it that some of the digits are missing as compared to the actual file or something else? – Aman Chhabra Mar 27 '18 at 02:05
  • printing them out. – Jesse Mar 27 '18 at 02:05
  • Can you share the code around your print statement? – Parth Mody Mar 27 '18 at 02:07
  • so, if I do: theScreen.println(table); I get SalesTable@677327b6 , I tried Arrays.toString and it did not work – Jesse Mar 27 '18 at 02:07
  • import java.util.*; import java.io.*; public class Cars { static PrintStream theScreen = new PrintStream(System.out); static Scanner theKeyboard = new Scanner(System.in); public static void main(String args[]) { theScreen.print("\nEnter the name of the file: "); String inFile; inFile = theKeyboard.nextLine(); SalesTable table = new SalesTable(inFile); theScreen.println(table); //theScreen.println(Arrays.toString(table)); } } – Jesse Mar 27 '18 at 02:08

0 Answers0