Results 1 to 8 of 8
  1. #1
    RBDiaz31 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Inheritance......nothing shows up

    I am not showing any errors but when I go to run the program nothing is happening can someone tell me what I am doing wrong???


    import javax.swing.JOptionPane;

    public class InheritanceTest {

    public static void main(String[] args) {
    Point[] shapeAR = new Point[3];

    try {
    shapeAR[0] = new Point(0, 0);
    shapeAR[1] = new Square(0, 0);
    shapeAR[2] = new Cube(0, 0);
    } catch (Exception e) {
    JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
    "ERROR!!", JOptionPane.ERROR_MESSAGE);

    }

    }

    }

    class Point {
    protected double x;
    protected double y;
    private String xString, yString;// converted later to double x/y

    public Point(double x1, double y1) {
    x = x1;
    y = y1;
    }

    public String getXString() {
    return xString;
    }

    public String getYString() {
    return yString;
    }

    public double getX() {
    return x;
    }

    public double getY() {
    return y;
    }

    public void getUserInput() {
    xString = JOptionPane.showInputDialog("Enter for x:");
    x = Double.parseDouble(xString);

    yString = JOptionPane.showInputDialog("Enter for y:");
    y = Double.parseDouble(yString);

    }

    public String toString1() {
    return "X :" + x + "\n" + "Y :" + y + "\n";
    }

    }

    class Square extends Point {
    protected double sideLength;
    private String sideString;// Converted to Double
    public double perimeter, area;

    public Square(double x1, double y1) {
    super(x1, y1);

    }

    public double getSideLength() {
    return sideLength;
    }

    public String getSideStrength() {
    return sideString;
    }

    public void getSideInput() {

    super.getUserInput();
    sideString = JOptionPane.showInputDialog("Enter for side length:");
    sideLength = Double.parseDouble(sideString);

    perimeter = sideLength * 4;
    area = sideLength * sideLength;

    }

    public String toString1() {
    return "X :" + x + "\n" + "Y :" + y + "\n" + "Side Length :"
    + sideLength + "Perimeter :" + perimeter + "\n" + "Area :"
    + area + "\n";
    }
    }

    class Cube extends Square {

    public Cube(double x1, double y1) {
    super(x1, y1);

    }

    protected double depth, volume;

    public void getVoidInput() {

    super.getUserInput();
    super.getSideInput();

    depth = 6 * area;
    volume = depth * area;
    }

    public String toString() {
    return "X :" + x + "\n" + "Y :" + y + "\n" + "Depth:" + depth + "\n"
    + "Area :" + area + "\n" + "Volume :" + volume + "\n";
    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Inheritance......nothing shows up

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    RBDiaz31 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Inheritance......nothing shows up

    I don't understand.......

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Inheritance......nothing shows up

    If you follow Darryl's advice and read the links it will provide information on how to post code in a readable format as well as other valuable information on how to improve your chances of getting help.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Inheritance......nothing shows up

    As for your problem, your code creates 3 objects places them into an array and then ends. What were you expecting to happen? If you want some output to be displayed on the screen then perhaps you should call some methods on those objects.

  6. #6
    RBDiaz31 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Inheritance......nothing shows up

    ok that makes sense see I was thinking that calling the array it would call from the class I guess I was confused.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Inheritance......nothing shows up

    I have no idea what you mean.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,379
    Blog Entries
    7
    Rep Power
    20

    Default Re: Inheritance......nothing shows up

    A Cube is a Square is a Point? c'mon ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Code works but nothing shows
    By Hagelslag in forum New To Java
    Replies: 2
    Last Post: 01-21-2013, 06:03 PM
  2. formatter shows nothing
    By nonybrighto in forum New To Java
    Replies: 10
    Last Post: 12-27-2012, 01:55 PM
  3. output shows null !!!!
    By jawa in forum New To Java
    Replies: 3
    Last Post: 12-11-2012, 10:15 PM
  4. Canvas Only Shows on Resize
    By K3R in forum AWT / Swing
    Replies: 5
    Last Post: 03-28-2012, 10:28 PM
  5. JTable in Frame only shows 3 rows
    By Laura Warren in forum New To Java
    Replies: 4
    Last Post: 12-24-2008, 05:48 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
  •