Here is the entire code, and the new error. Does the main method need to be in the "Box" class? I need the second class to test the constructors to make sure they all work properly, that is what the book wants me to do.
Error:Code:// Program that ues constructors to assig values (length, width and height) to a box import javax.swing.JOptionPane; // Create "Box" class public class Box { // Declare variables private int length; private int width; private int height; // Constructors to set length, width, and height public Box(int length) { this.length = length; this.width = 0; this.height = 0; // Display box length JOptionPane.showMessageDialog(null, "Line created with length " + length); } public Box(int length, int width) { this.length = length; this.width = width; this.height = 0; // Display box length and width JOptionPane.showMessageDialog(null, "Rectangle created with length " + length + " and width " + width); } public Box(int length, int width, int height) { this.length = length; this.width = width; this.height = height; // Display box length and width JOptionPane.showMessageDialog(null, "Box created with length " + length + ", width " + width + ", and height " + height); System.exit(0); } } public class BoxTest { // Main method public void main(String[] args) { Box boxOne = new Box(1); Box boxTwo = new Box(1,2); Box boxThree = new Box(1,2,3); } }
Box.java:53: class BoxTest is public, should be declared in a file named BoxTest.java
public class BoxTest
^
1 error




Reply With Quote