Answer to Question #231579 in Java | JSP | JSF for Chadwin Fritz

Question #231579

Magazine


-name: String

-price: double

-editor: String

-email: String


+Magazine() <<constructor>>

+Magazine(String, double, String, String) <<constructor>>

+getters()

+setters()

+toString:() String


1. Code the Magazine class according to the class diagram.

2. Code a class MagazineApp.

a. This class have a main method.

b. Code an array that can hold 5 Magazine objects.

c. Add (hard-code) objects to this array.

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.


1
Expert's answer
2021-08-31T17:35:53-0400




class Magazine {
	private String name;
	private double price;
	private String editor;
	private String email;


	Magazine() {
	}


	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";
	}
}


//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 magazines[] = new Magazine[5];
		// c. Add (hard-code) objects to this array.
		magazines[0] = new Magazine("Rolling Stone", 45.99, "Peter Smith", "RollingStone@gmail.com");
		magazines[1] = new Magazine("GQ", 35.99, "Mary Clark", "GQ@gmail.com");
		magazines[2] = new Magazine("Time", 25.99, "Mike Johnson", "Time@gmail.com");
		magazines[3] = new Magazine("Cosmopolitan", 15.99, "Julia Rob", "Cosmopolitan@gmail.com");
		magazines[4] = new Magazine("Men's Health", 85.99, "Mary Smith", "MensHealth@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("\nAll magazines:");
		for (int i = 0; i < 5; i++) {
			System.out.println(magazines[i].toString());
		}


	}
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS