Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

TEST: Getting ce

$
0
0

Hi,

I used Eclipse to write the program Life, Universe, Everything. It compiles and works perfectly. However, when I submit, I get the message

Main.java:4: class LifeUniverseEverything is public, should be declared in a file named LifeUniverseEverything.java public class LifeUniverseEverything { ^ 1 error

My file is called LifeUniverseEverything.java

Here's my code, its more complex than necessary.


import java.io.*;
import java.util.*;

public class LifeUniverseEverything {

    //Private Variables
    private BufferedReader breader;

    //Constructor
    public LifeUniverseEverything() {
        breader = new BufferedReader(new InputStreamReader(System.in));
    }

    //Pre: User will only input numbers of one or two digits
    //Post: Returns an array consisting of all Strings the user inputs 
    public ArrayList<String> getInput() throws Exception{

         String s = null;
         ArrayList<String> input = new ArrayList<String>();
         try {
                 while((s=breader.readLine()) != null) {
                     input.add(s);
                 }

         } catch (Exception E) {
             System.out.println(E.getMessage());
             System.exit(1);
         }

         return input;

    }

    //Pre: result is an ArrayList of Strings. Result is not null
    //Post: Prints each string in result array. Stops when 42 is reached. 
    public void print(ArrayList<String> result) {
        for (int i=0; i<result.size(); i++) {
            if(result.get(i).equals(new String("42"))) {
                break;
            }
            System.out.println(result.get(i));
        }
    }

    public static void main(String[] args) throws Exception{
        LifeUniverseEverything start = new LifeUniverseEverything();
        ArrayList<String> result = start.getInput();
        start.print(result);

    }

}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>