Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Ivor Horton's Beginning Java, Java 7 Edition
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2015, 11:18 AM
Registered User
 
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
 
Old July 7th, 2015, 11:49 AM
Authorized User
 
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
[email protected]
Free Java Video Courses, https://goo.gl/bhMHTq
 
Old July 7th, 2015, 08:01 PM
Registered User
 
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you that fixed it
 
Old July 8th, 2015, 10:14 AM
Authorized User
 
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
[email protected]
Free Java Video Courses
https://goo.gl/bhMHTq





Similar Threads
Thread Thread Starter Forum Replies Last Post
Who's to blame? W8 or touch panel? Georg Orig Access 0 March 5th, 2014 09:44 AM
Errors nnrin Classic ASP Databases 2 December 11th, 2007 12:36 PM
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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.