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);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.