How do i debug the application attached consisting of four Java classes

***************     Pictures of screen shots to go here  *****************


Color.java
public class Color extends Object {
   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 extends Object {    
   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 extends Object {
   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 ); 
   }
}

I'm on my way to class, so don't have much time to look through your code...but one thing that DOES jump out is the fact that in all your void methods, you still have returns. By declaring the method void (i.e. public void setColor()), you don't return anything. If, using the same example, you DID want to return a color when the method was called, then you would use public Color setColor(); Also, you're incorrectly importing classes and I'm not sure what the Color.java, Miles.java, etc are for. Start off by correcting these and I'll get back at ya to see if I can be of any more help.

In the future, we don't need to know how URGENT your request is. Urgency should ideally be determined on a first-come, first-serve basis: If you posted before someone else, you should get precedence before that other person.

Further, it's simply rude to imply that your question is more important than other posters. This is a free, community run, forum. Please respect the fact that we're doing this free for the benefit of all, not just you.

Alt F4
Colld u please tell or show me where i am illegally importing classes.
regards,
PS.

Ok, to start with, this (everything between the /* and */ in front of it is something I'm saying about the code)

public Color()
   {// constructor
      return setColor( "" ); /* this is calling the second setColor method, not the first one. The first one would take nothing, you are giving it a string of "", so the second method is called*/
   }

   public void setColor()
   {
      color = "black";
      return color; /* you can't have a return statement in a void, either change void to Color, or comment out the return. Secondly, you really should change that color to something like theColor, to make it clearer*/
   }
        
   public void setColor( String m )
   {
      color = m;
      return color;
/* same thing here*/ 
   }

Ok, that's for the first bit.

This

private final double miles;
      
   public Miles()
   {
      setMile( 0.0 ); 
   }

   public void setMile( double m )
   {
      miles = ( ( m >= 0.0 && m <= 200000 ) ? m : 0 );
   }

I don't completely understand. As I understand 'final' you don't want it to change, but then you have a method to set it. I don't really understand that code, maybe you could explain it to me, and maybe there isn't a problem.

Ok, now for this bit:

public Person( String firstName, String lastName )
   {/* again, you don't really want the duplicates. I'm reasonably certain that you need a this.lastName = getLastName(), but again, don't go declaring duplicate strings, you can create problems that way, and it makes things a little harder to look at (at least for me) */
      lastName = getLastname();/*typo here, that N in name should be capitalized*/ 
      firstName = getFirstName(); 
   }

   public String getFirstName()
   {
      return firstName; 
   }

   public String getLastName()
   {
      return lastName;        
   }

And I think the rest of it should be fine. I'm not 100% on that, I'd have to copy it in and compile/run it with the changes, but that's the best I can do to eyeball it.

Thank you for your help i got it out eventually

lastName = getLastname();
	  firstName = getFirstName();

You have that in your Person constructor, and it makes no sense. You're calling a method that will obviously return a value that hasn't been set yet. I believe this is what you want to do:

public Person( String fn, String ln)
{
	   lastName = fn;
	   firstName = ln;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.