commit 7e5e390b8f2ac4a647e1bff22949d708421709d1 Author: kammerer Date: Fri Oct 15 11:29:52 2021 +0200 Initial commit of sources diff --git a/VideoStore/src/Application.java b/VideoStore/src/Application.java new file mode 100644 index 0000000..e9564cd --- /dev/null +++ b/VideoStore/src/Application.java @@ -0,0 +1,49 @@ +import java.util.ArrayList; + +public class Application { + + public static void main( String[] args ) { + Application app = new Application(); + app.init(); + app.run(); + app.done(); + } + + public void init() { + System.out.println( "initializing application" ); + + movies.add( new Movie("Regular_Movie_1 ", Movie.REGULAR ) ); + movies.add( new Movie("Regular_Movie_2 ", Movie.REGULAR ) ); + movies.add( new Movie("Children_Movie_1 ", Movie.CHILDRENS ) ); + movies.add( new Movie("Children_Movie_2 ", Movie.CHILDRENS ) ); + movies.add( new Movie("NewRelease_Movie_1", Movie.NEW_RELEASE ) ); + movies.add( new Movie("NewRelease_Movie_2", Movie.NEW_RELEASE ) ); + + + customers.add( new Customer( "Customer_A" ) ); + customers.add( new Customer( "Customer_B" ) ); + customers.add( new Customer( "Customer_C" ) ); + } + + public void run() { + System.out.println( "application is running" ); + + Customer customer_1 = customers.get( 0 ); + + customer_1.addRental( new Rental( movies.get( 0 ), 2 ) ); + customer_1.addRental( new Rental( movies.get( 1 ), 3 ) ); + customer_1.addRental( new Rental( movies.get( 2 ), 3 ) ); + customer_1.addRental( new Rental( movies.get( 3 ), 4 ) ); + customer_1.addRental( new Rental( movies.get( 4 ), 3 ) ); + customer_1.addRental( new Rental( movies.get( 5 ), 4 ) ); + String statement = customer_1.statement(); + System.out.println( statement ); + } + + public void done() { + System.out.println( "application finished" ); + } + + private final ArrayList movies = new ArrayList<>(); + private final ArrayList customers = new ArrayList<>(); +} \ No newline at end of file diff --git a/VideoStore/src/Customer.java b/VideoStore/src/Customer.java new file mode 100644 index 0000000..8fbbd5c --- /dev/null +++ b/VideoStore/src/Customer.java @@ -0,0 +1,62 @@ +import java.util.ArrayList; + +public class Customer { + + private final String name; + private final ArrayList rentals = new ArrayList<>(); + + public Customer( String name ) { + this.name = name; + } + + public void addRental( Rental arg ) { + rentals.add( arg ); + } + + public String getName() { + return name; + } + + public String statement() { + double totalAmount = 0; + int frequentRenterPoints = 0; + + String result = "Rental Record for " + getName() + "\n"; + for( Rental curRental : rentals ) { + double thisAmount = 0; + + // determine amounts for each line + switch( curRental.getMovie().getPriceCode() ) { + case Movie.REGULAR: + thisAmount += 2; + if( curRental.getDaysRented() > 2 ) + thisAmount += ( curRental.getDaysRented() - 2 ) * 1.5; + break; + case Movie.NEW_RELEASE: + thisAmount += curRental.getDaysRented() * 3; + break; + case Movie.CHILDRENS: + thisAmount += 1.5; + if( curRental.getDaysRented() > 3 ) + thisAmount += ( curRental.getDaysRented() - 3 ) * 1.5; + break; + + } + totalAmount += thisAmount; + + // add frequent renter points + frequentRenterPoints++; + // add bonus for a two day new release rental + if( ( curRental.getMovie().getPriceCode() == Movie.NEW_RELEASE ) && curRental.getDaysRented() > 1 ) + frequentRenterPoints++; + + // show figures for this rental + result += "\t" + curRental.getMovie().getTitle() + "\t days rented: " + curRental.getDaysRented() + " = " + String.valueOf( thisAmount ) + "\n"; + + } + // add footer lines + result += "Amount owed is " + String.valueOf( totalAmount ) + "\n"; + result += "You earned " + String.valueOf( frequentRenterPoints ) + " frequent renter points"; + return result; + } +} \ No newline at end of file diff --git a/VideoStore/src/Movie.java b/VideoStore/src/Movie.java new file mode 100644 index 0000000..93dc367 --- /dev/null +++ b/VideoStore/src/Movie.java @@ -0,0 +1,26 @@ +public class Movie { + + public static final int CHILDRENS = 2; + public static final int REGULAR = 0; + public static final int NEW_RELEASE = 1; + + private final String title; + private int priceCode; + + public Movie( String title, int priceCode ) { + this.title = title; + this.priceCode = priceCode; + } + + public String getTitle() { + return title; + } + + public int getPriceCode() { + return priceCode; + } + + public void setPriceCode( int priceCode ) { + this.priceCode = priceCode; + } +} \ No newline at end of file diff --git a/VideoStore/src/Rental.java b/VideoStore/src/Rental.java new file mode 100644 index 0000000..088c4c5 --- /dev/null +++ b/VideoStore/src/Rental.java @@ -0,0 +1,18 @@ +public class Rental { + + private final Movie movie; + private final int daysRented; + + public Rental( Movie movie, int daysRented ) { + this.movie = movie; + this.daysRented = daysRented; + } + + public Movie getMovie() { + return movie; + } + + public int getDaysRented() { + return daysRented; + } +} \ No newline at end of file