Color.java
public class Color { private String color;
public Color() { return setColor( "" ); }
public void setColor() { color = "black"; return color; }
public void setColor( String m ) { color = m; return color; }
public String toColorString() { return color; } }
Miles.java
import java.text.DecimalFormat;
public class Miles { private final double miles;
public Miles() { setMile( 0.0 ); }
public void setMile( double m ) { miles = ( ( m >= 0.0 && m <= 200000 ) ? m : 0 ); }
public String toMilesString() { DecimalFormatformatMile = new DecimalFormat( "0" ); return formatMile.format( miles ); } }
Person.java
public class Person { private String firstName; private String lastName;
public Person( String firstName, String lastName ) { lastName = getLastname(); firstName = getFirstName(); }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; } }
Test.java
import javax.swing.JOptionPane;
public class Test {
public static void main( String args[] ) { String firstName = JOptionPane.showInputDialog( "Enter your First name" ); String lastName = JOptionPane.showInputDialog( "Enter your Last name" ); String color2 = JOptionPane.showInputDialog( "What color is your car? " ); String miles = JOptionPane.showInputDialog( "how many miles have you" + " driven in your car? " );
double miles2 = Double.parseDouble( miles );
Miles mile = new Miles(); Color color = new Color(); Person person = new Person( firstName , lastName );
mile.setMile( miles2 ); color.setColor( color2 );
String output = person.getFirstName()+ " " + person.getLastName() + " drove his/her " + color.toString() + " car " + " for " + mile.toUniversalString() + " Miles";
JOptionPane.showMessageDialog( null, output, "Testing class Race", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); } }