Question

JAVA PROGRAMME A class called “Gallery” to hold information in an auto gallery catalog It will...

JAVA PROGRAMME
A class called “Gallery” to hold information in an auto gallery catalog
It will be described. “Gallery” class, brand (String) belonging to cars, model (int), price (double), color
(String) will hold the fuel type (String) and body type (String) attributes. Also a class named “Mother”
It will be. Values will be assigned to the properties of the “Gallery” class, and objects will be produced through this class.

a. Write the specified classes in Java programming language.
b. By defining the properties of the cars as public, it is worth these features from the "Main" class.
Make the assignment.
c. If the properties belonging to the cars are defined as private, these properties from the "Main" class
How is the value assigned? What is the name of this technique?
D. What is the constructar method? What are the features of the constructar method? Example above
When we think about it, we can directly assign values to the properties in the catalog.
write the constructar method

sorry for bad english translate :).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

if class Gallery has all the attribute public then code is


public class Gallery {
public String brand;
public int model;
public double price;
public String color;
public String fuelType;
public String bodyType;
}

public class Mother {

public static void main(String[] args) {
Gallery car=new Gallery();
car.bodyType="Steel";
car.brand="Marti";
car.color="Balck";
car.fuelType="Petrol";
car.model=2019;
car.price=23000;
}
  
}

you can directly access and assing properties of the Gallery class because  we are declaring the properties to public.

If the properties are declared private then we cant directrly assing the properties of the class we have to use constructor and mutor and accessor methods

Constructor is a special function(method) it is called when the object of the
class is created.

When you creat an object of the class with new keyword on of the constructor is called
this is called default constructor beause it has no perameters.

Constructor is used to initialize the properties of the class.

Example using gallery class is

Gallery class


public class Gallery {
private String brand;
private int model;
private double price;
private String color;
private String fuelType;
private String bodyType;

//parameterized cunstroctor
public Gallery(String brand, int model, double price, String color, String fuelType, String bodyType) {
this.brand = brand;
this.model = model;
this.price = price;
this.color = color;
this.fuelType = fuelType;
this.bodyType = bodyType;
}

  
//mutator methords
public void setBrand(String brand) {
this.brand = brand;
}

  

public void setModel(int model) {
this.model = model;
}

  

public void setPrice(double price) {
this.price = price;
}

  

public void setColor(String color) {
this.color = color;
}

  

public void setFuelType(String fuelType) {
this.fuelType = fuelType;
}

public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
  
//accessor methods
public String getBodyType() {
return bodyType;
}
public String getFuelType() {
return fuelType;
}
public String getColor() {
return color;
}
public double getPrice() {
return price;
}
public int getModel() {
return model;
}
public String getBrand() {
return brand;
}
}

Mother class

public class Mother {

public static void main(String[] args) {
//creating Gallery class object with the perameter
Gallery car=new Gallery("Maruti",2019,23000,"Black","Petrol","Steel");
  
}
  
}

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
JAVA PROGRAMME A class called “Gallery” to hold information in an auto gallery catalog It will...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Program: Design a class “Book” with the data attributes title - String, author - String,...

    Java Program: Design a class “Book” with the data attributes title - String, author - String, yearPublished - integer and price - double. Write a parameterized constructor that initializes the attributes. Write accessor and mutator methods, and a print method that prints all of the attributes. In the main method, create a single object and give it values of your choice. Call the print method to print the values. Sample Run: The Book is: The Art of Computer Programming Donald...

  • Write code to create a Java class called "Student". The class should hold information about a...

    Write code to create a Java class called "Student". The class should hold information about a student: name, id and whether or not the student is currently registered. There should be a constructor that takes name, id and registration status. Add getters and setters for the three properties. Make sure that you use appropriate visibility modifiers (public vs. private).

  • Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which...

    Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which accept type of String Add English, French, Italian and Arabic strings into languageList array object Print languageList using Iterator object Sort ArrayList object alphabetically Print languageList using Iterator object Solution will produce following: ArrayListExample class ArrayList object called languageList ArrayListExampleTest class with main method

  • The Java class called Holiday is started below. An object of class Holiday represents a holiday...

    The Java class called Holiday is started below. An object of class Holiday represents a holiday during the year. This class has three instance variables: name, which is a String representing the name of the holiday day, which is an int representing the day of the month of the holiday month, which is a String representing the month the holiday is in public class Holiday { private String name; private int day; private String month; // your code goes here...

  • in JAVA Which of the following attributes would be MOST appropriate for a class called Book,...

    in JAVA Which of the following attributes would be MOST appropriate for a class called Book, that represents a book in a library? libraryName, location, libraryHours title, author, typeOfBook pages, cost, shipping anything, anytime, anywhere Which of the following statements is FALSE regarding constructors? A constructor allows you to set up an object once it is instantiated. A constructor does not have a return type. A constructor must have the same name as the name of the class. You can...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's...

    Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1 in the textbook and in LMS). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double). Give your classes...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • Write the following in Java Design a class called ReviewSystem, this class should have an attribute...

    Write the following in Java Design a class called ReviewSystem, this class should have an attribute reviewList, which is an ArrayList type. add a constructor to initialize the attribute. add a method addReviewAndComment(). This method asks from the user to provide an integer (0 to 4 for the five ratings) and a String as a comment. If the user inputs -1, it ends the loop of asking. All valid user inputs should be saved to the reviewList attribute. For example:...

  • Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able...

    Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT