Question

public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor...

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

}
}

Homework Answers

Answer #1
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");
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
public class Auto { private String make; private String model; private int year; } a) write...
public class Auto { private String make; private String model; private int year; } a) write a default constructor for the Auto Class n) Write a constructor to initialize all instance variables c) write accessor and mutator for make variable d) create an onject name it myAuto with values of Toyota, Camry, and 2016
public class Date {    private int month;    private int day;    private int year;...
public class Date {    private int month;    private int day;    private int year;    public Date( int monthValue, int dayValue, int yearValue )    {       month = monthValue;       day = dayValue;       year = yearValue;    }    public void setMonth( int monthValue )    {       month = monthValue;    }    public int getMonth()    {       return month;    }    public void setDay( int dayValue )    {       day =...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
How do I make this: public class Country {     private String name;     private double area;     private...
How do I make this: public class Country {     private String name;     private double area;     private int population;     public Country(String name, double area, int population) {         this.name = name;         this.area = area;         this.population = population;     }     public double getPopulationDensity() {         return population / area;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public double getArea() {         return area;     }     public void setArea(double area) {         this.area = area;     }     public int getPopulation()...
Which method is correct to access the value of count? public class Person { private String...
Which method is correct to access the value of count? public class Person { private String name; private int age; private static int count = 0; } A. private int getCount() {return (static)count;} B. public static int getCount() {return count;} C. public int getCount() {return static count;} D. private static int getCount() {return count;} How can you print the value of count? public class Person { private String name; private int age; private static int count=0; public Person(String a, int...
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
2. String is an example of an immutable class. The Person class that is started below,...
2. String is an example of an immutable class. The Person class that is started below, is not. Add the method haveBirthday that will increase the person’s age and the getter and setter method for the name variable. public class Person{ private String myName; private int myAge; public Person(String name, int age) { myName = name; myAge = age; } public void printMe() { System.out.println(“Name: “ + myName + “\tAge: “ + myAge); } }
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B()...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions:...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions: 1. Fully parametrized Constructor (to initialize class variables) 2. Getter (getBalance()) and Setter (setBalance()) for the float balance, must be greater than zero. In Account.java Methods: checkBalance( ) to print CURRENT BALANCE. deposit(int added_amount) should add add_amount to balance withdraw(int withdraw_amount) should deduct withdraw_amount balance display( ) will print all the information (account number, name, balance). Class 2: AccountTest.java Create an object account1 and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT