Question

Write a Java Program You are being tasked with creating a bike store. You need to...

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.

Homework Answers

Answer #1

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}
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
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the...
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the BookStore class has the following members : long id; String name; Address address; Book book; The Address class has the following attributes : String streetName; String houseNumber; String apartmentNumber; String zipCode; The book class has the following members String name; String isbn; Author author; The Author class within the book class has the following member : String firstName; String lastName; Date dateOfBirth; Address address;...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Module 4 Code L Write a short code snippet creating a class with three class variables...
Module 4 Code L Write a short code snippet creating a class with three class variables and one method setting all three variables. The class is called Person and the variables should be name, birth, and address. You should supply a method called setAll() that will be used to set the values of the class variables. // This is a JAVA program! I am a little confused any help would be great :)
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
/* Write a function that looks for a particular person in their respective linked list The...
/* Write a function that looks for a particular person in their respective linked list The only place you need to write code is the "find" method in the linked list class */ #include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); #define BUFFLEN 10 /* Each "person" is defined by their name, zipcode, and their pet's name. Persons are hashed by their zipcode. */ //---------------------------------------------------------------------------- /* function declarations ------------------------*/ int computeKey(int); void add_to_buffer(string,int,string); void find_in_buffer(int);...
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT