Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Mag class, given below, would be useful for a small business that sells year

ID: 665179 • Letter: T

Question

The Mag class, given below, would be useful for a small business that sells yearly magazine subscriptions to the public. The attributes for this class are: a magazine's name; the number of issues in a yearly subscription (e.g., 6, 8, or 12); and the price, or cost, of a yearly subscription.


public class Mag{
  private String name; // magazine name
  private int issues; // issues in yearly subscription
  private double cost; // cost of yearly subscription

  public Mag(String n, int i, double cost){
    name = n;
    issues = i;
    this.cost = cost;
  }
  
  public String getName(){return name;}
  public int getIssues(){return issues;}
  public double getCost(){return cost;}

}

In the box below, enter the code for a new method called changeCost, which is to be added to the Mag class definition. It should take one parameter, a double value. If someMag is a magazine the company offers, then


should change the yearly subscription cost for that magazine to $44.00.

Explanation / Answer

public class Mag{
private String name; // magazine name
private int issues; // issues in yearly subscription
private double cost; // cost of yearly subscription

public Mag(String n, int i, double cost){
name = n;
issues = i;
this.cost = cost;
}
  
public String getName(){return name;}
public int getIssues(){return issues;}
public double getCost(){return cost;}
  
public void changeCost(double cost)
{
double newCost;
newCost=cost;
}

}

class Mag1
{
public static void main(String args[])
{
Mag m=new Mag('someMag',1,44.00);;
m.changeCost(44.00);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote