Question

In: Computer Science

IN JAVA!   Write a class Store which includes the attributes: store name, city. Write another class...

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

Solutions

Expert Solution

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:


Related Solutions

Write a class Store which includes the attributes: store name and sales tax rate. Write another...
Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a method returning the average taxes per year....
Write a Java class. The class name must be ShapeMetrics, which means the file name must...
Write a Java class. The class name must be ShapeMetrics, which means the file name must be ShapeMetrics.java. Provide the following functions: 1. getAreaOfRectangle(), with two float arguments, width and height, in that order, returning a float value which is the area of the rectangle with that width and height. 2. getSpaceDiagonalOfRectangularCuboid (), with three float arguments, width, height, and depth, in that order, returning a float value which is the length of the diagonal line which bisects the cuboid....
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Write a class Car that contains the following attributes: The name of car The direction of...
Write a class Car that contains the following attributes: The name of car The direction of car (E, W, N, S) The position of car (from imaginary zero point) The class has the following member functions: A constructor to initialize the attributes. Turn function to change the direction of car to one step right side (e.g. if the direction is to E,it should be changed to S and so on.) Overload the Turn function to change the direction to any...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Using JAVA Create a class Client. Your Client class should include the following attributes: Company Name...
Using JAVA Create a class Client. Your Client class should include the following attributes: Company Name (string) Company id (string) Billing address (string) Billing city (string) Billing state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyClient that inherits from the Client class.   HourClient must use the inherited parent class variables and add in hourlyRate and hoursBilled. Your Hourly Client class should contain a constructor that calls the constructor from the Client class to initialize...
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Write a Python class to represent a Salik account. The account has three attributes, a name,...
Write a Python class to represent a Salik account. The account has three attributes, a name, id, and the balance. The balance is a private attribute. The class has extra functions to add to the balance and reduce the balance. Both, these functions should return the current balance and if the balance is below AED 50.0 print the message “Note: Balance Below 50”. Your class must work for the code given below. #Test myCar = SalikAccount() myCar.setName("John") myCar.setID("190300300333") myCar.setBal(20.0) yourCar...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT