Write a Java Program
You are being tasked with creating a bike store. You need to create the following classes following the principles of encapsulation :
1. BikeStore -- This class will contain the following variables : String name, Address address, int numberOfBikes
2. Address -- This class will contain the following variables : String streetName, String city, String state, String zipCode
3. App -- This class will contain the main method and will print out the Bike store name and address. Please write the code in your IDE and attach the individual files.
public class Address { private String streetName; private String city; private String state; private String zipCode; public Address() { } public Address(String streetName, String city, String state, String zipCode) { this.streetName = streetName; this.city = city; this.state = state; this.zipCode = zipCode; } public String getStreetName() { return streetName; } public void setStreetName(String streetName) { this.streetName = streetName; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getZipCode() { return zipCode; } public void setZipCode(String zipCode) { this.zipCode = zipCode; } public String toString() { return "Address{" + "streetName='" + streetName + '\'' + ", city='" + city + '\'' + ", state='" + state + '\'' + ", zipCode='" + zipCode + '\'' + '}'; } }
public class BikeStore { private String name; private Address address; private int numberOfBikes; public BikeStore() { } public BikeStore(String name, Address address, int numberOfBikes) { this.name = name; this.address = address; this.numberOfBikes = numberOfBikes; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public int getNumberOfBikes() { return numberOfBikes; } public void setNumberOfBikes(int numberOfBikes) { this.numberOfBikes = numberOfBikes; } public String toString() { return "BikeStore{" + "name='" + name + '\'' + ", address=" + address + ", numberOfBikes=" + numberOfBikes + '}'; } }
public class App { public static void main(String[] args) { BikeStore bs = new BikeStore("ABC Bike store", new Address("xyz street","def city","ghi state","123456"),10); System.out.println(bs); } }
BikeStore{name='ABC Bike store', address=Address{streetName='xyz street', city='def city', state='ghi state', zipCode='123456'}, numberOfBikes=10}
Get Answers For Free
Most questions answered within 1 hours.