this is the question.
A customer has a name, an email address and a list of supplements which they are interested in.
A paying customer has a payment method and a list of associate customers whom they also pay for.
An associate customer is a customer whose subscription is paid for by a specified paying customer.
A payment method could be by a specified credit card or direct debit from a specified bank account.
A supplement has a name and a weekly cost.
The magazine also has a weekly cost for the main part.
Each week, each customer gets an email telling them their magazine is ready to look at and listing the supplements that they currently subscribe to.
Each month, each paying customer gets an email telling them how much is being charged to their card or account for the month and itemizing the cost by supplements for them and any of their associate customers.
Design and implement enough functionality in the classes to allow the operation of the following test program (which you also design, implement, test, and document):
The client program should do the following:
a) construct a magazine with an array of 3-4 supplements with made-up details built in to the program (Alternatively, get input from the user using the Java Scanner class),
b) construct an array of 5-6 different customers of various types with made-up details built in to the program (Alternatively, get input from the user using the Java Scanner class),
c) view details of all customers stored in the array,
d) print out the text of all the emails for all customers for one week of magazines,
e) print out the text for the end of month emails for the paying customers,
f) add a new customer to the magazine service,
g) remove an existing customer from the magazine service.
Display enough information during the running of the program to allow checking of its operation.
/*
* 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.
*/
package assignmentmag;
import java.util.*;
/**
*
* @author Matt Burdan
* S.No: 32307288
*/
public class AssignmentMag {
public static void main(String[] args){
//Make a new Magazine
Magazine newMag = new Magazine();
newMag.setTitle("Matts Test Magizine");
System.out.println(newMag.getTitle());
//Add some supplements using addSuppsToList
addSuppsToMag(newMag);
//View all the supplements briefly
newMag.viewSuppsBrief();
//View all the supplements in detail
newMag.viewSupps();
//View the supplement number i
addCustomertomag(newMag);
}
//addSuppsToList(Magazine)
//Adds various supplements to the magazine provided
public static void addSuppsToMag(Magazine inMag){
//Make a new supplement: Counterstrike
Supplement testSupp = new Supplement();
//Set its values
testSupp.setSuppName("Counter-strike");
testSupp.setSuppInfo("Subscribe to this supplement to get all the information "
+ "you could ever want to regarding Counterstrike!");
testSupp.setSuppCost(6);
//Add the supplement to the magazine
inMag.addSupp(testSupp);
//Make a new supplement: Titanfall
Supplement testSupp2 = new Supplement("Titanfall", 6, "Subscribe to this "
+ "supplement to get all the information you could ever want to "
+ "regarding Titanfall!");
//Add the supplement to the magazine
inMag.addSupp(testSupp2);
//Make a new supplement: Left for dead
Supplement testSupp3 = new Supplement("Left for dead", 6, "Subscribe to this "
+ "supplement to get all the information you could ever want to "
+ "regarding Left for dead!");
//Add the supplement to the magazine
inMag.addSupp(testSupp3);
//Make a new supplement: Halo
Supplement testSupp4 = new Supplement("Halo", 6, "Subscribe to this "
+ "supplement to get all the information you could ever want to "
+ "regarding Halo!");
//Add the supplement to the magazine
inMag.addSupp(testSupp4);
}
public static void addCustomertomag(Magazine inMag){
Customer testCust = new Customer();
testCust.setCustname("MattB");
testCust.setemail("matt_burdan@fakemail.com");
testCust.setPaymentinfo("PayPal");
inMag.addCust(testCust);
Customer testCust2 = new Customer();
testCust.setCustname("Josh");
testCust.setemail("joshn@fakemail.com");
testCust.setPaymentinfo("creditcard");
inMag.addCust(testCust2);
Customer testCust3 = new Customer();
testCust.setCustname("Tim");
testCust.setemail("timtam@fakemail.com");
testCust.setPaymentinfo("debitcard");
inMag.addCust(testCust3);
Customer testCust4 = new Customer();
testCust.setCustname("Aaron");
testCust.setemail("aron@fakemail.com");
testCust.setPaymentinfo("creditcard");
inMag.addCust(testCust4);
}
}
/*
* 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.
*/
package assignmentmag;
import java.util.*;
/**
*
* @author MattBurdan
*/
public class Magazine {
//Declare class variables
private String magTitle;
private String weeklyNot;
private String monthlyNot;
private double costPerWeek;
private double costPerMonth;
private ArrayList<Supplement> supplements = new ArrayList();
private int issueNo;
//Mutator Functions
//setTitle(String)
//Sets the name of the title to the string provided
public void setTitle(String inTitle){
magTitle = inTitle;
}
//setWeeklyNot(String)
//Sets the weekly notificcation to the string provided
public void setWeeklyNot(String inNot){
weeklyNot = inNot;
}
//setMontlyNot(String)
//Sets the monthly notification to the string provided
public void setMonthlyNot(String inNot){
monthlyNot = inNot;
}
//setWeeklyCost(double)
//Sets the weekly cost of the magazine to the value provided
public void setWeeklyCost(double inCost){
costPerWeek = inCost;
}
//setMonthlyCost(double)
//Sets the monthly cost to the value provided
public void setMonthlyCost(double inCost){
costPerMonth = inCost;
}
//addSupplement(Supplement)
//Adds the supplement provided to the list of supplements
public void addSupp(Supplement inSupp){
supplements.add(inSupp);
}
//delSupplement(Supplement)
//Removes provided supplement from the list of supplements
public void delSupp(Supplement inSupp){
supplements.remove(inSupp);
}
//Accessor Functions
//getTitle()
//Returns the title of the magazine
public String getTitle(){
return magTitle;
}
//weeklyNotification()
//Returns the weeklyNotification
public String weeklyNotification(){
return weeklyNot;
}
//monthlyNotification()
//Returns the monthly notification
public String monthlyNotification(){
return monthlyNot;
}
//getWeeklyCost()
//Returns the weekly cost of the magazine
public double getWeeklyCost(){
return costPerWeek;
}
//getMonthlyCost()
//Returns the monthly cost of the magazine
public double getMonthlyCost(){
return costPerMonth;
}
public Supplement getSupplement(int i){
Supplement result = new Supplement();
//Make sure supplement list not emptyp
if(!supplements.isEmpty())
{
if(i <= supplements.size())
{
result = supplements.get(i-1);
}
}
return result;
}
//viewSuppsBrief()
//Displays a brief list of the supplements available
public void viewSuppsBrief(){
//Check if supplement list is not empty
if(!supplements.isEmpty())
{
System.out.println("Current Supplements");
System.out.println("The current supplements are: " + supplements.size());
System.out.println();
for(int i = 0; i < supplements.size(); i++)
{
System.out.println("Number " + (i +1) +": " + supplements.get(i).getSuppName());
System.out.println();
}
}
}
//viewSupps
//Displays a listing of the current supplements available
public void viewSupps(){
//Display count of current supplements
System.out.println("Current Supplements");
System.out.println("The current supplements are: " + supplements.size());
System.out.println();
//Display information for each supplement
for(int i = 0; i < supplements.size(); i++)
{
System.out.print("Cost of supplement: $");
System.out.printf("%.2f\n", supplements.get(i).getSuppCost());
System.out.println("Number " + (i + 1));
System.out.println("Name of Supplement:" + supplements.get(i).getSuppName());
System.out.println(supplements.get(i).getSuppInfo( ));
System.out.println();
}
}
//viewSupp(i)
//Print out the details of the supplement at index i
public void viewSupp(int i){
//Make sure list is not empty
if(!supplements.isEmpty())
{
if((i > 0) && (i <= supplements.size()))
{
System.out.print("Cost of supplement: $");
System.out.printf("%.2f\n", supplements.get(i).getSuppCost());
System.out.println("Number " + i);
System.out.println("Name of Supplement:" + supplements.get(i-1).getSuppName());
System.out.println(supplements.get(i-1).getSuppInfo());
System.out.println();
}
}
}
}
/*
* 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.
*/
package assignmentmag;
/**
*
* @author MattBurdan
*/
public class Supplement {
//Declare Supplement Variables
private String suppName; //Name of the supplement
private double cost; //Cost of subscription
private String info; //Brief description of supplement
//Constructors
//Supplement()
//Creates a new supplement using default values
Supplement(){
suppName = "This field not yet set!";
cost = 0.00;
info = "This field not yet set!";
}
//Supplement(String, double, String)
//Creates a new supplement and sets its name, cost and info to those
//values supplied
Supplement(String inName, double inCost, String inInfo){
suppName = inName;
cost = inCost;
info = inInfo;
}
//Mutator functions
//setSuppName(String)
//Set the name of the supplement to supplied string
public void setSuppName(String inName){
suppName = inName;
}
//setSuppCost(double)
//Sets the cost of the supplement to value provided
public void setSuppCost(double inCost){
cost = inCost;
}
//setSuppInfo(String)
//Sets the info field to a brief description of supplement provided
public void setSuppInfo(String inInfo){
info = inInfo;
}
//Accessor functions
//getSuppName()
//Returns the name of the supplement
public String getSuppName(){
String value;
//If suppName not yet set, return a message indicating such
if(suppName.isEmpty())
{
value = "This field not set yet.";
}
else
{
value = suppName;
}
return value;
}
//getSuppCost()
//Returns the cost of the supplement
public double getSuppCost(){
return this.cost;
}
//getSuppInfo()
//Returns a brief description of the supplement
public String getSuppInfo(){
String value;
//If info not yet set, return a message indicating such
if(info.isEmpty())
{
value = "This field not set yet.";
}
else
{
value = info;
}
return value;
}
}