You are on page 1of 2

//The second file... save as SmartPhone.java in the same folder. package cartester; import javax.swing.

*; public class Car { private String carType, carModel, carYear, carPrice, carColour, carSpeed; private String type,model, year, price, colour, speed ; public Car (){ //user enters everything //Ask user type String str1 = JOptionPane.showInputDialog ("What type of car do you own?\nFor example: Mazda"); //Model String str2 = JOptionPane.showInputDialog ("What model is it?\nFor e xample: Carolla"); //Year String str3 = JOptionPane.showInputDialog ("How old is it?\nFor exam ple: 2013"); //Price String str4 = JOptionPane.showInputDialog ("How much does it cost?\n For example: $20,000"); //Colour String str5 = JOptionPane.showInputDialog ("What colour is it?\nFor example: Black and Yellow"); //Speed String str6 = JOptionPane.showInputDialog ("How fast is it?\nFor exa mple: 250km/h"); //No car type was sent - pick random carType=str1; carModel =str2; carYear = str3; carPrice = str4; carColour=str5; carSpeed = str6; } public Car( String type, String model, String year, String price, String colour, String speed) //default { carType=type; carModel=model; carYear=year; carPrice=price; carColour=colour; carSpeed=speed;

} public Car (String type, String model, String year) //Half { carType=type; carModel=model; carYear=year; } public String toString () { //outputs String output = "Type: " + carType + "\n"; output += "Model: " + carModel + "\n"; output += "Year: " + carYear + "\n"; output += "Price: " + carPrice + "\n"; output += "Colour: " + carColour + "\n"; output += "Speed: " + carSpeed + "\n"; //output string is complete, return it return output; }

You might also like