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
  • 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...

  • 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...

  • 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...

  • 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 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:...

  • In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes...

    In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...

  • dateInformation class. visual basic. Crate a class called DateInformation that includes three pieces of information as...

    dateInformation class. visual basic. Crate a class called DateInformation that includes three pieces of information as intense variable- a month(type Integer), a day(type Integer) and year (type Integer). Your class should provide properties that enables a client of the class to get and set the month, day, year values.The set acessor should perform validation and throw exception for invalid values. You class should have a constructor that initializes the three instances variables and uses the class's property to set each...

  • In java. You are provided an abstract class called MyAbstract. You can only modify the writeFile...

    In java. You are provided an abstract class called MyAbstract. You can only modify the writeFile () class. You are provided another class called Finally you are provided the file you must read from in the MyAbstract class. You will need to extend MyAbstract to MyTestClass. You should have the following outputs. The content of myData employee avg salary number of employees File that was created in myFile() Everything I was provided is listed already. l. Servers ary 1 35...

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
ADVERTISEMENT