In: Computer Science
IN JAVA!
Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork.
Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method returning the average number of paintings per artist.
You should create a test class which creates 2 Art Gallery objects, then calls your set methods, get methods, toString and equals methods and average paintings per artist for the Art Gallery objects. MAKE THE PROGRAM ASK USER FOR THE INPUTS ALSO THANKS
STORE CLASS:
public class Store {
private String name;
private String city;
public Store() {
super();
}
public Store(String name, String city) {
super();
this.name = name;
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "Store [name=" + name + ",
city=" + city + "]";
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method
stub
Store store=(Store) obj;
if(store.getCity().contentEquals(city) &&
store.getName().contentEquals(name)) {
return
true;
}else {
return
false;
}
}
}
ART GALLERY CLASS:
public class ArtGallery extends Store{
private int numberOfPaintinigsSold;
private int numberOfArtists;
public ArtGallery() {
super();
}
public ArtGallery(String name, String city, int
numberOfPaintinigsSold, int numberOfArtists) {
super(name, city);
this.numberOfPaintinigsSold =
numberOfPaintinigsSold;
this.numberOfArtists =
numberOfArtists;
}
public int getNumberOfPaintinigsSold() {
return
numberOfPaintinigsSold;
}
public void setNumberOfPaintinigsSold(int
numberOfPaintinigsSold) {
this.numberOfPaintinigsSold =
numberOfPaintinigsSold;
}
public int getNumberOfArtists() {
return numberOfArtists;
}
public void setNumberOfArtists(int numberOfArtists)
{
this.numberOfArtists =
numberOfArtists;
}
@Override
public String toString() {
return "ArtGallery
[numberOfPaintinigsSold=" + numberOfPaintinigsSold + ",
numberOfArtists=" + numberOfArtists
+ "]";
}
public float averagePaintingsPerArtist() {
return
((float)numberOfPaintinigsSold)/numberOfArtists;
}
}
MAIN CLASS:
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner scanner=new
Scanner(System.in);
//create first Art Gallery
object
ArtGallery gallery1=new
ArtGallery();
//take the input from user and set
the attributes of Art Gallery 1
System.out.println("Enter the name
of your Art Gallery 1: ");
gallery1.setName(scanner.nextLine());
System.out.println("Enter the city
of "+gallery1.getName()+" :");
gallery1.setCity(scanner.nextLine());
System.out.println("Enter the
number of paintings sold every year at "+gallery1.getName()+"
:");
gallery1.setNumberOfPaintinigsSold(scanner.nextInt());
System.out.println("Enter the
number of artists at "+gallery1.getName()+" :");
gallery1.setNumberOfArtists(scanner.nextInt());
scanner.nextLine(); //skip the next
input
//create first Art Gallery
object
ArtGallery gallery2=new
ArtGallery();
//take the input from user and set
the attributes of Art Gallery 1
System.out.println("Enter the name
of your Art Gallery 2: ");
gallery2.setName(scanner.nextLine());
System.out.println("Enter the city
of "+gallery2.getName()+" :");
gallery2.setCity(scanner.nextLine());
System.out.println("Enter the
number of paintings sold every year at "+gallery2.getName()+"
:");
gallery2.setNumberOfPaintinigsSold(scanner.nextInt());
System.out.println("Enter the
number of artists at "+gallery2.getName()+" :");
gallery2.setNumberOfArtists(scanner.nextInt());
System.out.println("Average number
of paintings per Artist at "+gallery1.getName()+" is :-
"+gallery1.averagePaintingsPerArtist());
System.out.println("Average number
of paintings per Artist at "+gallery2.getName()+" is :-
"+gallery2.averagePaintingsPerArtist());
}
}
OUTPUT: