Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Ivor Horton's Beginning Java, Java 7 Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 7th, 2015, 11:18 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I have so many errors I am not sure who is to blame

I am in chapter 5 working on the intersecting lines. The Point class page I have a critical error on line 14...Here is how it reads:
//Create a point from another Point object
14 Point(final Point oldPoint) {
x = oldPoint.x; //Copy x coordinate
y = oldPoint.y; //Copy y coordinate
}
When I look at it it says: Multiple markers at this line ( Point final Point oldPoint) oldPoint can not be resolved to a variable...Know how to fix that but it does not fix the problem; next it says; Description Resource Path Location Type
oldPoint cannot be resolved to a variable Point.java /Try Geometry/src line 14 Java Problem
Syntax error on token ",", ; expected Point.java /Try Geometry/src line 20 Java Problem
Syntax error on token "(", ; expected Point.java /Try Geometry/src line 20 Java Problem
Syntax error on token "(", ; expected Point.java /Try Geometry/src line 27 Java Problem
Syntax error on token ")", ; expected Point.java /Try Geometry/src line 20 Java Problem
Syntax error on token ")", ; expected Point.java /Try Geometry/src line 27 Java Problem
Syntax error on token "final", @ expected Point.java /Try Geometry/src line 14 Java Problem
Syntax error on token "String", new expected Point.java /Try Geometry/src line 32 Java Problem
Syntax error, insert ";" to complete Statement Point.java /Try Geometry/src line 14 Java Problem
Syntax error, insert ";" to complete Statement Point.java /Try Geometry/src line 32 Java Problem
Syntax error, type annotations are illegal here Point.java /Try Geometry/src line 14 Java Problem
The constructor Point(Point) is undefined Line.java /Try Geometry/src line 8 Java Problem
The constructor Point(Point) is undefined Line.java /Try Geometry/src line 9 Java Problem
The method distance(Point) is undefined for the type Point Line.java /Try Geometry/src line 19 Java Problem
The method move(double, double) is undefined for the type Point TryGeometry.java /Try Geometry/src line 16 Java Problem
toString cannot be resolved to a type Point.java /Try Geometry/src line 32 Java Problem
void is an invalid type for the variable move Point.java /Try Geometry/src line 20 Java Problem
Void methods cannot return a value Point.java /Try Geometry/src line 28 Java Problem
Void methods cannot return a value Point.java /Try Geometry/src line 33 Java Problem


Here is the code...for the point class : import static java.lang.Math.sqrt;

Code:
public class Point {
	//Coordinates of the point
	double x;
	double y;
	
	//Create a point from coordinates
	Point(double xVal, double yVal) {
		x = xVal;
		y = yVal;
		
	//Create a point from another Point object
		Point(final Point oldPoint) {
		x = oldPoint.x;			//Copy x coordinate
		y = oldPoint.y;			//Copy y coordinate
	}
	
	//Move a point
	void move(double xDelta, double yDelta) {
		//Parameter values are increments to the current coordinates
		x += xDelta;
		y += yDelta;
	}
	
	//Calculate the distance to another point
	double distance(final Point aPoint) {
		return sqrt((x - aPoint.x)*(x - aPoint.x) + (y - aPoint.y)*(y - aPoint.y));
	}
	
	//Convert a point to a string
	public String toString() {
		return Double.toString(x) + ", " + y;			//As "x,y"
	}
	}
}
The code starts on page 188 and goes to page 193
Reply With Quote
  #2 (permalink)  
Old July 7th, 2015, 11:49 AM
Authorized User
Points: 75, Level: 1
Points: 75, Level: 1 Points: 75, Level: 1 Points: 75, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2014
Posts: 13
Thanks: 1
Thanked 4 Times in 4 Posts
Default Re: I have so many errors I am not sure who is to blame

Hi larka06,

There is a missing curly brace on line 14.

There is also an extra curly brace on line 37.

I made those changes and here is the updated file.

Code:
import static java.lang.Math.sqrt;

public class Point {
    //Coordinates of the point
    double x;
    double y;
   
    //Create a point from coordinates
    Point(double xVal, double yVal) {
        x = xVal;
        y = yVal;
    }
    
    //Create a point from another Point object
        Point(final Point oldPoint) {
        x = oldPoint.x;            //Copy x coordinate
        y = oldPoint.y;            //Copy y coordinate
    }
   
    //Move a point
    void move(double xDelta, double yDelta) {
        //Parameter values are increments to the current coordinates
        x += xDelta;
        y += yDelta;
    }
   
    //Calculate the distance to another point
    double distance(final Point aPoint) {
        return sqrt((x - aPoint.x)*(x - aPoint.x) + (y - aPoint.y)*(y - aPoint.y));
    }
   
    //Convert a point to a string
    public String toString() {
        return Double.toString(x) + ", " + y;            //As "x,y"
    }    
}


Chad "Shod" Darby
darby@luv2code.com
Free Java Video Courses, https://goo.gl/bhMHTq
Reply With Quote
  #3 (permalink)  
Old July 7th, 2015, 08:01 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you that fixed it
Reply With Quote
  #4 (permalink)  
Old July 8th, 2015, 10:14 AM
Authorized User
Points: 75, Level: 1
Points: 75, Level: 1 Points: 75, Level: 1 Points: 75, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2014
Posts: 13
Thanks: 1
Thanked 4 Times in 4 Posts
Default Awesome!

Hey,

Glad to hear that worked :-)

Chad "Shod" Darby
darby@luv2code.com
Free Java Video Courses
https://goo.gl/bhMHTq
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Who's to blame? W8 or touch panel? Georg Orig Access 0 March 5th, 2014 08:44 AM
Errors nnrin Classic ASP Databases 2 December 11th, 2007 11:36 AM
Can't get errors to display with <html:errors> michaeldill JSP Basics 0 August 2nd, 2004 01:47 PM
errors and fixing errors Droopy XML 0 August 26th, 2003 12:47 AM
Errors Errors DB Errors Ljhopkins VS.NET 2002/2003 0 July 15th, 2003 12:42 PM



All times are GMT -4. The time now is 07:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.