Printing my toString method
Hi. I'm trying to get it so that I can print off my toString method. Or send the variable allStr from the toString method to the main method and print it there. I don't know enough about Java to figure it out myself, and I could really use some help.
Code:
import javax.swing.JOptionPane;
public class Driver
{
String license;
String name;
String street;
String city;
String province;
public Driver()
{
license = "N/A";
name = "N/A";
street = "N/A";
city = "N/A";
province = "N/A";
}
public Driver( String lE, String nE, String sT, String cY, String pE )
{
license = lE;
name = nE;
street = sT;
city = cY;
province = pE;
}
public String toString( Driver drStr)
{
String licStr = license;
String namStr = name;
String strStr = street;
String citStr = city;
String proStr = province;
String allStr = licStr + " belongs too " + namStr + " who lives at " + strStr + " in " + citStr + ", " + proStr;
System.out.println( allStr );
return allStr;
}
public static void main( String[] args )
{
Driver driver;
System.out.println( "This is the main method" );
String lE = (JOptionPane.showInputDialog( "License number:" ));
String nE = (JOptionPane.showInputDialog( "Name:" ));
String sT = (JOptionPane.showInputDialog( "Street:" ));
String cY = (JOptionPane.showInputDialog( "City:" ));
String pE = (JOptionPane.showInputDialog( "Province:" ));
driver = new Driver( lE, nE, sT, cY, pE );
System.out.println( toString );
}
}