Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Double cannot be dereferenced

$
0
0
Having problems comparing to objects radius... says double cannot be dereferenced. I'm new to the equals method and greaterThan method so I need some help!


 public class Circle
{
	private double radius;
	
	public Circle(double r)
	{
	
		radius=r;
		
	}
	
	public double getArea()
	{
	
		return Math.PI * radius * radius;
		
	}
	
	public double getRadius()
	{
	
		return radius;
		
	}
	
	public String toString()
	{
	
		String str = "The radius is: " + getRadius() + "and the area is: " + getArea(); ;
		
		return str;
		
	}
	
	
	public boolean equals(Circle circle1)
	{
	
		boolean status;
		
		if(getRadius.equals(circle1.getRadius()) && this.getArea().equals(circle1.getArea()))
			status=true;
		else
			status=false;
			return status;
			
	}
	
	public boolean greaterThan(Circle circle1)
	{
	
		boolean status;
			
			if(getArea().greaterThan(circle1.getArea()))
				status=true;
				
			else
				status=false;
				
		return status;
		
	}
}




Here is my demo class
public class CircleDemo
{

	public static void main(String [] args)
	{
	
	Circle circle1 = new Circle(1.44);
	Circle circle2 = new Circle(3.22);
	
	System.out.println(circle1);
	
	if(circle1.equals(circle2))
		System.out.println("Both objects have the same radius and area.");
	else
		System.out.println("The objects have different radi and areas.");
		
		
	if(circle1.greaterThan(circle2))
		System.out.println("Circle 1 is greater than circle 2.");
	else
		System.out.println("Circle 1 is not greater than circle 2.");
		
	}
		
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>