Friday, December 23, 2011

bicycle javaNeed help writing bicycle.java?

he are guidelines
public class G00123_Lab3
{
public static void main( String[] args ) {

// Create 2 Bicycle references

// Create 2 String references for owners' names

// Create 2 integers for license numbers

// Bicycle 1 is owned by Kenny McCormick, license number 12345
// Use the your full name and a license number for Bicycle 2
// This data must be stored in the above String and integer variables.

// Create the first Bicycle object with the default Bicycle constructor

// Set the owner's name and license number with set methods using
// the variables you created as arguments

// Create a second Bicycle object with the other Bicycle constructor
// Use the variables you created as arguments


// Output each owner's name and license number in printf statements
// using the objects and the get methods. For example: bike1.getOwnerName()

}
}




public class Bicycle {

// Instance field
private String ownerName;
private int licenseNumber;

// Defaultbicycle java Constructor
public Bicycle () {}

// Other Constructor
public Bicycle( String name, int license ) {
ownerName = name;
licenseNumber = license;
}

// Returns the name of this bicycle's owner
public String getOwnerName( ) {

return ownerName;
}

// Assigns the name of this bicycle's owner
public void setOwnerName( String name ) {

ownerName = name;
}

// Returns the license number of this bicycle
public int getLicenseNumber( ) {

return licenseNumber;
}

// Assigns the license number of this bicycle
public void setLicenseNumber( int license ) {

licenseNumber = license;
}
}
this what i got so far but keep messing up when i change name and license
"this what i got so far but keep messing up when i change name and license"

That's what you said. Your code doesn't show that you've changed anything. I see a Bicycle domain object. But your main method doesn't do anything, it's just commbicycle javaents. We're not doing your assignment for you. I have a hard time believing you're messing up anything when you haven't done anything. YOUR MAIN METHOD IS EMPTY! (comments don't count).

Show me how you 'keep messing up when changing name an license' and I will help you. I nor will anyone else do your assignment for you.


--------

Oh dear. Everything you did in "Additional Details" is wrong. You already have the Bicycle object you don't need to modify that. You need to modify the "G00123_Lab3" class to use the Bicycle class.

So in your main method where all the comments are you should be doing something like this:

Bicycle bicycle1 = new Bicycle();
bicycle1.setOwnerName("My Name");
bicycle1.setLicenseNumber(12345);

System.out.printf("Owner: %s\nLicense Num: %s", bicycle1.getOwnerName(),bicycle1.getLice…

That should be more than enough to finish your assignment.

No comments:

Post a Comment