public class Bicycle {
// Instance variables (fields)
private String ownerName;
private int licenseNumber;
// Constructor
public Bicycle( String name, int license ) {
ownerName = name;
licenseNumber = license;
}
// Returns the name of the bicycle's owner
public String getOwnerName( ) {
return ownerName;
}
// Assigns the name of the bicycle's owner
public void setOwnerName( String name ) {
ownerName = name;
}
// Returns the license number of the bicycle
public int getLicenseNumber( ) {
return licenseNumber;
}
// Assigns the license number of the bicycle
public void setLicenseNumber( int license ) {
licenseNumber = license;
}
}
////////////////////////////////////////////////
public class BicycleTest {
public static void main( String[] args ) {
// Declare 1 Bicycle reference variable - do NOT initialize
// Declare 1 String reference
variable for the owner's name
// Do NOT initialize
// Declare 1 integer variable for a
license number
// Do NOT initialize
// Assign your full name and a
license number to the String and
// integer variables (initialize
the variables)
// Initialize the Bicycle reference
variable by calling the
// Bicycle class constructor to
create a Bicycle object. Use
// the variables you created as
arguments to the constructor
// Output the owner's name and license number in
printf statements
// using the Bicycle reference
variable and the get methods.
// You must label the output.
// For example:
bike.getOwnerName()
// Change the owner's name to
Albert Einstein using setOwnerName
// Output the owner's name and
license number again in printf statements
// using the Bicycle reference
variable and the get methods.
// You must label the output.
// Output "Programmed by Your Full
Name" substituting your full name
}
}
public class BicycleTest { public static void main(String[] args) { // Declare 1 Bicycle reference variable - do NOT initialize Bicycle bike; // Declare 1 String reference variable for the owner's name // Do NOT initialize String ownerName; // Declare 1 integer variable for a license number // Do NOT initialize int licenseNumber; // Assign your full name and a license number to the String and // integer variables (initialize the variables) ownerName = "Ronaldo"; licenseNumber = 7; // Initialize the Bicycle reference variable by calling the // Bicycle class constructor to create a Bicycle object. Use // the variables you created as arguments to the constructor bike = new Bicycle(ownerName, licenseNumber); // Output the owner's name and license number in printf statements // using the Bicycle reference variable and the get methods. // You must label the output. // For example: bike.getOwnerName() System.out.printf("Owner name: %s, License number: %d\n", bike.getOwnerName(), bike.getLicenseNumber()); // Change the owner's name to Albert Einstein using setOwnerName bike.setOwnerName("Albert Einstein"); // Output the owner's name and license number again in printf statements // using the Bicycle reference variable and the get methods. // You must label the output. System.out.printf("Owner name: %s, License number: %d\n", bike.getOwnerName(), bike.getLicenseNumber()); // Output "Programmed by Your Full Name" substituting your full name System.out.println("Programmed by Cristiano ronaldo"); } }
Get Answers For Free
Most questions answered within 1 hours.