first commit
This commit is contained in:
171
Semester 1/Programming 1/Eclipse/Homework 3/src/Website.java
Normal file
171
Semester 1/Programming 1/Eclipse/Homework 3/src/Website.java
Normal file
@@ -0,0 +1,171 @@
|
||||
|
||||
/**
|
||||
* Represents a holiday website, where members can purchase holidays.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @8/11/23
|
||||
*/
|
||||
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 int salesTotal;
|
||||
|
||||
// Creates a pointer to a member object.
|
||||
private Member member;
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class Website
|
||||
*/
|
||||
public Website()
|
||||
{
|
||||
websiteName = "Club 18";
|
||||
hits = 1257;
|
||||
salesTotal = 10592;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Website
|
||||
*/
|
||||
public Website( String websiteName )
|
||||
{
|
||||
this.websiteName = websiteName;
|
||||
this.hits = 0;
|
||||
this.salesTotal = 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 int getSalesTotal()
|
||||
{
|
||||
return salesTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current member logged in.
|
||||
*/
|
||||
public Member getMember()
|
||||
{
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( int salesTotal )
|
||||
{
|
||||
this.salesTotal = salesTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the website to be logged into, taking a Member object as a parameter.
|
||||
* If the current member value is not null, do not allow another login. As per brief spec.
|
||||
*/
|
||||
public void memberLogin( Member member )
|
||||
{
|
||||
System.out.println( this.member );
|
||||
if( this.member != null )
|
||||
{
|
||||
System.out.println( "Current user is still logged in, please try again later." );
|
||||
}
|
||||
else {
|
||||
member.setLoggedInStatus( true );
|
||||
member.setWebsite( this );
|
||||
this.member = member;
|
||||
System.out.println( websiteName + " welcome member " + member.getMembershipNumber() + ", you are now logged in" );
|
||||
hits ++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if( member != null )
|
||||
{
|
||||
member.setLoggedInStatus( false );
|
||||
member.setWebsite( null );
|
||||
System.out.println( websiteName + " goodbye member " + member.getMembershipNumber() + ", you are now logged out" );
|
||||
member = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "No user 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( checkHitDiscount() == true )
|
||||
{
|
||||
System.out.println( "Congratulations! You are the 10th user to book a holiday, you will recieve a 10% discount on this holiday." );
|
||||
salesTotal += ( member.getHoliday().getPrice() * 0.9 );
|
||||
}
|
||||
else
|
||||
{
|
||||
salesTotal += ( member.getHoliday().getPrice() );
|
||||
}
|
||||
|
||||
System.out.println("Your purchase was sucessful, " + member.getMembershipNumber() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true or false, depending on the current state of hit count.
|
||||
* Every 10th member, result is true
|
||||
*/
|
||||
public boolean checkHitDiscount()
|
||||
{
|
||||
if( hits == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( hits % 10 ) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user