Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Trouble with Writing test program

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trouble with Writing test program

    Hey guys, I am trying to get a test program to run in the same application that my class is in... I seem to be having some trouble with it.
    Could you please advise, I have everything done I just can't figure this part out.

    Thanks in advance for your time.

    public class RegularPolygon {
     
        private int n; 
        private double side; 
        private double x; 
        private double y; 
     
     public RegularPolygon() {
                n = 3;
                side = 1;
                x = y = 0;
            }
     
            public RegularPolygon(int n, double side) {
                this.n = n;
                this.side = side;
                x = y = 0;
            }
     
            public RegularPolygon(int n, double side, double x, double y) {
                this.n = n;
                this.side = side;
                this.x = x;
                this.y = y;
            }
     
            public void setN(int n) {
                this.n = n;
            }
     
            public int getN() {
                return n;
            }
     
            public void setSide(double side) {
                this.side = side;
            }
     
            public double getSide() {
                return side;
            }
     
            public void setX(double x) {
                this.x = x;
            }
     
            public double getX() {
                return x;
            }
     
            public void setY() {
                this.y = y;
            }
     
            public double getY() {
                return y;
            }
     
            public double getPerimeter() {
                return n * side;
            }
     
            public double getArea() {
                 return (n * side) * 5;
            }
        }
     
        public static void main(String[] args)
    {
          RegularPolygon test1 = new RegularPolygon();
          RegularPolygon test2 = new RegularPolygon(6, 4);
          RegularPolygon test3 = new RegularPolygon(10, 4, 5.6, 7.8);
     
          System.out.println(test1.getPerimeter()+"\t"+test1.getArea();
          System.out.println(test2.getPerimeter()+"\t"+test2.getArea();
          System.out.println(test3.getPerimeter()+"\t"+test3.getArea();
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Trouble with Writing test program

    I seem to be having some trouble with it.
    Please explain. If there are any error messages, copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Trouble with Writing test program

    Please do as Norm suggests, but it's fairly obvious that the main() method is outside any class in what you posted. That won't work.

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with Writing test program

    It says "class, integer or enum expected"

    the problem is only with the test program ive written.

    --- Update ---

    ha, wow thanks greg. i figured it out. thank you.

Similar Threads

  1. [SOLVED] Would Really Appreciate Some Help!! Trouble Writing XML File From GUI :(
    By Raggazz4 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 11th, 2012, 07:37 AM
  2. Having trouble writing the methods for this program
    By michael305rodri in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 1st, 2012, 11:31 PM
  3. Having trouble writing insert method for Ordered LinkList.
    By orbin in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 28th, 2012, 05:25 PM
  4. Trouble with writing/reading array to/from file
    By MaximusPrime in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2012, 08:41 PM
  5. Trouble writing some code...help?
    By bChEos in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 7th, 2010, 08:54 PM