File Magazine.java
public class Magazine {
private String name;
private double price;
private String editor;
private String email;
public Magazine() {
}
public Magazine(String name, double price, String editor, String email) {
this.name = name;
this.price = price;
this.editor = editor;
this.email = email;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
/**
* @return the editor
*/
public String getEditor() {
return editor;
}
/**
* @param editor the editor to set
*/
public void setEditor(String editor) {
this.editor = editor;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Name: " + this.name + "\n" + "Price: " + this.price + "\n" + "Editor: " + this.editor + "\n" + "Email: "
+ this.email + "\n";
}
}
File MagazineApp.java
//Code a class MagazineApp.
// a. This class have a main method
public class MagazineApp {
public static void main(String[] args) {
// b. Code an array that can hold 5 Magazine objects.
Magazine allMagazines[] = new Magazine[5];
// c. Add (hard-code) objects to this array.
allMagazines[0] = new Magazine("Allure", 35.99, "Peter Smith", "Allure@gmail.com");
allMagazines[1] = new Magazine("Elle", 25.99, "Mary Clark", "Elle@gmail.com");
allMagazines[2] = new Magazine("Health", 56.99, "Mike Johnson", "Health@gmail.com");
allMagazines[3] = new Magazine("InStyle", 23.99, "Julia Rob", "InStyle@gmail.com");
allMagazines[4] = new Magazine("Marie Claire", 25.99, "Mary Smith", "MarieClaire@gmail.com");
// d. Display the array on the screen. Use the toString().
// e. Remember to code a heading for the report, as well as a ending message.
System.out.println("All magazines:");
for (int i = 0; i < 5; i++) {
System.out.println(allMagazines[i].toString());
}
}
}
Comments
Leave a comment