first commit
This commit is contained in:
10
Semester 1/Programming 1/Eclipse/Homework 3/.classpath
Normal file
10
Semester 1/Programming 1/Eclipse/Homework 3/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
Semester 1/Programming 1/Eclipse/Homework 3/.project
Normal file
17
Semester 1/Programming 1/Eclipse/Homework 3/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Homework 3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@@ -0,0 +1,12 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Holiday.class
Normal file
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Holiday.class
Normal file
Binary file not shown.
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Member.class
Normal file
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Member.class
Normal file
Binary file not shown.
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Website.class
Normal file
BIN
Semester 1/Programming 1/Eclipse/Homework 3/bin/Website.class
Normal file
Binary file not shown.
87
Semester 1/Programming 1/Eclipse/Homework 3/src/Holiday.java
Normal file
87
Semester 1/Programming 1/Eclipse/Homework 3/src/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;
|
||||
}
|
||||
}
|
148
Semester 1/Programming 1/Eclipse/Homework 3/src/Member.java
Normal file
148
Semester 1/Programming 1/Eclipse/Homework 3/src/Member.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Represents a user of a holiday website.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @8/11/32
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Default Constructor for objects of Class Member.
|
||||
*/
|
||||
public Member()
|
||||
{
|
||||
email = "john.doe@topstravel.co.uk";
|
||||
membershipNumber = 1;
|
||||
loggedInStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Member
|
||||
*/
|
||||
public Member( String email, int membershipNumber )
|
||||
{
|
||||
// initialise instance variables
|
||||
this.email = email;
|
||||
this.membershipNumber = membershipNumber;
|
||||
loggedInStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows member to select a holiday object, provided they are logged into a website.
|
||||
*/
|
||||
public void selectHoliday( Holiday holiday )
|
||||
{
|
||||
if( loggedInStatus == true )
|
||||
{
|
||||
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 {
|
||||
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 == true )
|
||||
{
|
||||
website.checkout( this );
|
||||
}
|
||||
else {
|
||||
System.out.println( "You are not logged 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