first commit
This commit is contained in:
BIN
Semester 1/Programming 1/Homework 4/Company.class
Normal file
BIN
Semester 1/Programming 1/Homework 4/Company.class
Normal file
Binary file not shown.
26
Semester 1/Programming 1/Homework 4/Company.ctxt
Normal file
26
Semester 1/Programming 1/Homework 4/Company.ctxt
Normal file
@@ -0,0 +1,26 @@
|
||||
#BlueJ class context
|
||||
comment0.params=name
|
||||
comment0.target=Company(java.lang.String)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Company\n
|
||||
comment1.params=
|
||||
comment1.target=Company()
|
||||
comment1.text=\n\ Default\ constructor\ for\ objects\ of\ class\ Company\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getName()
|
||||
comment2.text=\n\ Returns\ the\ name\ of\ the\ company.\n
|
||||
comment3.params=
|
||||
comment3.target=java.util.ArrayList\ getWebsiteList()
|
||||
comment3.text=\n\ Returns\ the\ list\ elements\ of\ websiteList.\n
|
||||
comment4.params=name
|
||||
comment4.target=void\ setName(java.lang.String)
|
||||
comment4.text=\n\ Set\ the\ name\ of\ the\ company\ to\ a\ new\ value.\n
|
||||
comment5.params=website
|
||||
comment5.target=void\ storeWebsite(Website)
|
||||
comment5.text=\n\ Store\ a\ website\ in\ the\ websiteList\n
|
||||
comment6.params=threshold
|
||||
comment6.target=java.util.ArrayList\ findProfitableWebsites(int)
|
||||
comment6.text=\n\ Returns\ the\ most\ profitable\ sites,\ of\ which\ are\ above\ a\ specified\ threshold\n\ of\ earnings.\n
|
||||
comment7.params=holiday
|
||||
comment7.target=java.util.ArrayList\ findMembersHoliday(Holiday)
|
||||
comment7.text=\n\ Returns\ the\ members\ currently\ on\ any\ given\ holiday\ within\ the\ company,\ across\n\ all\ websites.\n
|
||||
numComments=8
|
100
Semester 1/Programming 1/Homework 4/Company.java
Normal file
100
Semester 1/Programming 1/Homework 4/Company.java
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
/**
|
||||
* Creates objects to hold websites. Allows the viewing of the most profitable website,
|
||||
* and the website user's currently on specific holidays.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @28/11/23
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Company
|
||||
{
|
||||
// Instanciate a new ArrayList to hold all the websites.
|
||||
private ArrayList<Website> websiteList = new ArrayList<Website>();
|
||||
|
||||
// Holds the value of the company name.
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Company
|
||||
*/
|
||||
public Company( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class Company
|
||||
*/
|
||||
public Company()
|
||||
{
|
||||
name = "The Company";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the company.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list elements of websiteList.
|
||||
*/
|
||||
public ArrayList<Website> getWebsiteList()
|
||||
{
|
||||
return websiteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the company to a new value.
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a website in the websiteList
|
||||
*/
|
||||
public void storeWebsite( Website website )
|
||||
{
|
||||
websiteList.add( website );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most profitable sites, of which are above a specified threshold
|
||||
* of earnings.
|
||||
*/
|
||||
public ArrayList<Website> findProfitableWebsites( int threshold )
|
||||
{
|
||||
ArrayList<Website> profitableSites = new ArrayList<Website>();
|
||||
for( Website website : websiteList )
|
||||
{
|
||||
if( website.getSalesTotal() > threshold )
|
||||
profitableSites.add( website );
|
||||
}
|
||||
return profitableSites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the members currently on any given holiday within the company, across
|
||||
* all websites.
|
||||
*/
|
||||
public ArrayList<Member> findMembersHoliday( Holiday holiday )
|
||||
{
|
||||
ArrayList<Member> membersOnHoliday = new ArrayList<Member>();
|
||||
for( Website website : websiteList )
|
||||
{
|
||||
for( Member member : website.getLoggedInList() )
|
||||
{
|
||||
if( member.getHoliday().getRefNumber().equals( holiday.getRefNumber() ) )
|
||||
membersOnHoliday.add( member );
|
||||
}
|
||||
}
|
||||
return membersOnHoliday;
|
||||
}
|
||||
}
|
BIN
Semester 1/Programming 1/Homework 4/Friend.class
Normal file
BIN
Semester 1/Programming 1/Homework 4/Friend.class
Normal file
Binary file not shown.
23
Semester 1/Programming 1/Homework 4/Friend.ctxt
Normal file
23
Semester 1/Programming 1/Homework 4/Friend.ctxt
Normal file
@@ -0,0 +1,23 @@
|
||||
#BlueJ class context
|
||||
comment0.params=name\ money
|
||||
comment0.target=Friend(java.lang.String,\ double)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Friend\n
|
||||
comment1.params=
|
||||
comment1.target=Friend()
|
||||
comment1.text=\n\ Default\ constructor\ for\ objects\ of\ class\ Friend.\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getName()
|
||||
comment2.text=\n\ Returns\ the\ name\ of\ the\ friend.\n
|
||||
comment3.params=
|
||||
comment3.target=double\ getMoney()
|
||||
comment3.text=\n\ Returns\ the\ balance\ in\ their\ account.\n
|
||||
comment4.params=name
|
||||
comment4.target=void\ setName(java.lang.String)
|
||||
comment4.text=\n\ Sets\ the\ name\ of\ the\ friend\ to\ a\ new\ value.\n
|
||||
comment5.params=money
|
||||
comment5.target=void\ setMoney(double)
|
||||
comment5.text=\n\ Sets\ the\ balance\ of\ the\ friend\ to\ a\ new\ value.\n
|
||||
comment6.params=
|
||||
comment6.target=java.lang.String\ toString()
|
||||
comment6.text=\n\ Returns\ the\ current\ state\ of\ the\ field\ variables\ as\ a\ string,\ with\ newlines\ after\ each.\n
|
||||
numComments=7
|
74
Semester 1/Programming 1/Homework 4/Friend.java
Normal file
74
Semester 1/Programming 1/Homework 4/Friend.java
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
/**
|
||||
* Creates objects to represent a friend of a member, allowing them to order a holiday with
|
||||
* other people through the service.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @28/11/23
|
||||
*/
|
||||
public class Friend
|
||||
{
|
||||
// String variable holding the name of the friend
|
||||
private String name;
|
||||
|
||||
// Integer variable indicating the balance of the friend
|
||||
private double money;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Friend
|
||||
*/
|
||||
public Friend( String name, double money )
|
||||
{
|
||||
this.name = name;
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class Friend.
|
||||
*/
|
||||
public Friend()
|
||||
{
|
||||
name = "Mark Dude";
|
||||
money = 250.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the friend.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the balance in their account.
|
||||
*/
|
||||
public double getMoney()
|
||||
{
|
||||
return money;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the friend to a new value.
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the balance of the friend to a new value.
|
||||
*/
|
||||
public void setMoney( double money )
|
||||
{
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current state of the field variables as a string, with newlines after each.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return ( "name : " + this.name + "\n" + "money : " + this.money );
|
||||
}
|
||||
}
|
BIN
Semester 1/Programming 1/Homework 4/Holiday.class
Normal file
BIN
Semester 1/Programming 1/Homework 4/Holiday.class
Normal file
Binary file not shown.
26
Semester 1/Programming 1/Homework 4/Holiday.ctxt
Normal file
26
Semester 1/Programming 1/Homework 4/Holiday.ctxt
Normal file
@@ -0,0 +1,26 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Holiday()
|
||||
comment0.text=\n\ Default\ constructor\ for\ objects\ of\ class\ Holiday\n
|
||||
comment1.params=refNumber\ type\ price
|
||||
comment1.target=Holiday(java.lang.String,\ java.lang.String,\ int)
|
||||
comment1.text=\n\ Constructor\ for\ objects\ of\ class\ Holiday.\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getRefNumber()
|
||||
comment2.text=\n\ Return\ the\ reference\ number\ of\ the\ holiday.\n
|
||||
comment3.params=
|
||||
comment3.target=java.lang.String\ getType()
|
||||
comment3.text=\n\ Return\ the\ type\ of\ the\ holiday.\n
|
||||
comment4.params=
|
||||
comment4.target=int\ getPrice()
|
||||
comment4.text=\n\ Return\ the\ price\ of\ the\ holiday.\n
|
||||
comment5.params=refNumber
|
||||
comment5.target=void\ setRefNumber(java.lang.String)
|
||||
comment5.text=\n\ Set\ the\ reference\ number\ of\ the\ holiday\ to\ a\ new\ value.\n
|
||||
comment6.params=type
|
||||
comment6.target=void\ setType(java.lang.String)
|
||||
comment6.text=\n\ Set\ the\ type\ of\ the\ holiday\ to\ a\ new\ value.\n
|
||||
comment7.params=price
|
||||
comment7.target=void\ setPrice(int)
|
||||
comment7.text=\n\ Set\ the\ price\ of\ the\ holiday\ to\ a\ new\ value.\n
|
||||
numComments=8
|
87
Semester 1/Programming 1/Homework 4/Holiday.java
Normal file
87
Semester 1/Programming 1/Homework 4/Holiday.java
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
/**
|
||||
* Write a description of class Holiday here.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @3/11/23
|
||||
*/
|
||||
public class Holiday
|
||||
{
|
||||
// Create a String variable to hold the reference number.
|
||||
private String refNumber;
|
||||
|
||||
// Create a String variable to hold the type of holiday.
|
||||
private String type;
|
||||
|
||||
// Create an integer variable to hold the price in pounds of the holiday.
|
||||
private int price;
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class Holiday
|
||||
*/
|
||||
public Holiday()
|
||||
{
|
||||
// initialise instance variables
|
||||
refNumber = "W001";
|
||||
type = "beach";
|
||||
price = 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Holiday.
|
||||
*/
|
||||
public Holiday( String refNumber, String type, int price )
|
||||
{
|
||||
this.refNumber = refNumber;
|
||||
this.type = type;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the reference number of the holiday.
|
||||
*/
|
||||
public String getRefNumber()
|
||||
{
|
||||
return refNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the holiday.
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the price of the holiday.
|
||||
*/
|
||||
public int getPrice()
|
||||
{
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reference number of the holiday to a new value.
|
||||
*/
|
||||
public void setRefNumber( String refNumber )
|
||||
{
|
||||
this.refNumber = refNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of the holiday to a new value.
|
||||
*/
|
||||
public void setType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the price of the holiday to a new value.
|
||||
*/
|
||||
public void setPrice( int price )
|
||||
{
|
||||
this.price = price;
|
||||
}
|
||||
}
|
BIN
Semester 1/Programming 1/Homework 4/Member.class
Normal file
BIN
Semester 1/Programming 1/Homework 4/Member.class
Normal file
Binary file not shown.
70
Semester 1/Programming 1/Homework 4/Member.ctxt
Normal file
70
Semester 1/Programming 1/Homework 4/Member.ctxt
Normal file
@@ -0,0 +1,70 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Member()
|
||||
comment0.text=\n\ Default\ Constructor\ for\ objects\ of\ Class\ Member.\n
|
||||
comment1.params=email\ membershipNumber
|
||||
comment1.target=Member(java.lang.String,\ int)
|
||||
comment1.text=\n\ Constructor\ for\ objects\ of\ class\ Member\n
|
||||
comment10.params=email
|
||||
comment10.target=void\ setEmail(java.lang.String)
|
||||
comment10.text=\n\ Replaces\ the\ value\ of\ @email\ with\ a\ new\ value.\n
|
||||
comment11.params=membershipNumber
|
||||
comment11.target=void\ setMembershipNumber(int)
|
||||
comment11.text=\n\ Replaces\ the\ value\ of\ @membershipNumber\ with\ new\ value.\n
|
||||
comment12.params=loggedInStatus
|
||||
comment12.target=void\ setLoggedInStatus(boolean)
|
||||
comment12.text=\n\ Replaces\ the\ value\ of\ @loggedInStatus\ with\ new\ value.\n
|
||||
comment13.params=website
|
||||
comment13.target=void\ setWebsite(Website)
|
||||
comment13.text=\n\ Sets\ the\ object\ pointed\ to\ by\ the\ member.\n
|
||||
comment14.params=holiday
|
||||
comment14.target=void\ setHoliday(Holiday)
|
||||
comment14.text=\n\ Sets\ the\ object\ pointed\ to\ by\ the\ member.\n\ Currently\ used\ to\ clear\ the\ member's\ checkout\ after\ paying.\n
|
||||
comment15.params=money
|
||||
comment15.target=void\ setMoney(double)
|
||||
comment15.text=\n\ Sets\ the\ value\ of\ the\ money\ variable\ to\ a\ new\ value\n
|
||||
comment16.params=friend
|
||||
comment16.target=void\ storeFriend(Friend)
|
||||
comment16.text=\n\ Stores\ a\ friend\ /\ companion\ in\ the\ companions\ arrayList.\n
|
||||
comment17.params=
|
||||
comment17.target=void\ listFriends()
|
||||
comment17.text=\n\ Lists\ the\ value\ of\ each\ friend\ object\ in\ the\ companions\ list.\n
|
||||
comment18.params=holiday
|
||||
comment18.target=void\ selectHoliday(Holiday)
|
||||
comment18.text=\n\ Allows\ member\ to\ select\ a\ holiday\ object,\ provided\ they\ are\ logged\ into\ a\ website.\n
|
||||
comment19.params=
|
||||
comment19.target=void\ payForHoliday()
|
||||
comment19.text=\n\ Allows\ member\ to\ pay\ for\ a\ holiday,\ provided\ they\ are\ logged\ in,\ passing\ itself\ to\ website.checkout().\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getEmail()
|
||||
comment2.text=\n\ Returns\ the\ value\ of\ @email.\n
|
||||
comment20.params=
|
||||
comment20.target=java.lang.String\ toString()
|
||||
comment20.text=\n\ Returns\ the\ current\ state\ of\ field\ variables\ as\ a\ string,\ with\ newlines\ after\ each.\n
|
||||
comment21.params=holidayPrice
|
||||
comment21.target=boolean\ checkMoney(int)
|
||||
comment21.text=\n\ Checks\ if\ each\ person\ buying\ the\ holiday\ can\ afford\ it,\ returning\ a\ true\ or\ false.\n
|
||||
comment22.params=holidayPrice
|
||||
comment22.target=void\ whoCannotPay(int)
|
||||
comment3.params=
|
||||
comment3.target=int\ getMembershipNumber()
|
||||
comment3.text=\n\ Returns\ the\ value\ of\ @membershipNumber.\n
|
||||
comment4.params=
|
||||
comment4.target=boolean\ getLoggedInStatus()
|
||||
comment4.text=\n\ Returns\ the\ value\ of\ @loggedInStatus.\n
|
||||
comment5.params=
|
||||
comment5.target=Holiday\ getHoliday()
|
||||
comment5.text=\n\ Returns\ the\ current\ selected\ holiday\ object.\n
|
||||
comment6.params=
|
||||
comment6.target=Website\ getWebsite()
|
||||
comment6.text=\n\ Returns\ the\ current\ logged\ in\ website\ object.\n
|
||||
comment7.params=
|
||||
comment7.target=double\ getMoney()
|
||||
comment7.text=\n\ Returns\ the\ current\ balance\ of\ the\ member\n
|
||||
comment8.params=
|
||||
comment8.target=java.util.ArrayList\ getCompanions()
|
||||
comment8.text=\n\ Returns\ the\ companions\ arrayList\n
|
||||
comment9.params=
|
||||
comment9.target=int\ getNumberOfCompanions()
|
||||
comment9.text=\n\ Get\ the\ size\ of\ the\ companions\ list\n
|
||||
numComments=23
|
278
Semester 1/Programming 1/Homework 4/Member.java
Normal file
278
Semester 1/Programming 1/Homework 4/Member.java
Normal file
@@ -0,0 +1,278 @@
|
||||
|
||||
/**
|
||||
* Represents a user of a holiday website.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @13/11/23
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
public class Member
|
||||
{
|
||||
// Creates a String for variable @email.
|
||||
private String email;
|
||||
|
||||
// Creates an integer for variable @membershipNumber.
|
||||
private int membershipNumber;
|
||||
|
||||
// Creates a boolean for variable @loggedInStatus.
|
||||
private boolean loggedInStatus;
|
||||
|
||||
//Creates a new pointer to a Holiday object.
|
||||
private Holiday holiday;
|
||||
|
||||
// Creates a new pointer to a Website object.
|
||||
private Website website;
|
||||
|
||||
//Holds a list of friends / companions a member has.
|
||||
private ArrayList<Friend> companions = new ArrayList<Friend>();
|
||||
|
||||
// Stores the balance of the member.
|
||||
private double money;
|
||||
|
||||
/**
|
||||
* Default Constructor for objects of Class Member.
|
||||
*/
|
||||
public Member()
|
||||
{
|
||||
email = "john.doe@topstravel.co.uk";
|
||||
membershipNumber = 1;
|
||||
loggedInStatus = false;
|
||||
money = 500.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Member
|
||||
*/
|
||||
public Member( String email, int membershipNumber )
|
||||
{
|
||||
// initialise instance variables
|
||||
this.email = email;
|
||||
this.membershipNumber = membershipNumber;
|
||||
loggedInStatus = false;
|
||||
money = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of @email.
|
||||
*/
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of @membershipNumber.
|
||||
*/
|
||||
public int getMembershipNumber()
|
||||
{
|
||||
return membershipNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of @loggedInStatus.
|
||||
*/
|
||||
public boolean getLoggedInStatus()
|
||||
{
|
||||
return loggedInStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current selected holiday object.
|
||||
*/
|
||||
public Holiday getHoliday()
|
||||
{
|
||||
return holiday;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current logged in website object.
|
||||
*/
|
||||
public Website getWebsite()
|
||||
{
|
||||
return website;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current balance of the member
|
||||
*/
|
||||
public double getMoney()
|
||||
{
|
||||
return money;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the companions arrayList
|
||||
*/
|
||||
public ArrayList<Friend> getCompanions()
|
||||
{
|
||||
return companions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the companions list
|
||||
*/
|
||||
public int getNumberOfCompanions()
|
||||
{
|
||||
return companions.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the value of @email with a new value.
|
||||
*/
|
||||
public void setEmail( String email )
|
||||
{
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the value of @membershipNumber with new value.
|
||||
*/
|
||||
public void setMembershipNumber( int membershipNumber )
|
||||
{
|
||||
this.membershipNumber = membershipNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the value of @loggedInStatus with new value.
|
||||
*/
|
||||
public void setLoggedInStatus( boolean loggedInStatus )
|
||||
{
|
||||
this.loggedInStatus = loggedInStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the object pointed to by the member.
|
||||
*/
|
||||
public void setWebsite( Website website )
|
||||
{
|
||||
this.website = website;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the object pointed to by the member.
|
||||
* Currently used to clear the member's checkout after paying.
|
||||
*/
|
||||
public void setHoliday( Holiday holiday )
|
||||
{
|
||||
this.holiday = holiday;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the money variable to a new value
|
||||
*/
|
||||
public void setMoney( double money )
|
||||
{
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a friend / companion in the companions arrayList.
|
||||
*/
|
||||
public void storeFriend( Friend friend )
|
||||
{
|
||||
companions.add( friend );
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the value of each friend object in the companions list.
|
||||
*/
|
||||
public void listFriends()
|
||||
{
|
||||
for( Friend friendMessage : companions )
|
||||
{
|
||||
System.out.println( friendMessage.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows member to select a holiday object, provided they are logged into a website.
|
||||
*/
|
||||
public void selectHoliday( Holiday holiday )
|
||||
{
|
||||
if( loggedInStatus )
|
||||
{
|
||||
if ( checkMoney( holiday.getPrice() ) )
|
||||
{
|
||||
this.holiday = holiday;
|
||||
System.out.println( "member ID: " + membershipNumber );
|
||||
System.out.println( "holiday ref number: " + holiday.getRefNumber() );
|
||||
System.out.println( "holiday type: " + holiday.getType() );
|
||||
System.out.println( "holiday price: £" + holiday.getPrice() );
|
||||
}
|
||||
else
|
||||
whoCannotPay( holiday.getPrice() );
|
||||
}
|
||||
else {
|
||||
System.out.println( "You are not logged in" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows member to pay for a holiday, provided they are logged in, passing itself to website.checkout().
|
||||
*/
|
||||
public void payForHoliday()
|
||||
{
|
||||
if( loggedInStatus )
|
||||
{
|
||||
// Collect the cost of the holiday from each friend, and add to main member.
|
||||
for( Friend friend : companions )
|
||||
{
|
||||
// Negate amount from friend.
|
||||
friend.setMoney( friend.getMoney() - holiday.getPrice() );
|
||||
// Add amount to member.
|
||||
setMoney( getMoney() + holiday.getPrice() );
|
||||
}
|
||||
// Since the amount must be taken here, the member will be credited later.
|
||||
money -= ( holiday.getPrice() * ( getNumberOfCompanions() + 1 ) );
|
||||
//Pass current member to the checkout method of website
|
||||
website.checkout( this );
|
||||
}
|
||||
else {
|
||||
System.out.println( "You are not logged in" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current state of field variables as a string, with newlines after each.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return ( "membership number : " + this.membershipNumber + "\n" + "email : " + this.email + "\n" + "logged in status : " + this.loggedInStatus );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if each person buying the holiday can afford it, returning a true or false.
|
||||
*/
|
||||
private boolean checkMoney( int holidayPrice )
|
||||
{
|
||||
if( money >= holidayPrice )
|
||||
{
|
||||
boolean allCanAfford = true;
|
||||
for( Friend friend : companions )
|
||||
{
|
||||
if( friend.getMoney() <= holidayPrice )
|
||||
{
|
||||
allCanAfford = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allCanAfford;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void whoCannotPay( int holidayPrice )
|
||||
{
|
||||
if( money < holidayPrice )
|
||||
System.out.println( membershipNumber + " has insufficient money to afford this holiday");
|
||||
for( Friend friend : companions )
|
||||
{
|
||||
if( friend.getMoney() < holidayPrice )
|
||||
{
|
||||
System.out.println( friend.getName() + " has insufficient money to afford this holiday");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
Semester 1/Programming 1/Homework 4/README.TXT
Normal file
12
Semester 1/Programming 1/Homework 4/README.TXT
Normal file
@@ -0,0 +1,12 @@
|
||||
------------------------------------------------------------------------
|
||||
This is the project README file. Here, you should describe your project.
|
||||
Tell the reader (someone who does not know anything about this project)
|
||||
all he/she needs to know. The comments should usually include at least:
|
||||
------------------------------------------------------------------------
|
||||
|
||||
PROJECT TITLE:
|
||||
PURPOSE OF PROJECT:
|
||||
VERSION or DATE:
|
||||
HOW TO START THIS PROJECT:
|
||||
AUTHORS:
|
||||
USER INSTRUCTIONS:
|
BIN
Semester 1/Programming 1/Homework 4/Website.class
Normal file
BIN
Semester 1/Programming 1/Homework 4/Website.class
Normal file
Binary file not shown.
47
Semester 1/Programming 1/Homework 4/Website.ctxt
Normal file
47
Semester 1/Programming 1/Homework 4/Website.ctxt
Normal file
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Website()
|
||||
comment0.text=\n\ Default\ constructor\ for\ objects\ of\ class\ Website\n
|
||||
comment1.params=websiteName
|
||||
comment1.target=Website(java.lang.String)
|
||||
comment1.text=\n\ Constructor\ for\ objects\ of\ class\ Website\n
|
||||
comment10.params=
|
||||
comment10.target=void\ listMembersLoggedIn()
|
||||
comment10.text=\n\ Lists\ all\ members\ logged\ in\ by\ using\ a\ for\ each\ loop\ and\ accessing\ the\ member.toString()\ method.\n
|
||||
comment11.params=member
|
||||
comment11.target=void\ memberLogin(Member)
|
||||
comment11.text=\n\ Allows\ the\ website\ to\ be\ logged\ into,\ taking\ a\ Member\ object\ as\ a\ parameter.\n
|
||||
comment12.params=member
|
||||
comment12.target=void\ memberLogout(Member)
|
||||
comment12.text=\n\ Allows\ the\ current\ user\ of\ the\ website\ to\ be\ logged\ out,\ as\ long\ as\ there\ is\ a\ user\ logged\ in.\n\ The\ if\ statement\ here\ allows\ us\ to\ avoid\ a\ null\ reference\ error.\n
|
||||
comment13.params=member
|
||||
comment13.target=void\ checkout(Member)
|
||||
comment13.text=\n\ Provides\ a\ checkout\ to\ the\ member\ buying\ a\ holiday.\ This\ will\ also\ apply\ the\ hit\ discount,\ \n\ and\ amend\ the\ purchase\ to\ the\ sales\ total\ field\ variable\n
|
||||
comment14.params=
|
||||
comment14.target=boolean\ checkHitDiscount()
|
||||
comment14.text=\n\ Returns\ true\ or\ false,\ depending\ on\ the\ current\ state\ of\ hit\ count.\n\ Every\ 10th\ member,\ result\ is\ true\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getWebsiteName()
|
||||
comment2.text=\n\ Return\ website's\ name\n
|
||||
comment3.params=
|
||||
comment3.target=int\ getHits()
|
||||
comment3.text=\n\ Return\ hit\ count\ of\ website\n
|
||||
comment4.params=
|
||||
comment4.target=double\ getSalesTotal()
|
||||
comment4.text=\n\ Return\ total\ sales\ of\ holidays\ purchased\ through\ the\ website.\n
|
||||
comment5.params=
|
||||
comment5.target=java.util.ArrayList\ getLoggedInList()
|
||||
comment5.text=\n\ Return\ the\ logged\ in\ list\ ArrayList\n
|
||||
comment6.params=
|
||||
comment6.target=int\ getNumberOfUsers()
|
||||
comment6.text=\n\ Return\ the\ amount\ of\ users\ currently\ logged\ in\n
|
||||
comment7.params=websiteName
|
||||
comment7.target=void\ setWebsiteName(java.lang.String)
|
||||
comment7.text=\n\ Set\ the\ website's\ name\ to\ a\ new\ value.\n
|
||||
comment8.params=hits
|
||||
comment8.target=void\ setHits(int)
|
||||
comment8.text=\n\ Set\ the\ website's\ hit\ count\ to\ a\ new\ value.\n
|
||||
comment9.params=salesTotal
|
||||
comment9.target=void\ setSalesTotal(double)
|
||||
comment9.text=\n\ Set\ the\ total\ sales\ of\ the\ website\ to\ a\ new\ value.\n
|
||||
numComments=15
|
210
Semester 1/Programming 1/Homework 4/Website.java
Normal file
210
Semester 1/Programming 1/Homework 4/Website.java
Normal file
@@ -0,0 +1,210 @@
|
||||
|
||||
/**
|
||||
* Represents a holiday website, where members can purchase holidays.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @13/11/23
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Website
|
||||
{
|
||||
// Creates a String variable to hold the name of the website.
|
||||
private String websiteName;
|
||||
|
||||
// Creates an integer variable to hold the amount of logins (hits).
|
||||
private int hits;
|
||||
|
||||
// Creates an integer variable to hold the total sales in pounds.
|
||||
private double salesTotal;
|
||||
|
||||
// Creates an array for the logged in members.
|
||||
private ArrayList<Member> loggedInList = new ArrayList<Member>();
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class Website
|
||||
*/
|
||||
public Website()
|
||||
{
|
||||
websiteName = "Club 18";
|
||||
hits = 1257;
|
||||
salesTotal = 10592.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Website
|
||||
*/
|
||||
public Website( String websiteName )
|
||||
{
|
||||
this.websiteName = websiteName;
|
||||
hits = 0;
|
||||
salesTotal = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return website's name
|
||||
*/
|
||||
public String getWebsiteName()
|
||||
{
|
||||
return websiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return hit count of website
|
||||
*/
|
||||
public int getHits()
|
||||
{
|
||||
return hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return total sales of holidays purchased through the website.
|
||||
*/
|
||||
public double getSalesTotal()
|
||||
{
|
||||
return salesTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the logged in list ArrayList
|
||||
*/
|
||||
public ArrayList<Member> getLoggedInList()
|
||||
{
|
||||
return loggedInList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of users currently logged in
|
||||
*/
|
||||
public int getNumberOfUsers()
|
||||
{
|
||||
return loggedInList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the website's name to a new value.
|
||||
*/
|
||||
public void setWebsiteName( String websiteName )
|
||||
{
|
||||
this.websiteName = websiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the website's hit count to a new value.
|
||||
*/
|
||||
public void setHits( int hits )
|
||||
{
|
||||
this.hits = hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the total sales of the website to a new value.
|
||||
*/
|
||||
public void setSalesTotal( double salesTotal )
|
||||
{
|
||||
this.salesTotal = salesTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all members logged in by using a for each loop and accessing the member.toString() method.
|
||||
*/
|
||||
public void listMembersLoggedIn()
|
||||
{
|
||||
for ( Member memberMessage : loggedInList )
|
||||
{
|
||||
System.out.println( memberMessage.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the website to be logged into, taking a Member object as a parameter.
|
||||
*/
|
||||
public void memberLogin( Member member )
|
||||
{
|
||||
if( !member.getLoggedInStatus() )
|
||||
{
|
||||
//User status to logged in
|
||||
member.setLoggedInStatus( true );
|
||||
loggedInList.add( member );
|
||||
|
||||
//Assign to a website
|
||||
member.setWebsite( this );
|
||||
System.out.println( websiteName + " welcome member " + member.getMembershipNumber() + ", you are now logged in" );
|
||||
|
||||
//Increment hits
|
||||
hits++;
|
||||
}
|
||||
else {
|
||||
System.out.println( "Current user is still logged in, please try again later." );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the current user of the website to be logged out, as long as there is a user logged in.
|
||||
* The if statement here allows us to avoid a null reference error.
|
||||
*/
|
||||
public void memberLogout( Member member )
|
||||
{
|
||||
if( member.getLoggedInStatus() )
|
||||
{
|
||||
//User status logged out
|
||||
member.setLoggedInStatus( false );
|
||||
loggedInList.remove( member );
|
||||
//No longer registered to a website
|
||||
member.setWebsite( null );
|
||||
System.out.println( websiteName + ": goodbye member " + member.getMembershipNumber() + ", you are now logged out" );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "User not logged in" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a checkout to the member buying a holiday. This will also apply the hit discount,
|
||||
* and amend the purchase to the sales total field variable
|
||||
*/
|
||||
public void checkout( Member member )
|
||||
{
|
||||
if( member.getHoliday() != null ) {
|
||||
//Stores the integer price of holiday as a double so it can be discounted.
|
||||
//This couldve been avoided by repeating redundant code but this is cleaner.
|
||||
double holidayPrice = ( member.getHoliday().getPrice() * ( member.getNumberOfCompanions() + 1 ) );
|
||||
|
||||
if( checkHitDiscount() == true )
|
||||
{
|
||||
//Discounts price, hence why holidayPrice must be a double
|
||||
double credit = holidayPrice * 0.1;
|
||||
holidayPrice -= credit;
|
||||
|
||||
// Reimburse the user for discount, since money is taken in payForHoliday
|
||||
member.setMoney( member.getMoney() + credit );
|
||||
System.out.println( "Congratulations! You are the 10th user to book a holiday, you will recieve a 10% discount on this holiday." );
|
||||
}
|
||||
|
||||
//Add holiday price to running total
|
||||
salesTotal += holidayPrice;
|
||||
System.out.println("Your purchase totaling £" + holidayPrice + " was sucessful, user " + member.getMembershipNumber() + ", thank you for using Tops Travel.");
|
||||
member.setHoliday( null );
|
||||
memberLogout( member );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "You have not selected a holiday!" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true or false, depending on the current state of hit count.
|
||||
* Every 10th member, result is true
|
||||
*/
|
||||
private boolean checkHitDiscount()
|
||||
{
|
||||
//hits mod 10, when hits is multiple of 10, return true.
|
||||
if ( hits > 0 )
|
||||
return ( hits % 10 ) == 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
101
Semester 1/Programming 1/Homework 4/package.bluej
Normal file
101
Semester 1/Programming 1/Homework 4/package.bluej
Normal file
@@ -0,0 +1,101 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Website
|
||||
dependency1.to=Member
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Member
|
||||
dependency2.to=Holiday
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Member
|
||||
dependency3.to=Website
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Member
|
||||
dependency4.to=Friend
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Website
|
||||
dependency5.to=Friend
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Company
|
||||
dependency6.to=Website
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=Company
|
||||
dependency7.to=Member
|
||||
dependency7.type=UsesDependency
|
||||
dependency8.from=Company
|
||||
dependency8.to=Holiday
|
||||
dependency8.type=UsesDependency
|
||||
objectbench.height=95
|
||||
objectbench.width=938
|
||||
package.editor.height=639
|
||||
package.editor.width=812
|
||||
package.editor.x=16
|
||||
package.editor.y=37
|
||||
package.numDependencies=8
|
||||
package.numTargets=5
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.editor.height=689
|
||||
target1.editor.width=900
|
||||
target1.editor.x=26
|
||||
target1.editor.y=31
|
||||
target1.height=50
|
||||
target1.name=Company
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=90
|
||||
target1.x=170
|
||||
target1.y=10
|
||||
target2.editor.height=833
|
||||
target2.editor.width=960
|
||||
target2.editor.x=0
|
||||
target2.editor.y=31
|
||||
target2.height=50
|
||||
target2.name=Friend
|
||||
target2.naviview.expanded=true
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=80
|
||||
target2.x=20
|
||||
target2.y=130
|
||||
target3.editor.height=700
|
||||
target3.editor.width=900
|
||||
target3.editor.x=31
|
||||
target3.editor.y=40
|
||||
target3.height=50
|
||||
target3.name=Holiday
|
||||
target3.naviview.expanded=true
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=80
|
||||
target3.x=20
|
||||
target3.y=230
|
||||
target4.editor.height=1049
|
||||
target4.editor.width=1920
|
||||
target4.editor.x=0
|
||||
target4.editor.y=31
|
||||
target4.height=50
|
||||
target4.name=Website
|
||||
target4.naviview.expanded=true
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=90
|
||||
target4.x=170
|
||||
target4.y=80
|
||||
target5.editor.height=700
|
||||
target5.editor.width=900
|
||||
target5.editor.x=0
|
||||
target5.editor.y=37
|
||||
target5.height=50
|
||||
target5.name=Member
|
||||
target5.naviview.expanded=true
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.typeParameters=
|
||||
target5.width=90
|
||||
target5.x=170
|
||||
target5.y=180
|
Reference in New Issue
Block a user