java - Testing my program? -
i have class need implement in code. instructions are: code testing program/class. should construct or instantiate objects of class coded in step #1. testing program should call every method make sure work. should construct @ least 2 objects – 1 default constructor , 1 “other” constructor. second scenario, ask user values (radius and) height. may use input , output want this.
this have far , i'm stuck:
public class cube { private double height; public cube(){ height = 1.0; } public cube(double h){ height = h; } public double getheight(){ return height; } public void setheight(double h){ height = h; } public double calcvolume() { return height*height*height; } public double calcsurface(){ return height*height*6; } public string tostring(){ return this.tostring(); } public boolean equals(cube c){ return (c.getheight() == this.height); } } import java.util.* public class testthecube { public static void main(string[] args) { cube cube1 = new cube(); scanner kb = new scanner(system.in); system.out.print("enter height positive number"); double height = kb.nextdouble(); cube cube2 = new cube(height); system.out.println( } }
i've invoked calcvolume()
of cube1
, cube2
.
cube cube1 = new cube(); scanner kb = new scanner(system.in); system.out.print("enter height positive number"); double height = kb.nextdouble(); cube cube2 = new cube(height); system.out.println("cube 1's volume = "+cube1.calcvolume()); system.out.println("cube 2's volume = "+cube2.calcvolume()); .....//repeat every instance method have.
Comments
Post a Comment