Walt Lee

Greenhorn
+ Follow
since Oct 20, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Walt Lee

It is a begging program I know, but getting an error that I can't figure out what is wrong with the line. Still hoping I did this program correctly per instructions:

// Rectangle.java:

package rectangle;

public class Rectangle

{

private double width = 1;

private double height = 1;

private static String color = "white";

public Rectangle() { }

public Rectangle(double w, double h, String c)

{

width = w;

height = h;

color = c;

}

public double getWidth() { return width; }

public void setWidth(double w) { width = w; }

public double getHeight() { return height; }

public void setHeight(double h) { height = h; }

public static String getColor() { return color; }

public static void setColor(String c) { color = c; }

public double findArea() { return height * width; }

}

// ClientProgram.java


package rectangle;

public class ClientProgram

{

public static void main(String args[])

{

Rectangle mySquare = new Rectangle(5, 5, "green");

System.out.print("\n Height = " + mySquare.getHeight() );

System.out.print("\n Width = " + mySquare.getWidth() );

System.out.print("\n Color = " + mySquare.getColor() );

mySquare.setHeight(10);

mySquare.setWidth(15);

System.out.print("\n\n Height = " + mySquare.getHeight() );

System.out.print("\n Width = " + mySquare.getWidth() );

System.out.print("\n Area = " + mySquare.findArea() );

}

}
16 years ago
This is what I have. I am sure it is probably something simple, but can't seeme to find it.




import javax.swing.JOptionPane;

public class Ovrldmeth {

public static void main(String[] args) {


System.out.printf("Num 1\tNum 2\tResult", sub(7,3), sub(13.5,12.6), sub(9.9, 3), sub(6,2.9));

}

public static int sub(int num1, int num2) {
return (num1 > num2) ? num1 - num2 : num2 - num1;
}

public static int sub(double num1, double num2) {
return ((num1 > num2) ? num1 - num2 : num2 - num1);
}

public static int sub(double num1, int num2) {
return ((num1 > num2) ? num1 - num2 : num2 - num1);
}

public static double sub(int num1, double num2) {
return (num1 > num2) ? num1 - num2 : num2 - num1;


}
}
16 years ago
Trying to figure out how to create 3 columns for subtraction, using an overloading method. First column first number and largest, second number smaller number, and 3rd column what the first number subtracting the second number equals. I wasn't doing bad with begginer stuff in java till I started this and just can't figure out what I need to do. The actual instructions are:

Write overloaded Java methods that return the difference of two integers. Your methods should contain the logic to return the difference of the (larger - smaller).

Parm 1 TypeParm 2 TypeReturn Type

int int int
double double double
int double double
double int double


Anyone able to help out. I know it is probably fairly easy, but I am just not figuring it out using the book I have.
[ October 21, 2007: Message edited by: Walt Lee ]
16 years ago