Hello,
My son is taking a java course in Hawaii. His text book is "Java Solutions by Lewis & Loftus 6th edition.

He copied several text book examples and tried to compile them with JCreator and NetBeans 6.8, each compiler gave pages of errors. The question is " What is wrong???" The text book?? the Compiler??
I'm completly Lost, any help would be greatly appreciated.

What my son needs at present is some correct Java code examples , that he could lear from.

Thanks in advance

Schippi

Recommended Answers

All 11 Replies

Please post the code and error received and we will try to assist

Please post the code and error received and we will try to assist

//
// RollingDice.java
//
//   Book example page 162
//
//
     public class RollingDice
  {
//
// Creates two Die objects and rolls them several times.
//
   public static void main (String[] args )
     Die die1, die2 ;
     int sum ;

     die1 = new Die() ;
     die2 = new Die() ;

     die1.roll() ;
     die2.roll() ;

     system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;

     die1.roll() ;
     die2.setFaceValue(4) ;
     system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;

     sum = die1.getFaceValue() + die2.getFaceValue();
     system.out.println ( " Sum: " + sum ) ;

     sum = die1.roll() + die2.roll();
     system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
     system.out.println ( " New sum: " + sum ) ;

     }
   }
//
// RollingDice.java
//
//   Book example page 162
//
//
     public class RollingDice
  {
//
// Creares two Die objects and rolls them several times.
//
   public static void main (String[] args )
     Die die1, die2 ;
     int sum ;

     die1 = new Die() ;
     die2 = new Die() ;

     die1.roll() ;
     die2.roll() ;

     system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;

     die1.roll() ;
     die2.setFaceValue(4) ;
     system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;

     sum = die1.getFaceValue() + die2.getFaceValue();
     system.out.println ( " Sum: " + sum ) ;

     sum = die1.roll() + die2.roll();
     system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
     system.out.println ( " New sum: " + sum ) ;

     }
   }

Much Thanks in Advance

Please wrap your code in code-tags the next time you post any code.
Whew! That's a lot of errors:

RollingDice.java:12: ';' expected
public static void main (String[] args )
                                        ^
RollingDice.java:16: <identifier> expected
die1 = new Die() ;
    ^
RollingDice.java:17: <identifier> expected
die2 = new Die() ;
    ^
RollingDice.java:19: <identifier> expected
die1.roll() ;
         ^
RollingDice.java:20: <identifier> expected
die2.roll() ;
         ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                  ^
RollingDice.java:22: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                     ^
RollingDice.java:22: ')' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                 ^
RollingDice.java:22: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                   ^
RollingDice.java:22: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                         ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                          ^
RollingDice.java:22: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                        ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                               ^
RollingDice.java:24: <identifier> expected
die1.roll() ;
         ^
RollingDice.java:25: <identifier> expected
die2.setFaceValue(4) ;
                 ^
RollingDice.java:25: illegal start of type
die2.setFaceValue(4) ;
                  ^
RollingDice.java:26: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                  ^
RollingDice.java:26: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                     ^
RollingDice.java:26: ')' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                 ^
RollingDice.java:26: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                   ^
RollingDice.java:26: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                         ^
RollingDice.java:26: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                          ^
RollingDice.java:26: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                        ^
RollingDice.java:26: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                               ^
RollingDice.java:28: <identifier> expected
sum = die1.getFaceValue() + die2.getFaceValue();
   ^
RollingDice.java:29: <identifier> expected
system.out.println ( " Sum: " + sum ) ;
                  ^
RollingDice.java:29: illegal start of type
system.out.println ( " Sum: " + sum ) ;
                     ^
RollingDice.java:29: ')' expected
system.out.println ( " Sum: " + sum ) ;
                             ^
RollingDice.java:29: ';' expected
system.out.println ( " Sum: " + sum ) ;
                               ^
RollingDice.java:29: illegal start of type
system.out.println ( " Sum: " + sum ) ;
                                    ^
RollingDice.java:29: <identifier> expected
system.out.println ( " Sum: " + sum ) ;
                                     ^
RollingDice.java:29: ';' expected
system.out.println ( " Sum: " + sum ) ;
                                       ^
RollingDice.java:31: illegal start of type
sum = die1.roll() + die2.roll();
    ^
RollingDice.java:31: ';' expected
sum = die1.roll() + die2.roll();
          ^
RollingDice.java:31: invalid method declaration; return type required
sum = die1.roll() + die2.roll();
           ^
RollingDice.java:31: ';' expected
sum = die1.roll() + die2.roll();
                 ^
RollingDice.java:32: <identifier> expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                  ^
RollingDice.java:32: illegal start of type
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                     ^
RollingDice.java:32: ')' expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                 ^
RollingDice.java:32: ';' expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                      ^
RollingDice.java:32: illegal start of type
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                         ^
RollingDice.java:32: <identifier> expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                                      ^
RollingDice.java:32: ';' expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                                        ^
RollingDice.java:32: illegal start of type
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                                              ^
RollingDice.java:32: <identifier> expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                                               ^
RollingDice.java:32: ';' expected
system.out.println ( " Die One: " die1 + ", Die Two: " + die2 ) ;
                                                                 ^
RollingDice.java:33: illegal start of type
system.out.println ( " New sum: " + sum ) ;
      ^
RollingDice.java:33: ';' expected
system.out.println ( " New sum: " + sum ) ;
          ^
RollingDice.java:33: invalid method declaration; return type required
system.out.println ( " New sum: " + sum ) ;
           ^
RollingDice.java:33: illegal start of type
system.out.println ( " New sum: " + sum ) ;
                     ^
RollingDice.java:33: ')' expected
system.out.println ( " New sum: " + sum ) ;
                                 ^
RollingDice.java:33: ';' expected
system.out.println ( " New sum: " + sum ) ;
                                   ^
RollingDice.java:33: illegal start of type
system.out.println ( " New sum: " + sum ) ;
                                        ^
RollingDice.java:33: <identifier> expected
system.out.println ( " New sum: " + sum ) ;
                                         ^
RollingDice.java:33: ';' expected
system.out.println ( " New sum: " + sum ) ;
                                           ^
55 errors

Corrections:

//
// RollingDice.java
//
// Book example page 162
//
//
public class RollingDice
{
//
// Creates two Die objects and rolls them several times.
//
public static void main (String[] args ){
Die die1, die2 ;
int sum ;
die1 = new Die() ;
die2 = new Die() ;
die1.roll() ;
die2.roll() ;
System.out.println ( " Die One: " + die1.getFaceValue() + " , Die Two: " + die2.getFaceValue() ) ;
die1.roll() ;
die2.setFaceValue(4) ;System.out.println ( " Die One: " + die1.getFaceValue() + " , Die Two: " + die2.getFaceValue() ) ;
sum = die1.getFaceValue() + die2.getFaceValue();System.out.println ( " Sum: " + sum ) ;
sum = die1.roll() + die2.roll();System.out.println ( " Die One: " + die1.getFaceValue() + " , Die Two: " + die2.getFacevalue() ) ;System.out.println ( " New sum: " + sum ) ;
}
}

This is how I think the code should have been, it might be that I've made some incorrect assumptions.
Anyway, feeding this code to the compiler still produces some unwanted error messages:

RollingDice.java:13: cannot find symbol
symbol  : class Die
location: class RollingDice
Die die1, die2 ;
^
RollingDice.java:16: cannot find symbol
symbol  : class Die
location: class RollingDice
die1 = new Die() ;
^
RollingDice.java:17: cannot find symbol
symbol  : class Die
location: class RollingDice
die2 = new Die() ;
^
RollingDice.java:28: incompatible types
found   : java.lang.String
required: int
sum = die1.getFaceValue() + die2.getFaceValue();
^
RollingDice.java:31: incompatible types
found   : java.lang.String
required: int
sum = die1.roll() + die2.roll();
^
5 errors

The problem is that you haven't provided the code for the Die-class, take a second look at the code example in the book, are you sure that there isn't listed code for a Die-class?
If you can spot this code, then all you'll have to do is put this code in a file called Die.java, then you recompile your whole program using: javac RollingDice.java Die.java It should work now.

Now I'm wondering, much programming books come with either a CD or free code online, a quick Google search learned me that your book comes with a CD on which all source code is already, if you first try getting to work the code featured on the CD, then you don't risk making typos in your code (as you did).

hi sir,
learn java with a book is not possible.
Your son is learn java now (like me) i give some points that your son must be follow
1.join this community for he's problem with java and other.
2.visit a web sites like java2s.com for online problem solutions
3.download the javadoc so it give him offline support for learn java.
this are 3 simple steps and he became a good programmer with java.
best luck for him; and have a good day

I can’t thank you enough for your help and comments. Your post was exactly correct and resolved all my problems. Sorry about the code tags. This was my first post and I did not understand them. As a point of information, system instead of System was my copying error. But the many instances of the absence of .getFaeValue( ) are actual text book errors.

Again, Thank You, Thank You, …………………………………………………… Thank You

Schippi

sir,
I highly recommend your son to stop trying to copy-paste the codes of the book and start practising with very basic exercises from the end of the chapters in the book. copy-paste som codes is a waste of time and clearly is not a good way to learn Java.

do you have an example? try using jGRASP

Welcome @kezkez.

If you want to ask question, start your own thread.

Thanks

Thread Closed.

Java code that inputs any number of product names and their prices from the user. Display the average price of the products as well as the name and price of the product with the highest price and the product with the lowest price. HINT: Use the sentinel-controlled loop pattern.

DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules
Please start your own new thread for your question

This thread is closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.