Compute Area of a Triangle Errors

Keep getting same errors but fixing them messes it up more.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2441 Views - Last Post: 15 October 2010 - 07:00 AM Rate Topic: -----

#1 Guest_Michael Wheeler*


Reputation:

Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:42 AM

public class Exercise3.25 {

		private double side1 = 1.0;
		private double side2 = 1.0;
		private double side3 = 1.0;
		
		public Triangle()
		{
		}
		
		public Triangle(double side1, double side2, double side3)
		{
			this.side1 = side1;
			this.side2 = side2;
			this.side3 = side3;
		}
		
		public void setSide1(double side1)
		{
			this.side1 = side1;
		}
		
		public void setSide2(double side2)
		{
			this.side2 = side2;
		}
		
		public void setSide3(double side3)
		{
			this.side3 = side3;
		}
		
		public double getSide1()
		{
			return side1;
		}
		
		public double getSide2()
		{
			return side2;
		}
		
		public double getSide2()
		{
			return side3;
		}
		
		public double getArea()
		{
			return side1 * side2 * side3;
		}
		
		public double getPerimeter();
		}
			return side1 + side2 + side3;
		}
		
		public String toString()
		{
			return "Triangle: Side 1 = " + side1 + "Side2 = " + side2 + " Side3 = " + side3;
		}
	}




I keep getting this errors...

 ----jGRASP exec: javac -g C:\Exercise3_25.java

Exercise3_25.java:1: '{' expected
public class Exercise3.25 {
                      ^
Exercise3_25.java:7: invalid method declaration; return type required
		public Triangle()
		       ^
Exercise3_25.java:11: invalid method declaration; return type required
		public Triangle(double side1, double side2, double side3)
		       ^
Exercise3_25.java:55: class, interface, or enum expected
			return side1 + side2 + side3;
			^
Exercise3_25.java:56: class, interface, or enum expected
		}
		^
Exercise3_25.java:58: class, interface, or enum expected
		public String toString()
		       ^
Exercise3_25.java:61: class, interface, or enum expected
		}
		^
7 errors



I don't know why I am having these problems cause I believe this should be working right.
I just need a couple headers on what I need to fix or adjust to get this too compile right.

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 14 October 2010 - 03:28 PM


Is This A Good Question/Topic? 0

Replies To: Compute Area of a Triangle Errors

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:50 AM

Rename your class to Triangle and see if that fixes it.
Was This Post Helpful? 0
  • +
  • -

#3 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:53 AM

That helped solve some of the problems but still have these errors..



Triangle.java:55: class, interface, or enum expected
return side1 + side2 + side3;
^
Triangle.java:56: class, interface, or enum expected
}
^
Triangle.java:58: class, interface, or enum expected
public String toString()
^
Triangle.java:61: class, interface, or enum expected
}
^
4 errors
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:59 AM

public double getPerimeter();
}
return side1 + side2 + side3;
}



The first bracket is the wrong one. Switch it from } to { and you should be good.
Was This Post Helpful? 0
  • +
  • -

#5 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 10:09 AM

Overlooked that obviously. I fixed that and couple new errors appeared but I fixed those but however, after I compiled and ran it now there is a runtime error. Ugh!

java.lang.NoSuchMethodError: main
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Now I'm not sure what to do. This mean just isn't going to work or what?

thanks for all your help so far. Much appreciated.

This is the code I have when I got that..

public class Triangle {

		private double side1 = 1.0;
		private double side2 = 1.0;
		private double side3 = 1.0;
		
		public Triangle()
		{
		}
		
		public Triangle(double side1, double side2, double side3)
		{
			this.side1 = side1;
			this.side2 = side2;
			this.side3 = side3;
		}
		
		public void setSide1(double side1)
		{
			this.side1 = side1;
		}
		
		public void setSide2(double side2)
		{
			this.side2 = side2;
		}
		
		public void setSide3(double side3)
		{
			this.side3 = side3;
		}
		
		public double getSide1()
		{
			return side1;
		}
		
		public double getSide2()
		{
			return side2;
		}
		
		public double getSide3()
		{
			return side3;
		}
		
		public double getArea()
		{
			return side1 * side2 * side3;
		}
		
		public double getPerimeter()
		{
			return side1 + side2 + side3;
		}
		
		public String toString()
		{
			return "Triangle: Side 1 = " + side1 + "Side2 = " + side2 + " Side3 = " + side3;
		}
	}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 14 October 2010 - 03:29 PM

Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 10:10 AM

From the error you're getting it seems to me, but I barely know anything about Java, that you need a main function. The help I've given so far is just object oriented programming basics that generally work across all OOP languages. For help with the main method, you'll have to get someone else in here with more experience in Java. Wish I could help more, but glad I could at least help at all.
Was This Post Helpful? 0
  • +
  • -

#7 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 10:13 AM

Yeah, I'm in first programming class but yes thanks for everything.
Was This Post Helpful? 0
  • +
  • -

#8 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 10:16 AM

java.lang.NoSuchMethodError: main
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Now I'm not sure what to do. This mean just isn't going to work or what?


This is the code I have when I got that..

public class Triangle {

private double side1 = 1.0;
private double side2 = 1.0;
private double side3 = 1.0;

public Triangle()
{
}

public Triangle(double side1, double side2, double side3)
{
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}

public void setSide1(double side1)
{
this.side1 = side1;
}

public void setSide2(double side2)
{
this.side2 = side2;
}

public void setSide3(double side3)
{
this.side3 = side3;
}

public double getSide1()
{
return side1;
}

public double getSide2()
{
return side2;
}

public double getSide3()
{
return side3;
}

public double getArea()
{
return side1 * side2 * side3;
}

public double getPerimeter()
{
return side1 + side2 + side3;
}

public String toString()
{
return "Triangle: Side 1 = " + side1 + "Side2 = " + side2 + " Side3 = " + side3;
}
} 


Please help me with the main method and figuring out what to do..

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 14 October 2010 - 03:27 PM

Was This Post Helpful? 0
  • +
  • -

#9 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • Posts: 378
  • Joined: 28-November 09

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 01:24 PM

you need a main method
public static void main(String[] args){
//code here
}


you would put in code to call your Triangle class, and all methods that you want to perform
Was This Post Helpful? 0
  • +
  • -

#10 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 01:55 PM

Sorry but could you tell me what code I need?
Was This Post Helpful? -2
  • +
  • -

#11 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 06:44 PM

View PostVonWheeler, on 14 October 2010 - 03:55 PM, said:

Sorry but could you tell me what code I need?


If you don't know how or what a main() method is, you did not write this code and you are trying to cheat. It's not appreciated.
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 07:04 PM

View PostVonWheeler, on 14 October 2010 - 02:55 PM, said:

Sorry but could you tell me what code I need?

Open any basic (not advanced) Java book I am sure you will find plenty of examples using a main() method as the main() method is required to run any Java application.
Was This Post Helpful? 1
  • +
  • -

#13 VonWheeler  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 14-October 10

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:13 PM

Actually I wrote most of it with help from a friend. Some stuff I don't remember to do as easily as others. Idk why but just don't but thanks <pbl>. I appreciate your help.
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:21 PM

OK let's not waste time with a pedagogic approach
If you steal that code why not stealing the solution

public class Triangle {

	private double side1 = 1.0;
	private double side2 = 1.0;
	private double side3 = 1.0;

	public Triangle()
	{
	}

	public Triangle(double side1, double side2, double side3)
	{
		this.side1 = side1;
		this.side2 = side2;
		this.side3 = side3;
	}

	public void setSide1(double side1)
	{
		this.side1 = side1;
	}

	public void setSide2(double side2)
	{
		this.side2 = side2;
	}

	public void setSide3(double side3)
	{
		this.side3 = side3;
	}

	public double getSide1()
	{
		return side1;
	}

	public double getSide2()
	{
		return side2;
	}

	public double getSide3()
	{
		return side3;
	}

	public double getArea()
	{
		return side1 * side2 * side3;
	}

	public double getPerimeter()
	{
		return side1 + side2 + side3;
	}

	public String toString()
	{
		return "Triangle: Side 1 = " + side1 + "Side2 = " + side2 + " Side3 = " + side3;
	}
	
	public static void main(String[] args) {
		// lets build a Triangle
		Triangle t = new Triangle(2.0, 3.0, 5.0);
		// prints it's perimeter
		System.out.println("The triangle preimeter is: " + t.getPerimeter());
	}
} 



Was This Post Helpful? 0
  • +
  • -

#15 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Compute Area of a Triangle Errors

Posted 14 October 2010 - 09:49 PM

Related topics merged
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2