231k views
5 votes
Define a new object in variable painter that has properties "name" storing "Vincent van Gogh"; "artworks" storing "The Starry Night", "Irises" and "The Potato Eaters"; "bornDate" storing "March 30, 1853"; and "diedDate" storing "July 29, 1890".

User Lynn
by
5.1k points

2 Answers

3 votes

Final answer:

To define a new object in Java with the given properties, use the code provided

Step-by-step explanation:

To define a new object in Java with the given properties, we can use the following code:

public class Painter {
String name;
ArrayList<String> artworks;
String bornDate;
String diedDate;

public Painter(String painterName, ArrayList<String> painterArtworks, String born, String died) {
name = painterName;
artworks = painterArtworks;
bornDate = born;
diedDate = died;
}

public static void main(String[] args) {
ArrayList<String> artworks = new ArrayList<>();
artworks.add("The Starry Night");
artworks.add("Irises");
artworks.add("The Potato Eaters");

Painter painter = new Painter("Vincent van Gogh", artworks, "March 30, 1853", "July 29, 1890");

System.out.println("Name: " + painter.name);
System.out.println("Artworks: " + painter.artworks);
System.out.println("Born Date: " + painter.bornDate);
System.out.println("Died Date: " + painter.diedDate);
}
}

User Zeroimpl
by
4.8k points
3 votes

Answer:

painter = {'name' : "Vincent van Gogh", 'artworks': ["The Starry Night","Irises","The Potato Eaters"],'bornDate': "March 30, 1853", 'eyeColor': "July 29, 1890", 'diedDate': "July 29, 1890"} #this is a code which holds the questions defined value in a painter variable.

Step-by-step explanation:

  • The above question wants to declare a variable that is in the form of a key and value pair.
  • The above question states to define name, artworks,eyeColor, and dieddate as a key and the other is defined as a value.
  • when a user wants to access the whole dictionary then he can do with the help of the painter variable.
  • But when he wants to access the value of any particular key, then he can do it with the help of the key name as "painter[keyname]".

User Robert Obryk
by
4.5k points