## JMART
```java=
import java.text.SimpleDateFormat;
import java.util.Date;
import goldenSample.Shipment.Duration;
/**
* Write a description of class Jmart here.
*
* @author (your name)
* @version (a version number or a date)
*/
class Jmart {
public static void main(String[] args) {
System.out.println(Shipment.Duration.KARGO.getEstimatedArrival(new Date()));
}
}
```
## Complaint
```java=
public class Complaint extends Recognizable implements FileParser
{
public final String date;
public String desc;
public Complaint(int id, String desc)
{
super(id);
this.desc = desc;
date = "Date";
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
}
```
## Coupon
```java=
public class Coupon extends Recognizable implements FileParser
{
public final String name;
public final int code;
public final double cut;
public final Type type;
public final double minimum;
private boolean used;
public enum Type
{
DISCOUNT,
REBATE
}
public Coupon(int id, String name, int code, Type type, double cut, double minimum)
{
super(id);
this.name = name;
this.code = code;
this.cut = cut;
this.type = type;
this.minimum = minimum;
this.used = false;
}
public boolean isUsed() { return used; }
public boolean canApply(PriceTag priceTag)
{
if (used || priceTag.getAdjustedPrice() < minimum)
return false;
return true;
}
public double apply(PriceTag priceTag)
{
used = true;
double adjustedPrice = priceTag.getAdjustedPrice();
switch (type)
{
case REBATE:
if (adjustedPrice <= cut) return 0.0;
return adjustedPrice - cut;
case DISCOUNT:
if (cut >= 100.0) return 0.0;
return adjustedPrice - adjustedPrice * (cut / 100);
}
return 0.0;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
}
```
## FileParser
```java=
public interface FileParser
{
boolean read(String content);
default Object write() { return null; }
static Object newInstance(String content) { return null; }
}
```
## Invoice
```java=
public abstract class Invoice extends Recognizable implements FileParser
{
public enum Status { WAITING_CONFIRMATION, CANCELLED, ON_PROGRESS, ON_DELIVERY, COMPLAINT, FINISHED, FAILED }
public enum Rating { NONE, BAD, NEUTRAL, GOOD }
public final String date; // Modul 4 ganti jadi Date
public int buyerId;
public int productId;
public int complaintId;
public Rating rating;
public Status status;
protected Invoice(int id, int buyerId, int productId)
{
super(id);
this.buyerId = buyerId;
this.productId = productId;
this.complaintId = -1;
this.date = "Date";
this.rating = Rating.NONE;
this.status = Status.WAITING_CONFIRMATION;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
public abstract double getTotalPay();
}
```
## Product
```java=
public class Product extends Recognizable implements FileParser
{
public int storeId;
public String name;
public int weight;
public boolean conditionUsed;
public PriceTag priceTag;
public ProductCategory category;
public ProductRating rating;
public MultiDuration multiDuration;
public Product(int id, int storeId, String name, int weight, boolean conditionUsed, PriceTag priceTag, ProductCategory category, MultiDuration multiDuration)
{
super(id);
this.storeId = storeId;
this.name = name;
this.weight = weight;
this.conditionUsed = conditionUsed;
this.priceTag = priceTag;
this.category = category;
this.multiDuration = multiDuration;
this.rating = new ProductRating();
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
public String toString()
{
return "Name: " + name +
"\nWeight: " + weight +
"\nconditionUsed: " + conditionUsed +
"\npriceTag: " + priceTag.getAdjustedPrice() +
"\ncategory: " + category.toString() +
"\nrating: " + rating.toString() +
"\nstoreId: "+ storeId;
}
}
```
## ProductRating
```java=
public class ProductRating implements FileParser
{
private long total;
private long count;
public ProductRating()
{
total = 0;
count = 0;
}
public void insert(int rating)
{
total += rating;
++count;
}
public double getAverage()
{
if (count == 0) return 0.0;
return (double) total / count;
}
public long getCount()
{
return count;
}
public long getTotal()
{
return total;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
}
```
## ProductCategory
```java=
public enum ProductCategory
{
BOOK,
KITCHEN,
ELECTRONIC,
FASHION,
GAMING,
GADGET,
MOTHERCARE,
COSMETICS,
HEALTHCARE,
FURNITURE,
JEWELRY,
TOYS,
FNB,
STATIONERY,
SPORTS,
AUTOMOTIVE,
PETCARE,
ART_CRAFT,
CARPENTRY,
MISCELLANEOUS,
PROPERTY,
TRAVEL,
WEDDING
}
```
## Recognizeable
```java=
public abstract class Recognizable
{
public final int id;
protected Recognizable(int id) { this.id = id; }
public boolean equals(Object other)
{
return other instanceof Recognizable && ((Recognizable) other).id == id;
}
public boolean equals(Recognizable other)
{
return other.id == id;
}
}
```
## PriceTag
```java=
class PriceTag
{
public static final double COMMISSION_MULTIPLIER = 0.05;
public static final double BOTTOM_PRICE = 20000.0;
public static final double BOTTOM_FEE = 1000.0;
public double discount;
public double price;
public PriceTag(double price)
{
this.price = price;
this.discount = 0.0;
}
public PriceTag(double price, double discount)
{
this.price = price;
this.discount = discount;
}
public double getAdjustedPrice()
{
return getDiscountedPrice() + getAdminFee();
}
public double getAdminFee()
{
double discountedPrice = getDiscountedPrice();
if (discountedPrice < BOTTOM_PRICE)
return BOTTOM_FEE;
return COMMISSION_MULTIPLIER * discountedPrice;
}
private double getDiscountedPrice()
{
if (discount >= 100.0) return 0.0;
double cut = price * discount / 100.0;
return price - cut;
}
}
```
## Store
```java=
public class Store extends Recognizable implements FileParser
{
public static final String REGEX_PHONE = "^\\d{9,12}$";
public static final String REGEX_NAME = "^[A-Z](?!.*(\\s)\\1).{4,20}$";
public String name;
public String address;
public String phoneNumber;
public Store(int accountId, String name, String address, String phoneNumber) {
super(accountId);
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
public Store(Account account, String name, String address, String phoneNumber) {
super(account.id);
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
public String toString() {
return "name: " + name + "\naddress: " + address + "\nphoneNumber: " + phoneNumber;
}
public boolean validate() {
Pattern pattern = Pattern.compile(REGEX_NAME);
Matcher matcher = pattern.matcher(name);
Pattern pattern2 = Pattern.compile(REGEX_PHONE);
Matcher matcher2 = pattern2.matcher(phoneNumber);
return matcher.find() && matcher2.find();
}
}
```
## Shipment
```java=
public class Shipment implements FileParser
{
public static class Duration
{
public static final Duration INSTANT = new Duration((byte) (1 << 0));
public static final Duration SAME_DAY = new Duration((byte) (1 << 1));
public static final Duration NEXT_DAY = new Duration((byte) (1 << 2));
public static final Duration REGULER = new Duration((byte) (1 << 3));
public static final Duration KARGO = new Duration((byte) (1 << 4));
public final byte bit;
private Duration(byte bit) { this.bit = bit; }
}
public static class MultiDuration
{
public final byte bit;
public MultiDuration(Duration... args)
{
byte flags = 0;
for (byte i = 0; i < args.length; ++i)
flags |= args[i].bit;
bit = flags;
}
public boolean isDuration(Duration reference) { return (bit & reference.bit) != 0; }
}
public String address;
public int shipmentCost;
public Duration duration;
public String receipt;
public Shipment(String address, int shipmentCost, Duration duration, String receipt)
{
this.address = address;
this.shipmentCost = shipmentCost;
this.duration = duration;
this.receipt = receipt;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
}
```
## Store
```java=
public class Store extends Recognizable implements FileParser
{
public String name;
public String address;
public String phoneNumber;
public Store(int accountId, String name, String address, String phoneNumber)
{
super(accountId);
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
public Store(Account account, String name, String address, String phoneNumber)
{
super(account.id);
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
@Override
public boolean read(String content) {
// TODO Auto-generated method stub
return false;
}
public String toString()
{
return "name: "+ name +
"\naddress: " + address +
"\nphoneNumber: " + phoneNumber;
}
}
```
## Transactor
```java=
public interface Transactor
{
public abstract boolean validate();
public abstract Invoice perform();
}
```