chuck
Posts: 9
Nickname: chuckjava2
Registered: Jul, 2002
|
|
Please HelpPPPPPPPPP.
|
Posted: Jul 8, 2002 10:14 PM
|
|
Advertisement
|
I don't know what is wrong in this program. It doesn't work. Please help. Thank you very much.
public abstract class Cube { private double width, height, depth; private String name;
public Cube() {width = height = depth =0.0; name = "null";}
public Cube(double w, double h, double d, String n) {width =w; height =h; depth =d; name =n;}
public Cube(double x, String n) {width = height = depth = x; name = n;}
public Cube(Cube ob) {width = ob.width; height = ob.height; depth = ob.depth; name = ob.name;}
double getWidth() {return width;} double getHeight() {return height;} double getDepth() {return depth;} void setWidth(double w) {width =w;} void setHeight(double h) {height =h;} void setDepth(double d) epth =d;
public double getArea() {return width * height * depth;}
public abstract String open();
public abstract String close();
public String getName() {return "Cube";}
public String toString() {return "Object ";} }
public class Box extends Cube { private int numberOfFlaps; private String positionOfFlaps;
public Box() {super();}
public Box(double w, double h, double d, String n, int num, String p) {super(w, h, d, n); numberOfFlaps =num; positionOfFlaps =p;}
public Box(double x, String n, int num, String p) {super(x, n); numberOfFlaps =num; positionOfFlaps =p;System.out.println("in Box()");}
public Box(Box ob) {super(ob);}
public String foldFlaps() {return "Flaps are fold";}
public String isOpen() { int i = (int)Math.random() * 2; if(i>=1) open(); close(); } public String open() {return "is opened"; }
public String close() {return "is closed";}
public String getName() {return "Box";}
public String toString() {super.toString();} }
public class Case extends Cube { private String positionOfLid, latchOpen;
public Case() {super();}
public Case(double w, double h, double d, String n, String p) {super(w, h, d, n); positionOfLid =p;}
public Case(double x, String n, String p) {super(x, n); positionOfLid =p;}
public Case(Case ob) {super(ob);}
public String isOpen() { int i = (int)Math.random() * 2; if(i==0) return close(); return open(); }
public String closeLatch() {return "Latches are closed";}
public String open() {return "is opened";}
public String close() {return "is closed";}
public String getName() {return "Case";}
public String toString() {super.toString();} }
public class Suitcase extends Case { private String zipperOpen, positionOfLid, latchOpen;
public Suitcase() {super();}
public Suitcase(double w, double h, double d, String n, String p) {super(w, h, d, n, p);}
public Suitcase(double x, String n, String p) {super(x, n, p);}
public Suitcase(Suitcase ob) {super(ob);}
public String isOpen() { int i = (int)Math.random() * 2; if(i>=1) open(); close(); }
public String closeZipper() {return "Zippers are closed";}
public String closeLatch() {return "Latches are closed";}
public String open() {return super.open();}
public String close() {return super.close();}
public String getName() {return "Suitcase ";}
public String toString() {super.toString();} }
import javax.swing.*; import java.text.DecimalFormat; import java.awt.Graphics;
public class Assign3th extends JApplet { public static void init(String[] args) { DecimalFormat precision2 = new DecimalFormat("0.00");
Box b1 = new Box(1.0, 2.0, 3.0, "Box", 8, "stand up once"); Box b2 = new Box(3.0, "Box", 8, "stand up twice"); Case c1 = new Case(4.0, 5.0, 6.0, "Case", "laydown once"); Case c2 = new Case(6.0, "Case", "laydown twice"); Suitcase s1 = new Suitcase(7.0, 8.0, 9.0, "Suitcase", "flies once"); Suitcase s2 = new Suitcase(9.0, "Suitcase", "flies twice");
String output = b1.toString() + b1.getName() + b1.isOpen() + "\n" + b2.toString() + b2.getName() + b2.isOpen() + "\n" + c1.toString() + c1.getName() + c1.isOpen() + "\n" + c2.toString() + c2.getName() + c2.isOpen() + "\n" + s1.toString() + s1.getName() + s1.isOpen() + "\n" + s2.toString() + s2.getName() + s2.isOpen() + "\n";
Cube[] c = new Cube[6];
c[0] = b1; c[1] = b2; c[2] = c1; c[3] = c2; c[4] = s1; c[5] = s2;
for(int i=0; i<c.length; i++) output += c.toString() + c.getName();
JOptionPane.showMessageDialog(null, output, "Assignment 3th", JOptionPane.INFORMATION_MESSAGE);
} }
|
|