-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fe407c
commit a13e30d
Showing
56 changed files
with
9,269 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package Model; | ||
|
||
import javafx.scene.Scene; | ||
import javafx.scene.control.ScrollPane; | ||
import org.menu.UniqueAuction; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Random; | ||
|
||
public class Auction { | ||
private String id; | ||
private Product product; | ||
private HashMap<Buyer,Integer> proposals=new HashMap<>(); | ||
private LocalDateTime startDate; | ||
private LocalDateTime stopDate; | ||
private static ArrayList<Auction> allAuctions=new ArrayList<>(); | ||
private UniqueAuction auctionMenu; | ||
|
||
public Auction(Product product,LocalDateTime stopDate) throws IOException, ClassNotFoundException { | ||
Random random=new Random(); | ||
while (getAuctionById(this.id=Integer.toString(random.nextInt(899999)+100000))!=null); | ||
this.product=product; | ||
this.startDate=LocalDateTime.now(); | ||
this.stopDate=stopDate; | ||
this.auctionMenu=new UniqueAuction(new ScrollPane(),this,null); | ||
allAuctions.add(this); | ||
|
||
startCountDown(); | ||
} | ||
|
||
public Product getProduct() { | ||
return product; | ||
} | ||
|
||
public LocalDateTime getStopDate() { | ||
return stopDate; | ||
} | ||
|
||
public String getFormattedStopDate(){ | ||
return stopDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); | ||
} | ||
|
||
public LocalDateTime getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public String getFormattedStartDate(){ | ||
return startDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); | ||
} | ||
|
||
public static ArrayList<Auction> getAllAuctions() { | ||
return allAuctions; | ||
} | ||
|
||
public int getHighestProposal(){ | ||
int highest=proposals.get(0); | ||
for (int proposal:proposals.values()){ | ||
if (proposal>highest){ | ||
highest=proposal; | ||
} | ||
} | ||
return highest; | ||
} | ||
|
||
public HashMap<Buyer, Integer> getProposals() { | ||
return proposals; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public static Auction getAuctionById(String id){ | ||
for (Auction auction:allAuctions){ | ||
if (id.equals(auction.id)){ | ||
return auction; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void startCountDown(){ | ||
Auction auction=this; | ||
new Thread(){ | ||
|
||
@Override | ||
public void run() { | ||
while (true){ | ||
if (LocalDateTime.now().isAfter(auction.stopDate)){ | ||
allAuctions.remove(auction); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
}.start(); | ||
} | ||
|
||
public UniqueAuction getAuctionMenu(Scene previousScene) { | ||
this.auctionMenu.setPreviousPage(previousScene); | ||
return auctionMenu; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package Model; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Random; | ||
|
||
enum postStatusBuyLog {deliverToTheCustomer, deliverToThePost, preparingTheOrder;} | ||
|
||
public class BuyLog { | ||
|
||
|
||
private float purchasedMoney; | ||
private float omittedPrice; | ||
private int discountPercent; | ||
private postStatusBuyLog postStatus; | ||
private static ArrayList<BuyLog> allSales = new ArrayList<>(); | ||
private Buyer Buyer; | ||
private ArrayList<CartItem> listOfProducts = new ArrayList<>(); | ||
private String address, phone, receiver; | ||
private String logId; | ||
private LocalDateTime date; | ||
|
||
public BuyLog(Buyer buyer, ArrayList<CartItem> cartItems, float purchasedMoney, float omittedPrice, int discountPercent, | ||
String address, String phone, String receiver) { | ||
Random random = new Random(); | ||
while (getBuyLogById(this.logId = Integer.toString(random.nextInt(999999) + 1)) != null) ; | ||
this.Buyer = buyer; | ||
this.address = address; | ||
this.phone = phone; | ||
this.receiver = receiver; | ||
this.purchasedMoney = purchasedMoney; | ||
this.omittedPrice = omittedPrice; | ||
this.discountPercent = discountPercent; | ||
this.listOfProducts.addAll(cartItems); | ||
this.date = LocalDateTime.now(); | ||
buyer.setCredit((int) (buyer.getCredit() - purchasedMoney)); | ||
this.postStatus=postStatusBuyLog.preparingTheOrder; | ||
allSales.add(this); | ||
buyer.getOrderHistory().add(this); | ||
} | ||
|
||
public static BuyLog getBuyLogById(String id) { | ||
for (BuyLog log : allSales) { | ||
if (log.logId.equalsIgnoreCase(id)) { | ||
return log; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public ArrayList<CartItem> getListOfProducts() { | ||
return listOfProducts; | ||
} | ||
|
||
public String getLogId() { | ||
return logId; | ||
} | ||
|
||
public String getDate() { | ||
return date.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); | ||
} | ||
|
||
public float getPurchasedMoney() { | ||
return purchasedMoney; | ||
} | ||
|
||
public float getOmittedPrice() { | ||
return omittedPrice; | ||
} | ||
|
||
public static ArrayList<BuyLog> getAllSales() { | ||
return allSales; | ||
} | ||
|
||
public String getPostStatus() { | ||
if (postStatus==postStatusBuyLog.preparingTheOrder){ | ||
return "preparing the order"; | ||
}else if (postStatus==postStatusBuyLog.deliverToThePost){ | ||
return "delivered to post station"; | ||
}else { | ||
return "arrived to destination"; | ||
} | ||
} | ||
|
||
public void changeState(String newState){ | ||
if (newState.equals("preparing the order")){ | ||
this.postStatus=postStatusBuyLog.preparingTheOrder; | ||
}else if (newState.equals("delivered to post station")){ | ||
this.postStatus=postStatusBuyLog.deliverToThePost; | ||
}else if (newState.equals("arrived to destination")){ | ||
this.postStatus=postStatusBuyLog.deliverToTheCustomer; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package Model; | ||
|
||
import javafx.scene.image.Image; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
|
||
public class Buyer extends User { | ||
private Cart cart; | ||
private ArrayList<BuyLog> orderHistory = new ArrayList<BuyLog>(); | ||
private static final LinkedList<Buyer> allBuyers = new LinkedList<>(); | ||
|
||
public Buyer(String userName, String firstName, String lastName, String email, String phoneNumber, String password, int credit, String profile) { | ||
super(userName, firstName, lastName, email, phoneNumber, password,profile); | ||
this.credit = new Wallet(credit,this); | ||
this.cart=new Cart(this); | ||
allBuyers.add(this); | ||
} | ||
|
||
public Cart getCart() { | ||
return cart; | ||
} | ||
|
||
public void setCart(Cart cart) { | ||
this.cart = cart; | ||
} | ||
|
||
public void addProductToCart(Product product) { | ||
for (CartItem cartItem:cart.getCartItems()){ | ||
if (cartItem.getItem().equals(product)){ | ||
cartItem.increaseItem(); | ||
return; | ||
} | ||
} | ||
cart.getCartItems().add(new CartItem(product)); | ||
} | ||
|
||
|
||
public ArrayList<BuyLog> getOrderHistory() { | ||
return orderHistory; | ||
} | ||
|
||
public static LinkedList<Buyer> getAllBuyers() { | ||
return allBuyers; | ||
} | ||
|
||
@Override | ||
public void changeInfo(String field, String newValue) { | ||
if (field.equalsIgnoreCase("first name")) { | ||
setFirstName(newValue); | ||
} else if (field.equalsIgnoreCase("last name")) { | ||
setLastName(newValue); | ||
} else if (field.equalsIgnoreCase("email")) { | ||
if (newValue.matches("[a-zA-Z0-9_\\-\\.]+@(gmail|@yahoo)\\.com")) setEmail(newValue); | ||
else { | ||
System.out.println("invalid email format."); | ||
return; | ||
} | ||
} else if (field.equalsIgnoreCase("phone number")) { | ||
setPhoneNumber(newValue); | ||
} else if (field.equals("credit")) { | ||
try { | ||
setCredit(Integer.parseInt(newValue)); | ||
} catch (NumberFormatException e) { | ||
System.out.println("invalid number format"); | ||
return; | ||
} | ||
} else { | ||
System.out.println("invalid field"); | ||
return; | ||
} | ||
System.out.println(field + " changed successfully!"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "role: Buyer" + | ||
"userName: " + username + '\n' + | ||
"firstName: " + firstName + '\n' + | ||
"lastName: " + lastName + '\n' + | ||
"credit" + credit + '\n' + | ||
"email: " + email + '\n' + | ||
"phoneNumber: " + phoneNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package Model; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Cart { | ||
private ArrayList<CartItem> cartItems = new ArrayList<>(); | ||
|
||
public Cart(Buyer buyer) { | ||
buyer.setCart(this); | ||
} | ||
|
||
public ArrayList<CartItem> getCartItems() { | ||
return cartItems; | ||
} | ||
|
||
public int calculatePrice() { | ||
Off.updateOffs(); | ||
int sum = 0; | ||
if (!cartItems.isEmpty()) { | ||
for (CartItem item : cartItems) { | ||
Product product = item.getItem(); | ||
if (product.getAssignedOff() == null) { | ||
sum += product.getPrice() * item.getQuantity(); | ||
} else { | ||
sum += product.getPriceAfterOff() * item.getQuantity(); | ||
} | ||
} | ||
return sum; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package Model; | ||
|
||
public class CartItem { | ||
private Product item; | ||
private int quantity; | ||
|
||
public CartItem(Product item) { | ||
this.item = item; | ||
this.quantity = 1; | ||
} | ||
|
||
public void increaseItem() { | ||
this.quantity += 1; | ||
} | ||
|
||
public void decreaseItem() { | ||
if (this.quantity > 1) { | ||
this.quantity -= 1; | ||
} | ||
} | ||
|
||
public Product getItem() { | ||
return item; | ||
} | ||
|
||
public int getQuantity() { | ||
return quantity; | ||
} | ||
|
||
public float getPricePerEach() { | ||
return item.getPrice(); | ||
} | ||
|
||
public float getTotalPrice() { | ||
return item.getPrice() * quantity; | ||
} | ||
} |
Oops, something went wrong.