We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,167 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Java Software Solutions text book by Lewis & Loftus 6th Edition

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

9
Contributors
11
Replies
2 Years
Discussion Span
7 Months Ago
Last Updated
12
Views
Question
Answered
schippi
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

peter_budo
Code tags enforcer
Moderator
15,789 posts since Dec 2004
Reputation Points: 2,867
Solved Threads: 944
Skill Endorsements: 50

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

schippi
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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).

mvmalderen
Posting Maven
2,612 posts since Feb 2009
Reputation Points: 2,221
Solved Threads: 280
Skill Endorsements: 36

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

skwatamkar
Newbie Poster
17 posts since Jan 2010
Reputation Points: 6
Solved Threads: 2
Skill Endorsements: 0

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

schippi
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Years Ago by mvmalderen, skwatamkar and peter_budo

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.

Korhan
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

As it relates to learning Java, you'll also find this material useful:
http://www.daniweb.com/forums/thread99132.html

mvmalderen
Posting Maven
2,612 posts since Feb 2009
Reputation Points: 2,221
Solved Threads: 280
Skill Endorsements: 36

do you have an example? try using jGRASP

kezkez
Light Poster
31 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Welcome @kezkez.

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

Thanks

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50

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.

kasho.junior
Newbie Poster
1 post since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

JamesCherrill
... trying to help
Moderator
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0966 seconds using 2.74MB