Bob\'s Bike Shop is finally moving into the 21st century and Bob want\'s you to
ID: 3774805 • Letter: B
Question
Explanation / Answer
/**
* enum for bike type
* @author JKishore
*
*/
enum BIKE_TYPE{
Road,Mountain,Hybrid,Cruiser
}
/**
* enum for user type
* @author JKishore
*
*/
enum USER_TYPE{
Men,Women,Boys,Girls
}
/**
* enum for frame material type
* @author JKishore
*
*/
enum FRAME_MATERAIL_TYPE{
Steel,Aluminium,Carbon
}
/**
* enum for brake type
* @author JKishore
*
*/
enum BRAKE_TYPE{
Calliper,Cantilever,LinearPull,Disc
}
/**
* enum for bike condition
* @author JKishore
*
*/
enum CONDITION{
New,Used
}
/**
* enum for wheel size
* @author JKishore
*
*/
enum WHEEL_SIZE{
INCH10(10),
INCH12(12),
INCH114(14),
INCH16(16),
INCH18(18),
INCH20(20),
INCH24(24),
INCH26(26),
INCH29(29);
private final int size;
WHEEL_SIZE(final int newSize) {
size = newSize;
}
public int getValue() {
return size;
}
}
/**
* Bicycle model class
* @author JKishore
*
*/
class Bicycle{
private BIKE_TYPE bikeType;
private USER_TYPE userType;
private FRAME_MATERAIL_TYPE frameMaterialType;
private BRAKE_TYPE braketype;
private WHEEL_SIZE wheelSize;
private int weight;
private int noOfGears;
private String brand;
private String color;
/*
* Bicycle default constructor
*
*/
public Bicycle(){
this.bikeType=BIKE_TYPE.Cruiser;
this.userType=userType.Girls;
this.frameMaterialType=frameMaterialType.Aluminium;
this.braketype=BRAKE_TYPE.Cantilever;
this.wheelSize=WHEEL_SIZE.INCH114;
this.weight=10;
this.noOfGears=5;
this.brand="Harley";
this.color="Red";
};
/*
* Bicycle paramaterized constructor
*
*/
public Bicycle(BIKE_TYPE bikeType, USER_TYPE userType, FRAME_MATERAIL_TYPE frameMaterialType, BRAKE_TYPE braketype,
WHEEL_SIZE wheelSize, int weight, int noOfGears, String brand, String color) {
super();
this.bikeType = bikeType;
this.userType = userType;
this.frameMaterialType = frameMaterialType;
this.braketype = braketype;
this.wheelSize = wheelSize;
this.setWeight(weight);
this.setNoOfGears(noOfGears);
this.brand = brand;
this.color = color;
}
/**
*
* Accessors
*/
public BIKE_TYPE getBikeType() {
return bikeType;
}
public USER_TYPE getUserType() {
return userType;
}
public FRAME_MATERAIL_TYPE getFrameMaterialType() {
return frameMaterialType;
}
public WHEEL_SIZE getWheelSize() {
return wheelSize;
}
public BRAKE_TYPE getBraketype() {
return braketype;
}
public int getWeight() {
return weight;
}
public int getNoOfGears() {
return noOfGears;
}
/**
*
* Mutators
*/
public void setBikeType(BIKE_TYPE bikeType) {
this.bikeType = bikeType;
}
public void setUserType(USER_TYPE userType) {
this.userType = userType;
}
public void setFrameMaterialType(FRAME_MATERAIL_TYPE frameMaterialType) {
this.frameMaterialType = frameMaterialType;
}
public void setBraketype(BRAKE_TYPE braketype) {
this.braketype = braketype;
}
public void setWheelSize(WHEEL_SIZE wheelSize) {
this.wheelSize = wheelSize;
}
/**
*
* @param weight
* @exception IllegalArgumentException
*/
public void setWeight(int weight) {
if(weight<=0){
throw new IllegalArgumentException("Weight can't be zero or neagtive");
}
this.weight = weight;
}
/**
*
* @param noOfGears
* @exception IllegalArgumentException
*/
public void setNoOfGears(int noOfGears) {
if(weight<0){
throw new IllegalArgumentException("Gear can't be negative");
}
this.noOfGears = noOfGears;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return "Bicycle [bikeType=" + bikeType + ", userType=" + userType + ", frameMaterialType=" + frameMaterialType
+ ", braketype=" + braketype + ", wheelSize='" + wheelSize.getValue() + " inches', weight=' "+ weight +" pounds ', noOfGears="
+ noOfGears + ", brand=" + brand + ", color=" + color + "]";
}
}
/**
* Customer model class
* @author JKishore
*
*/
class Customer{
private String firstName;
private String lastName;
private String phoneNumber;
private String emailAddress;
private Bicycle bikeOwned;
/**
* Customer default constructor
*/
public Customer(){
this.firstName="Bob";
this.lastName="Marley";
this.phoneNumber="9876566553";
}
/*
* Customer paramaterized constructor
*
*/
public Customer(String firstName, String lastName, String phoneNumber) {
super();
this.setFirstName(firstName);
this.setLastName(lastName);
this.setPhoneNumber(phoneNumber);
}
/**
*
* Accessors
*/
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getEmailAddress() {
return emailAddress;
}
public Bicycle getBikeOwned() {
return bikeOwned;
}
/**
*
* Mutators
*/
/**
*
* @param firstName
* @exception IllegalArgumentException
*/
public void setFirstName(String firstName) {
if(firstName==null || firstName.length()==0){
throw new IllegalArgumentException("First name can't be blank");
}
this.firstName = firstName;
}
/**
*
* @param lastName
* @exception IllegalArgumentException
*/
public void setLastName(String lastName) {
if(lastName==null || lastName.length()==0){
throw new IllegalArgumentException("Last name can't be blank");
}
this.lastName = lastName;
}
/**
*
* @param phoneNumber
* @exception IllegalArgumentException
*/
public void setPhoneNumber(String phoneNumber) {
if(phoneNumber==null || phoneNumber.length()!=10){
throw new IllegalArgumentException("Phone no can't be blank or less than 10 digit");
}
this.phoneNumber = phoneNumber;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public void setBikeOwned(Bicycle bikeOwned) {
this.bikeOwned = bikeOwned;
}
@Override
public String toString() {
return "Customer [firstName=" + firstName + ", lastName=" + lastName + ", phoneNumber=" + phoneNumber
+ ", emailAddress=" + emailAddress + ", bikeOwned=" + bikeOwned + "]";
}
}
/**
* Demo class for testing
* @author JKishore
*
*/
public class Demo{
public static void main(String args[]){
Bicycle bicycle=new Bicycle();
System.out.println(bicycle);
Customer customer=new Customer("Bob","Marley","9876543231");
customer.setBikeOwned(bicycle);
customer.setEmailAddress("bob.marley@g.com");
System.out.println(customer);
}
}
------------------------------------------------------output--------------------------------------------------------
Bicycle [bikeType=Cruiser, userType=Girls, frameMaterialType=Aluminium, braketype=Cantilever, wheelSize='14 inches', weight=' 10 pounds ', noOfGears=5, brand=Harley, color=Red]
Customer [firstName=Bob, lastName=Marley, phoneNumber=9876543231, emailAddress=bob.marley@g.com, bikeOwned=Bicycle [bikeType=Cruiser, userType=Girls, frameMaterialType=Aluminium, braketype=Cantilever, wheelSize='14 inches', weight=' 10 pounds ', noOfGears=5, brand=Harley, color=Red]]