Provide instance fields for title, month, and year (for example, "Scientific American", "April", 2020). Each of these should be accessible only within the Magazine class.Create a constructor, which initializes the instance fieldsWrite a toString() method, modeled after the standard Java toString() method, to return a String representation of the Magazine.Write an equals() method, modeled after the standard Java equals() method. Two Magazines are equal if they have the same title, month, and year.HTML EditorKeyboard Shortcuts

Respuesta :

Answer:

Check the explanation

Explanation:

Note : check attached image for output and program and also note that you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Program : **************Magzine.java**********************

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

public class Magzine {

 

//class variable private can not access outside class

private String title;

private String month;

private int year;

 

//parameterized constructor

public Magzine(String title,String month,int year)

{

this.title=title;

this.month=month;

this.year=year;

}

 

//override toString method

"at"Override

public String toString()

{

String detail=title+" "+month+" "+Integer.toString(year);

return detail;//return string of class variable

}

 

//get Magzine objecte

 

public boolean equals(Magzine obj)

{

//commented returm statement compare string by address so you can uncomment if

//we do not use same string object of String class

//return this.month==obj.month && this.title==obj.title && this.year==obj.year;

//compare two object element if matches return true else false

return (this.month.equals(obj.month)) &&(this.title.equals(obj.title)) && this.year==obj.year;

}

   

}

Program : *************************Main.java****************************

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

public class Main {

/**

* "at"param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Magzine Obj =new Magzine("Scientific American ", "April", 2020); //object of class

Magzine Obj1 =new Magzine("Scientific American ", "April", 2020);//Obj and obj1 is same content data

Magzine Obj2 =new Magzine("Scientific American", "June", 2020); //obj and obj1 same but obj2 different

 

System.out.println(Obj.toString()); //print string of obj

System.out.println(Obj1.toString());//print string of obj1

System.out.println(Obj2.toString());//print string of obj2

 

 

System.out.println(Obj.equals(Obj1)); //obj and obj1 equal and return true

System.out.println(Obj.equals(Obj2)); // obj and obj2 not equal so return false

 

 

}

 

}

Output can be seen below:

Ver imagen temmydbrain