views:

620

answers:

4

here is the program: (the file name is date.java)

class date {
    public static void main (String[] args) {
    int day, hour, minute;
    String firstline, half;

    firstline="the current imaginary time is:";
    day=24;
    hour=5;
    minute=36;

    String half;
    half="PM" ;


    System.out.println ("here is some program about the time kindof:");
    system.out.print (firstline) ;
    system.out.print (day) ;
    system.out.print (hour) ;
    system.out.print (":") ;
    system.out.print (minute) ;
    system.out.println (half) ;

    }
    }

here is what happens when i try to compile it in terminal:

david-allenders-macbook-pro:~ davidallender$ javac date.java
date.java:11: half is already defined in main(java.lang.String[])
    String half;
               ^
date.java:15: package system does not exist
    system.out.print (firstline) ;
              ^
date.java:16: package system does not exist
    system.out.print (day) ;
              ^
date.java:17: package system does not exist
    system.out.print (hour) ;
              ^
date.java:18: package system does not exist
    system.out.print (":") ;
              ^
date.java:19: package system does not exist
    system.out.print (minute) ;
              ^
date.java:20: package system does not exist
    system.out.println (half) ;
              ^
7 errors
david-allenders-macbook-pro:~ davidallender$ 

im learning from a book i found online. right now i'm in the chapter about variables. What did i do wrong?

+2  A: 

Remove the second 'String half;' in main. And system should be System.

brian
+5  A: 
String half;

you have already declared half earlier, remove this one

system.out.print (firstline) ;

Class names in java are case sensitive. system should be System

objects
thank you for your help.
David
no worries, best of luck with it
objects
A: 

Variables can be declared once in any scope and it is System not system.

fastcodejava
A: 

You may want to try the Eclipse Java IDE (Integrated Development Environment) so that you can avoid these problems in the future. It will suggest fixes to these sort of simple errors.

http://www.eclipse.org/downloads/

Plus, it's free!

Jason
1) This should rather have been a comment. 2) Using an IDE before having a good grasp on Java would only make it more hard and opaque.
BalusC