Jump to content

my BlueJ ignoring the class??how to make it work??

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
TAboy24

TAboy24

    Newbie

  • Members
  • PipPip
  • 13 posts
Hello,
I'm writing a Class for Triangle using an existing class Point(see atachment of its description)...
it supposed to consist constructors and functions in it and i just started ,but for some reason its writing me an error in the first moment where the Point definition is...and i don't know why ...im using BlueJ and added the class to there..
import java.util.Scanner;
import java.lang.Math;
import java.util.*;
import java.io.*;

class  Triangle {
 public static void  main (string[] args ) {
private Point p1,p2,p3;  <----here writing my first error!
public Triangle() { p1=new Point(1,0);p2=new Point(-1,0);p3=new Point(0,1);}  //defining triangle points(see Point class options)
public Triangle (int x1,int y1,int  x2,int y2,int x3,int y3) {p1=new Point(x1,y1);p2=new Point (x2,y2);p3=new Point(x3,y3);}
public Triangle (Point a,Point b,Point c) {p1=Point(a);p2=Point(b);p3=Point(c); }
public Point getPoint1() {return p1;}
public Point getPoint2() {return p2;}
public Point getPoint3() {return p3;}
public  boolean isValid() {  //checking if its triangle by the points
if (p1.getX()==p2.getX())&&(p2.getX()==p3.getX()) return false
else if (p1.getY()==p2.getY())&&(p2.getY()==p3.getY()) return false
else if  (p1.getX()!=p2.getX())&&(p2.getX()!=p3.getX())&&(p1.getX()!=p3.getX()) &&(p1.getY()!=p2.getY())&&(p2.getY()!=p3.getY())&&(p1.getY()!=p3.getY()) return false
else return true;
} }
Thanks!

Attached Files


Edited by WingedPanther, 08 December 2008 - 01:04 PM.
add code tags (the # button)


#2
Exe

Exe

    Newbie

  • Members
  • Pip
  • 7 posts
This will fix most of your bugs. I don't know what you were trying to do with your if and else if statements. You can solve that one by yourself. By the way, you need to clean up your code. You had all syntax errors. Your style of coding is messy and it will continue to haunt you with hard to find errors. Using more whitespace will save you a lot of headaches.
import java.util.Scanner;
import java.lang.Math;
import java.util.*;
import java.io.*;

class Triangle {
    private Point p1;
    private Point p2;
    private Point p3;
    public static void main (string[] args ) {}
public Triangle() {
    this(1,0, -1,0,0,1);
}
public Triangle (int x1,int y1,int x2,int y2,int x3,int y3) {
    p1=new Point(x1,y1);
    p2=new Point (x2,y2);
    p3=new Point(x3,y3);}
public Triangle (Point a,Point b,Point c) {p1=Point(a);p2=Point(b);p3=Point(c); }
public Point getPoint1() {return p1;}
public Point getPoint2() {return p2;}
public Point getPoint3() {return p3;}
public boolean isValid() { //checking if its triangle by the points
if (p1.getX()==p2.getX())&&(p2.getX()==p3.getX())) 
    return false;
else if (p1.getY()==p2.getY())&&(p2.getY()==p3.getY()))
    return false;
else if (p1.getX()!=p2.getX())&&(p2.getX()!=p3.getX())&&(p 1.getX()!=p3.getX()) &&(p1.getY()!=p2.getY())&&(p2.getY()!=p3.getY())&& (p1.getY()!=p3.getY()) return false
else return true;
} }

Edited by WingedPanther, 08 December 2008 - 01:04 PM.
add code tags (the # button)


#3
Exe

Exe

    Newbie

  • Members
  • Pip
  • 7 posts
By the way, when you see that you have three false statements and one true statement that raises a logic flag to me. Would it be easier to search for what is true or what is false in this case? I'm not reading through you if statements, but that is a general truth.

#4
TAboy24

TAboy24

    Newbie

  • Members
  • PipPip
  • 13 posts
Thank you!!!You are very right here i must say...and the correction actualy helped to solve the bug i was talking about...but here i completed the whole program almost i think and when i put there the line of "public static void main () {..} its writing all the time errors but without this line i managed making the compilation properly i think..furthemore i tried making a "Tester" seperate class and it doesnt do any call properly..what to do:(??
here the code of the triangle class(the Point attachment that is used here is attached in my previous comment-look up):
import java.util.Scanner;
import java.lang.Math;


class Triangle {                //Class which represents 3 points of triangle
private Point p1;
private Point p2;
private Point p3;

public Triangle() {
this(1,0, -1,0,0,1);
}
public Triangle (int x1,int y1,int x2,int y2,int x3,int y3) {
p1=new Point(x1,y1);
p2=new Point (x2,y2);
p3=new Point(x3,y3);}
public Triangle (Point a,Point b,Point c) {p1=new Point(a);p2=new Point(b);p3=new Point(c); }
public Point getPoint1() {return p1;}
public Point getPoint2() {return p2;}
public Point getPoint3() {return p3;}
public boolean isValid() { //checking if its a a triangle by the its points,if there are 3 X's or 3 Y's which are same its a straight line..and if all X's and Y's 
if  (p1.getX()==p2.getX() && p2.getX()==p3.getX()) return false; //thats also makes it be not a triangle
else if (p1.getY()==p2.getY()&& p2.getY()==p3.getY()) return false;
else if (p1.getX()!=p2.getX()&&p2.getX()!=p3.getX()&&p1.getX()!=p3.getX() &&p1.getY()!=p2.getY()&&p2.getY()!=p3.getY() &&p1.getY()!=p3.getY()) return false;
else return true;
} 
public String  toString() {
return ""+ p1.getX()+" ,"+p1.getY()+"    "+p2.getX()+","+p2.getY()+"     "+p3.getX()+","+p3.getY();} //supposed to print all of the points as strings
public void moveTriangle(int deltaX , int deltaY) {     //supposed to move the whole triangle using the function "move" (see the  attached file)
p1.move(deltaX,deltaY);
p2.move(deltaX,deltaY);
p3.move(deltaX,deltaY);}
public double getLengthOfSide(Point pp1, Point pp2) {    //function which returns  us the length of a Side...by formula between 2 points 
double power1,power2,squareResult;
if  (pp1!=p1&&pp1!=p2&&pp1!=p3) return 0;
else if ( pp2!=p1 &&pp2!=p2&&pp2!=p3) return 0;
else  {power1=Math.pow(pp2.getY()-pp1.getY(),2);
power2=Math.pow(pp2.getX()-pp1.getX(),2);
squareResult=Math.sqrt(power1+power2);
return  squareResult;
}}
public double getPerimeter() {  //by adding all the Sides together it returns us the Perimeter
return (getLengthOfSide(p1,p2)+getLengthOfSide(p2,p3)+getLengthOfSide(p3,p1));}
public double getArea() {   //by the Haron formula it finds us the area of the triangle
double perimeter=getPerimeter();
return Math.sqrt(perimeter*(perimeter-getLengthOfSide(p1,p2)))*(perimeter-getLengthOfSide(p2,p3))*(perimeter-getLengthOfSide(p3,p1));}

boolean isIsosceles() {  //checking if the triangle is isosceles....
if ( getLengthOfSide(p1,p2)==getLengthOfSide(p2,p3)) return true;
else if (getLengthOfSide(p2,p3)==getLengthOfSide(p3,p1)) return true;
else if (getLengthOfSide(p3,p1)==getLengthOfSide(p1,p2)) return true;
else return false;}
}
Thanks...

Edited by WingedPanther, 08 December 2008 - 01:05 PM.
add code tags (the # button)


#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
For both of you: please use code tags and format your code.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog