Results 1 to 2 of 2
  1. #1
    zainsayeed is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default Problem with my DimAnal program

    my program, DimAnal...or Dimensional Analysis is supposed to created different shapes and compute the surface area, and volume,etc for it. Along with that it also lets the user input the values in the main program...i dont know why but theres errors in which i dont know how to fix...can i get some help? im a rookie...code is below

    Java Code:
    import javax.swing.*;
    interface DimAnal
    {
        public double volume();
        public double surfarea();
    }
    
    interface ExtraDimAnal extends DimAnal
    {
        public double baseperimeter();
    }
    
    class sphere implements  DimAnal
    {
       public double  radius = 1;
       public double pi = 3.1415926535;
        public  sphere()
        {}
        public sphere(double s)
        {
            radius = s;
        }
        public double volume()
        {
            double v;
            v = (4.0/3) * 3.141592654* radius * radius * radius;
            return v;
        }
        public double surfarea()
        {
        double x;
        x = 4.0 * 3.141592654 * radius * radius;
        return x;
    }
    public void output()
    {
        System.out.println(" \n Sphere " );
        System.out.println(" \n The radius of the Sphere is " + radius);
        System.out.println("\n The volume is " + volume());
        System.out.println("\n The surface area is " + surfarea());  
    }
    }
    
    
    class box implements ExtraDimAnal 
    {
        public double length = 1;
        public double width = 1;
        public double height = 1;
        public double volume;
        public double surfarea;
        public double baseperimeter = 1;
        
        public box()
        {}
        public box (double l, double w, double h)
        {
            l = length;
            w = width;
            h = height;
        } 
        
        public double volume()
        {
            double v;
            v =  length * width * height;
            return v;
        }
        public double surfarea()
        {
            double x;
            x = 2 * (length * width) + 2 * (length * height) + 2 * (width * height);
            return x;
        }
        public double baseperimeter()
        {
            double baseperimeter;
            baseperimeter = length + length + width + width;
            return baseperimeter;
        }
        public void output()
        {
            System.out.println("Box 1");
            System.out.println(" The length of the Box is " + length);
            System.out.println(" The width of the Box is " + width);
            System.out.println(" The height of the Box is " + height);
            System.out.println(" The volume of the Box is " + volume);
            System.out.println("The surface area of the Box is " + surfarea);
            System.out.println(" The base perimeter of the Box is " + baseperimeter);
    }
    }
    class pyramid implements ExtraDimAnal
    {
        public double base = 1;
        public double height = 1;
        public double baseperimeter = 1;
        public double volume = 1;
        public double surfarea;
        
        
        public pyramid()
        {
        }
        public pyramid( double base, double height)
        {
            this.base = base;
            this.height = height;
        }
        public double volume()
        {
            double v;
            v = (1.0/3) * (base * base) * height;
            return v;
        }
        public double surfarea()
        {
            double x;
            x = 2.0 * base * Math.sqrt( 1.0/4 * base * base + height * height + base * base);
            return x;
        }
        public double baseperimeter()
        {
            double baseperimeter;
            baseperimeter = base * 4;
            return baseperimeter;
        }
        public void output()
        {
            System.out.println("  Pyramid ");
            System.out.println(" The base of the Pyramid is " + base);
            System.out.println(" The height of the Pyramid is " + height);
            System.out.println(" The volume of the Pyramid is " + volume);
            System.out.println("  The surface area of the Pyramid " + surfarea);
            System.out.println(" The base perimeter of the Pyramid is " + baseperimeter);
        }
    }
    public class uprightcylinder implements DimAnal
    {
        public double radius = 1;
        public double height = 1;
        public double volume;
        public double surfarea;
        
        public uprightcylinder()
        {
        }
        public uprightcylinder( double radius, double height)
        {
            this.radius = radius;
            this.height = height;
        }
        public double volume()
        {
            double v;
            v = 3.141592654 * (radius * radius) + height;
            return v;
        }
        public double surfarea()
        {
            double x;
            x = (2 * 3.141592654 * radius * height) + (2 * 3.141592654 * (radius * radius));
            return x;
        }
        public void output()
        {
            System.out.println(" Cylinder ");
            System.out.println(" The radius of the cylinder is " + radius);
            System.out.println(" The height of the cylinder is " + height);
            System.out.println( " The volume of the cylinder is " + volume);
            System.out.println(" The surface area of the cylinder is " + surfarea);
        }
        public static void main( String [] args)
        {
            sphere sphere1 = new sphere();
            System.out.println(" This is Sphere 1 ");
            sphere1.volume();
            sphere1.surfarea();
            sphere1.output();
            System.out.println(" ------------------------------------------- ");
            //Sphere 2
            //user will get to input values
            String z;
            double r;
            z = JOptionPane.showInputDialog (" Enter the radius "  );
            r = Double.parseDouble(z);
            sphere sphere2 = new sphere(r);
            System.out.println( " This is Sphere 2 ");
            sphere2.volume();
            sphere2.surfarea();
            sphere2.output();
            System.out.println("  ------------------------------------------- ");
            //Box Objects
            box box1 = new box();
            System.out.println(" This is Box 1 ");
            box1.volume();
            box1.surfarea();
            box1.output();
            System.out.println(" ------------------------------------------- ");
            //Box 2
            String y;
            double l;
            double w;
            y = JOptionPane.showInputDialog( " Enter the length ");
            l = Double.parseDouble(y);
            y = JOptionPane.showInputDialog( " Enter the width ");
            w= Double.parseDouble(y);
            box box2 = new box(double l, double w);
            System.out.println(" This is Box 2 ");
            box2.volume();
            box2.surfarea();
            box2.output();
            System.out.println(" ------------------------------------------- ");
            //Pyramid Objects 
            //Default Object 
            pyramid pyramid1 = new pyramid();
            System.out.println(" This is Pyramid 1 ");
            pyramid1.volume();
            pyramid1.surfarea();
            pyramid1.output();
            System.out.println(" ------------------------------------------- ");
            //Pyramid 2
            //User gets to input the values
            String c;
            double b;
            double h;
            c = JOptionPane.showInputDialog( " Enter the length ");
            b = Double.parseDouble(c);
            c = JOptionPane.showInputDialog( " Enter the height ");
            h = Double.parseDouble(c);
            pyramid pyramid2 = new pyramid( b, h);
            System.out.println(" This is Pyramid 2 ");
            pyramid2.volume();
            pyramid2.surfarea();
            pyramid2.output();
            System.out.println(" ------------------------------------------- ");
            //End Pyramid Objects
            //Begin uprightcylinder 
            uprightcylinder uprightcylinder1 = new uprightcylinger();
            System.out.println(" This is Upright Cylinder 1 ");
            uprightcylinder1.volume();
            uprightcylinder1.surfarea();
            uprightcylinder1.output();
            System.out.println(" ------------------------------------------- ");
            //End of default 
            String t;
            double r;
            double h;
            t =  JOptionPane.showInputDialog(" Enter the radius ");
            r = Double.parseDouble(t);
            t = JOptionPane.showInputDialog( " Enter the height ");
            h = Double.parseDouble(t);
            uprightcylinder uprightcylinder2 = new uprightcylinder( r, h);
            System.out.println(" This is Upright Cylinder 2 ");
            uprightcylinder2.volume();
            uprightcylinder2.surfarea();
            uprightcylinder2.output();
            System.out.println(" ------------------------------------------- ");
            //End of Upright Cylinder objects 
        }
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,514
    Rep Power
    25

    Default Re: Problem with my DimAnal program

    theres errors in which i dont know how to fix
    Please copy the full text of the error message and paste it here. It has important info about the errors.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. problem with this program
    By bunty83 in forum New To Java
    Replies: 7
    Last Post: 11-01-2011, 11:05 PM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Problem with first program...
    By JavaNoob1998 in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 12:39 PM
  4. Can anyone tell me problem in this program ??
    By sahildave1991 in forum AWT / Swing
    Replies: 3
    Last Post: 07-02-2010, 05:37 PM
  5. Problem in Program
    By Abbinormal in forum New To Java
    Replies: 9
    Last Post: 01-08-2010, 03:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •