Advertisement
fuadfatali

OOAD-HW2

Apr 30th, 2024 (edited)
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.90 KB | None | 0 0
  1. import java.util.Date;
  2. import java.util.List;
  3. import java.util.ArrayList;
  4.  
  5. // Base class for all products
  6. class Product {
  7.     protected int id;
  8.     protected String name;
  9.     protected String description;
  10.     protected float price;
  11.     protected float amount;
  12.     protected Date expiryDate;
  13.  
  14.     public Product(int id, String name, String description, float price, float amount, Date expiryDate) {
  15.         this.id = id;
  16.         this.name = name;
  17.         this.description = description;
  18.         this.price = price;
  19.         this.amount = amount;
  20.         this.expiryDate = expiryDate;
  21.     }
  22.  
  23.     public void setPrice(float newPrice) {
  24.         this.price = newPrice;
  25.     }
  26.  
  27.     public void setDescription(String newDescription) {
  28.         this.description = newDescription;
  29.     }
  30. }
  31.  
  32. class MeatProduct extends Product {
  33.     public MeatProduct(int id, String name, String description, float price, Date expiryDate) {
  34.         super(id, name, description, price, 0, expiryDate);
  35.     }
  36. }
  37.  
  38. class DairyItem extends Product {
  39.     public DairyItem(int id, String name, String description, float price, Date expiryDate) {
  40.         super(id, name, description, price, 0, expiryDate);
  41.     }
  42. }
  43.  
  44. class FreshProduct extends Product {
  45.     public FreshProduct(int id, String name, String description, float price, Date expiryDate) {
  46.         super(id, name, description, price, 0, expiryDate);
  47.     }
  48. }
  49.  
  50. class ChilledItem extends Product {
  51.     public ChilledItem(int id, String name, String description, float price, Date expiryDate) {
  52.         super(id, name, description, price, 0, expiryDate);
  53.     }
  54. }
  55.  
  56. class SmokingItem extends Product {
  57.     public SmokingItem(int id, String name, String description, float price, Date expiryDate) {
  58.         super(id, name, description, price, 0, expiryDate);
  59.     }
  60. }
  61.  
  62. class BeverageItem extends Product {
  63.     public BeverageItem(int id, String name, String description, float price, Date expiryDate) {
  64.         super(id, name, description, price, 0, expiryDate);
  65.     }
  66. }
  67.  
  68. class AlcoholicBeverage extends Product {
  69.     public AlcoholicBeverage(int id, String name, String description, float price, Date expiryDate) {
  70.         super(id, name, description, price, 0, expiryDate);
  71.     }
  72. }
  73.  
  74. class BreadProduct extends Product {
  75.     public BreadProduct(int id, String name, String description, float price, Date expiryDate) {
  76.         super(id, name, description, price, 0, expiryDate);
  77.     }
  78. }
  79.  
  80. class DessertItem extends Product {
  81.     public DessertItem(int id, String name, String description, float price, Date expiryDate) {
  82.         super(id, name, description, price, 0, expiryDate);
  83.     }
  84. }
  85.  
  86. class PersonalCareProduct extends Product {
  87.     public PersonalCareProduct(int id, String name, String description, float price, Date expiryDate) {
  88.         super(id, name, description, price, 0, expiryDate);
  89.     }
  90. }
  91.  
  92. // Order class
  93. class Order {
  94.     private int id;
  95.     private User user;
  96.     private List<Product> products;
  97.     private float totalPrice;
  98.     private String status;
  99.     private Courier courier;
  100.  
  101.     public Order(int id, User user) {
  102.         this.id = id;
  103.         this.user = user;
  104.         this.products = new ArrayList<>();
  105.         this.status = "New";
  106.     }
  107.  
  108.     public void addProduct(Product product) {
  109.         products.add(product);
  110.         totalPrice += product.price;
  111.     }
  112.  
  113.     public float getTotalPrice() {
  114.         return totalPrice;
  115.     }
  116.  
  117.     public void setStatus(String status) {
  118.         this.status = status;
  119.     }
  120. }
  121.  
  122. // User management
  123. class User {
  124.     private int id;
  125.     private String fullName;
  126.     private String address;
  127.     private List<Card> cards;
  128.     private String username;
  129.     private String password;
  130.  
  131.     public User(int id, String fullName, String address, String username, String password) {
  132.         this.id = id;
  133.         this.fullName = fullName;
  134.         this.address = address;
  135.         this.username = username;
  136.         this.password = password;
  137.         this.cards = new ArrayList<>();
  138.     }
  139.  
  140.     public void addCard(Card card) {
  141.         cards.add(card);
  142.     }
  143.  
  144.     public void changePassword(String newPassword) {
  145.         this.password = newPassword;
  146.     }
  147. }
  148.  
  149. // Payment system
  150. abstract class Payment {
  151.     public abstract void confirmPayment();
  152. }
  153.  
  154. class CardPayment extends Payment {
  155.     private String cardNumber;
  156.  
  157.     public CardPayment(String cardNumber) {
  158.         this.cardNumber = cardNumber;
  159.     }
  160.  
  161.     public boolean verifyBankCard() {
  162.         // Placeholder for card verification logic
  163.         return true;
  164.     }
  165.  
  166.     @Override
  167.     public void confirmPayment() {
  168.         if (verifyBankCard()) {
  169.             System.out.println("Payment confirmed via card.");
  170.         }
  171.     }
  172. }
  173.  
  174. class CashPayment extends Payment {
  175.     private float cashAmount;
  176.  
  177.     public CashPayment(float cashAmount) {
  178.         this.cashAmount = cashAmount;
  179.     }
  180.  
  181.     @Override
  182.     public void confirmPayment() {
  183.         System.out.println("Payment confirmed with cash.");
  184.     }
  185. }
  186.  
  187. // Admin class
  188. class Admin {
  189.     private int id;
  190.     private String fullName;
  191.  
  192.     public Admin(int id, String fullName) {
  193.         this.id = id;
  194.         this.fullName = fullName;
  195.     }
  196.  
  197.     public void addProduct(Product product) {
  198.         // Add product logic
  199.     }
  200.  
  201.     public void deleteProduct(Product product) {
  202.         // Delete product logic
  203.     }
  204.  
  205.     public void editProduct(Product product) {
  206.         // Edit product logic
  207.     }
  208.  
  209.     public void createCoupon(Coupon coupon) {
  210.         // Create coupon logic
  211.     }
  212. }
  213.  
  214. // Address and coupon management
  215. class Address {
  216.     private String name;
  217.     private String address;
  218.  
  219.     public Address(String name, String address) {
  220.         this.name = name;
  221.         this.address = address;
  222.     }
  223. }
  224.  
  225. class Coupon {
  226.     private String code;
  227.     private float discountPercentage;
  228.     private Date expiryDate;
  229.  
  230.     public Coupon(String code, float discountPercentage, Date expiryDate) {
  231.         this.code = code;
  232.         this.discountPercentage = discountPercentage;
  233.         this.expiryDate = expiryDate;
  234.     }
  235. }
  236.  
  237. // Reporting system
  238. class Report {
  239.     private Date day;
  240.     private List<Order> orders;
  241.     private float revenue;
  242.  
  243.     public Report(Date day, List<Order> orders, float revenue) {
  244.         this.day = day;
  245.         this.orders = orders;
  246.         this.revenue = revenue;
  247.     }
  248.  
  249.     public void sendToAdmin() {
  250.         // Send report to admin logic
  251.     }
  252. }
  253.  
  254. // Staff and specific roles
  255. class Staff extends User {
  256.     private float yearsOfExperience;
  257.     private boolean isOnline;
  258.  
  259.     public Staff(int id, String fullName, String address, String username, String password, float yearsOfExperience) {
  260.         super(id, fullName, address, username, password);
  261.         this.yearsOfExperience = yearsOfExperience;
  262.         this.isOnline = false;
  263.     }
  264.  
  265.     public void changeOrderStatus(Order order, String newStatus) {
  266.         order.setStatus(newStatus);
  267.     }
  268. }
  269.  
  270. class Courier extends Staff {
  271.     private boolean isDelivering;
  272.  
  273.     public Courier(int id, String fullName, String address, String username, String password, float yearsOfExperience) {
  274.         super(id, fullName, address, username, password, yearsOfExperience);
  275.         this.isDelivering = false;
  276.     }
  277.  
  278.     public void takeOrder(Order order) {
  279.         this.isDelivering = true;
  280.         // Logic to handle order delivery
  281.     }
  282.  
  283.     public void deliverOrder(Order order) {
  284.         this.isDelivering = false;
  285.         // Logic to finalize order delivery
  286.     }
  287. }
  288.  
  289. class CustomerSupporter extends Staff {
  290.     private boolean isOnSupport;
  291.  
  292.     public CustomerSupporter(int id, String fullName, String address, String username, String password, float yearsOfExperience) {
  293.         super(id, fullName, address, username, password, yearsOfExperience);
  294.         this.isOnSupport = false;
  295.     }
  296.  
  297.     public void answerUser(User user) {
  298.         // Answers will be here
  299.     }
  300. }
  301.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement