Welcome to Dream.In.Code
Become a Java Expert!

Join 149,414 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,228 people online right now. Registration is fast and FREE... Join Now!




Square.java, Circle.java, shapeTest.java

 
Reply to this topicStart new topic

Square.java, Circle.java, shapeTest.java

prit876
7 Mar, 2007 - 03:19 PM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2007
Posts: 5


My Contributions
I have these 3 programs and I have done the coding for 2 of them and they both compile but the shapeTest file keeps giving me errors... I have been wprking on this for the last week and have not slept in the lst 2 days and my teacher never has nay time to help me... here are the codes...
CODE

import javax.swing.JOptionPane;
public class shapeTest
{
    public static void main(String[] args)
    {
            Square square1 = new squareOne ( 50 );
            Circle circle1 = new circle1 ( 20 );
    
        //Get radius of the Circle
            double radius = circle1.getRadius();
            
        //Get diameter of the Circle
            double diameter = circle1.getDiameter();
            
        //Get circumference of the Circle
            double circumference = circle1.getCircumference();
        
        //Get the area of the Circle
            double area = circle1.getArea();
        
        //Get side of the Square
            double side = Square.getSide();
            
        //Get perimeter of the Square
            double perimeter = Square.getPerimeter();
            
        //Get area of the Sqaure
            double area1 = Square.getArea();
            
            String input = JOptionPane.showInputDialog( "Enter side of the square: " );
            squareOne = Double.parseDouble( input ); //convert square to number
            
    }
}




public class Square
{
    private double side;
  
    public Square(double squareOne)
    {
        side = squareOne;
    }
    
    private void setSide(double squareOne)
    {
        side = squareOne;
    }
    
    public double getSide()
    {
        return side;
    }
    
    public double getPerimeter()
    {
        return 4 * side;
    }

    public double getArea()
    {
        return side * side;
    }
}//End class Square



public class Circle
{
    private double radius;
    
    public Circle(double circle1)
    {
        radius = radRadius;
    }
    
    private void setRadius(double radRadius)
    {
        radius = radRadius;
    }
    
    public double getRadius()
    {
        return radius;
    }
    
    public double getDiameter()
    {
        return 2 * radius;
    }
    
    public double getCircumference()
    {
        return Math.PI * getDiameter();
    }
    
    public double getArea()
    {
        return Math.PI * radius * radius;
    }
}//End class Circle

User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Square.java, Circle.java, ShapeTest.java
7 Mar, 2007 - 04:04 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
there are a couple issues with your testing code:
Square square1 = new squareOne ( 50 );
should be:
Square square1 = new Square ( 50 );
you are calling the constructor of Square to return a Square object, there is no such thing as squareOne in your program so i doubt that could work.
*similarly for your circle.

also:
double side = Square.getSide();
will not work, Square is not a static class and getSide is not a static method, thus you cannot call this class in this way, because you have instantiated objects that are copies of Square, but the name Square itself, does not represent anything that can be called. Only instantiated.
User is offlineProfile CardPM
+Quote Post

prit876
RE: Square.java, Circle.java, ShapeTest.java
18 Mar, 2007 - 06:29 PM
Post #3

New D.I.C Head
*

Joined: 7 Mar, 2007
Posts: 5


My Contributions
QUOTE(William_Wilson @ 7 Mar, 2007 - 05:04 PM) *

there are a couple issues with your testing code:
Square square1 = new squareOne ( 50 );
should be:
Square square1 = new Square ( 50 );
you are calling the constructor of Square to return a Square object, there is no such thing as squareOne in your program so i doubt that could work.
*similarly for your circle.

also:
double side = Square.getSide();
will not work, Square is not a static class and getSide is not a static method, thus you cannot call this class in this way, because you have instantiated objects that are copies of Square, but the name Square itself, does not represent anything that can be called. Only instantiated.


thank you i think it would havehelped but i forgot to check back on her because it was my first day on the site... Are you a professional coder? because I am stuck in a java class meaning a real class at CSM and I do not have a clue in almost all of the project of what I have to do... can you be like a tutor... and help with everything... I can pay you or can u just help me out on some stuff?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:55AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month