This commit is contained in:
nheron 2014-02-14 00:00:49 +01:00
commit 4dbaba5e48
80 changed files with 4193 additions and 0 deletions

View file

@ -0,0 +1,59 @@
package demo;
public class Card {
private String number;
private String name;
private Customer customer;
public void setNumber(String number) {
this.number = number;
}
public void setName(String name) {
this.name = name;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public void setCartType(String cartType) {
this.cartType = cartType;
}
private String cartType;
public Card(String number, String cartName, String cartType,
String customerID, String name, String surname, String maritalName,
Gender gender) {
this.number = number;
this.name = cartName;
this.cartType = cartType;
this.customer = new Customer(customerID, name, surname, maritalName,
gender, null);
}
public String getName() {
return name;
}
public String getCartType() {
return cartType;
}
public String getNumber() {
return number;
}
public Customer getCustomer() {
return customer;
}
public Card() {
super();
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,5 @@
package demo;
public enum Currency {
Euro, Dollar, Yen
}

View file

@ -0,0 +1,77 @@
package demo;
import java.util.Date;
public class Customer {
private String customerID;
private String surName;
private String name;
private String maritalName;
private Gender gender;
private Date birthDate;
public String getCustomerID() {
return customerID;
}
public void setCustomerID(String customerID) {
this.customerID = customerID;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMaritalName() {
return maritalName;
}
public void setMaritalName(String maritalName) {
this.maritalName = maritalName;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Customer(String customerID, String surName, String name,
String maritalName, Gender gender, Date birthDate) {
super();
this.customerID = customerID;
this.surName = surName;
this.name = name;
this.maritalName = maritalName;
this.gender = gender;
this.birthDate = birthDate;
}
public Customer() {
super();
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,5 @@
package demo;
public enum Gender {
Mr,Mrs,Miss
}

View file

@ -0,0 +1,35 @@
package demo;
public class Price {
private Float price;
private Currency currency;
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public Currency getCurrency() {
return currency;
}
public void setCurrency(Currency currency) {
this.currency = currency;
}
public Price(Float price, Currency currency) {
super();
this.price = price;
this.currency = currency;
}
public Price() {
super();
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,84 @@
package demo;
import org.joda.time.DateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Product {
private String Id;
private String Name;
private Map<Date, Map<Currency, Price>> prices = new HashMap<Date, Map<Currency, Price>>();
private Provider provider;
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public Provider getProvider() {
return provider;
}
public void setProvider(Provider provider) {
this.provider = provider;
}
public Product(String id, String name, Provider provider) {
super();
Id = id;
Name = name;
this.provider = provider;
}
public void setPrice(Date startTime, Float price, Currency currency) {
if (prices.containsKey(startTime) == false) {
Price newprice = new Price(price, currency);
Map<Currency, Price> priceMap = new HashMap<Currency, Price>();
priceMap.put(currency, newprice);
prices.put(startTime, priceMap);
} else {
Map<Currency, Price> priceMap = prices.get(startTime);
if (priceMap.containsKey(currency) == false) {
Price aNewPrice = new Price(price, currency);
priceMap.put(currency, aNewPrice);
} else {
Price aExistingPrice = priceMap.get(currency);
aExistingPrice.setPrice(price);
}
}
}
public void delPrice(DateTime startTime) {
if (prices.containsKey(startTime) == true) {
prices.remove(startTime);
}
}
public Product() {
super();
// TODO Auto-generated constructor stub
}
public Map<Date, Map<Currency, Price>> getPrices() {
return prices;
}
public void setPrices(Map<Date, Map<Currency, Price>> prices) {
this.prices = prices;
}
}

View file

@ -0,0 +1,34 @@
package demo;
public class Provider {
private String name;
private String country;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Provider(String name, String country) {
super();
this.name = name;
this.country = country;
}
public Provider() {
super();
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,85 @@
package demo;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Ticket {
private String Id;
private Date date;
private Float amount;
private Card loyaltyCard;
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Card getLoyaltyCard() {
return loyaltyCard;
}
public void setLoyaltyCard(Card loyaltyCard) {
this.loyaltyCard = loyaltyCard;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
private List<TicketLine> ticketLines = new ArrayList<TicketLine>();
public long AddLine(Product product, Float price, long quantity) {
TicketLine newLine = new TicketLine(this, product, quantity, price);
ticketLines.add(newLine);
this.amount = this.amount + newLine.getLineTotal();
return newLine.getLineNumber();
}
public void delLine(int lineNumber) {
if (lineNumber <= this.ticketLines.size()) {
TicketLine lineToDel = this.ticketLines.get(lineNumber);
lineToDel.setValid(false);
this.amount = this.amount-lineToDel.getLineTotal();
}
}
public Ticket() {
super();
// TODO Auto-generated constructor stub
}
public Float getAmount() {
return amount;
}
public void setAmount(Float amount) {
this.amount = amount;
}
public List<TicketLine> getTicketLines() {
return ticketLines;
}
public void setTicketLines(List<TicketLine> ticketLines) {
this.ticketLines = ticketLines;
}
}

View file

@ -0,0 +1,97 @@
package demo;
public class TicketLine {
private static int numberLines = 0;
private Ticket ticket;
private int lineNumber;
private Product product;
private long quantity;
private Float price = null;
private Float lineTotal;;
private boolean valid;
public int getLineNumber() {
return lineNumber;
}
public Float getLineTotal() {
return lineTotal;
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public Ticket getTicket() {
return ticket;
}
public void setTicket(Ticket ticket) {
this.ticket = ticket;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public long getQuantity() {
return quantity;
}
public TicketLine(Ticket ticket, Product product, long quantity, Float price) {
super();
numberLines = numberLines + 1;
this.lineNumber = numberLines;
this.ticket = ticket;
this.product = product;
this.quantity = quantity;
this.price = price;
this.lineTotal = price * quantity;
}
public void setQuantity(long quantity) {
this.quantity = quantity;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public TicketLine() {
super();
// TODO Auto-generated constructor stub
}
public static int getNumberLines() {
return numberLines;
}
public static void setNumberLines(int numberLines) {
TicketLine.numberLines = numberLines;
}
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
public void setLineTotal(Float lineTotal) {
this.lineTotal = lineTotal;
}
public void AddProductToTicketLine(Product p){
this.product = p;
}
}

View file

@ -0,0 +1,40 @@
package service;
import java.util.List;
import demo.Product;
import demo.Ticket;
import demo.TicketLine;
public class TickerService {
public void CalculateAmountTicket(Ticket ticket) {
if (ticket != null) {
Float total = new Float(0.0);
for (TicketLine line : ticket.getTicketLines()) {
total = total + line.getQuantity() * line.getPrice();
}
ticket.setAmount(total);
}
}
public void CalculateTicketLineAmount(TicketLine line) {
if (line != null) {
Float total = new Float(0.0);
total = line.getQuantity() * line.getPrice();
line.setLineTotal(total);
}
}
public void CalculateTicketLinesAmount(List<TicketLine> lines) {
if (lines != null) {
Float total = new Float(0.0);
for (TicketLine aLine : lines) {
total = aLine.getQuantity() * aLine.getPrice();
aLine.setLineTotal(total);
}
}
}
public void addProductTicket(Product p, TicketLine t){
t.setProduct(p);
}
}

View file

@ -0,0 +1,20 @@
package util;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateHelper {
public static String sFormat = "yyyy-MM-dd";
public static Date getDate(String sDate) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}
public static Date getDate(String sDate, String anotherFormat)
throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat(anotherFormat);
return sdf.parse(sDate);
}
}