-2

I want a System class to read the books that have been written in a text file.

import java.io.BufferedReader;
import java.io.FileReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class System
{
    private String FILENAME = "books.txt";
    private static final int MAX_BOOKS = 10;

        public void readBooks()
    {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(FILENAME));
            String line = null;
            int count=0;

            while ((line = br.readLine()) != null && count < MAX_BOOKS) {
                String[] values = line.split(",");

                String ISBN = values[0];
                String author = values[1];
                String title = values[2];
                String subject = values[3];

                String inputDate = "04/04/2015";
                SimpleDateFormat formatter = new SimpleDateFormat("d/M/yyyy");
                Date date = null;
                try {
                    date = formatter.parse(values[4]);
                }
                catch (ParseException exc)
                {
                   System.out.println("A date format error occurred"); //***
                }

                Transaction bok = new Book(ISBN,author,title,subject,date);
                books[count] = bok;

                count++;
            }
            br.close();

            numberOfBooks = count;

            System.out.println("Books read from file successfully");

            updateBalance();
        }
        catch (Exception ex) {
           System.out.println("A file error occurred");
        }
    }

}

The error in the title refers to the System.out.println that I have highlighted. Why does this error show up and how can I fix it? Thanks in advance!

Tunaki
  • 132,869
  • 46
  • 340
  • 423
dinko
  • 9
  • 1
  • 3

2 Answers2

4

Rename your class to something other than System so that Java's own java.lang.System can be used

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Wow, thanks. My mind is just so clouded can't even see such a simple mistake. Thanks man – dinko Mar 29 '15 at 15:42
0

You can replace each instruction started with :

System.out.println()

with

java.lang.System.out.println()

  • 1
    The answer seems to be true. But as 'Hovercraft Full Of Eels' and 'Reimeus' mention, naming a class 'System' is just no good idea.It leads to confusion as why this Question was raised in the first place. – Dirk Schumacher Aug 16 '21 at 10:44
  • While your answer is technically correct, this is not an acceptable solution. The actual solution has been posted by Reimus and Hovercraft already, as noted by Dirk. – Eric Aya Aug 16 '21 at 13:39