Untitled
unknown
plain_text
4 years ago
1.9 kB
6
Indexable
package com.company;
import java.util.ArrayList;
import java.util.Scanner;
class Order {
private String ID;
private int unit_buy_price;
private int amount;
private double tax_percentage;
private double transport_fee;
public Order(String ID, int unit_price, int amount) {
this.ID = ID;
this.unit_buy_price = unit_price;
this.amount = amount;
setTax_and_TransportFee();
check_voucher();
}
private void setTax_and_TransportFee() {
char code = ID.charAt(0);
switch (code) {
case 'T':
tax_percentage = 29;
transport_fee = 4;
break;
case 'C':
tax_percentage = 10;
transport_fee = 3;
break;
case 'D':
tax_percentage = 8;
transport_fee = 2.5;
break;
case 'M':
tax_percentage = 2;
transport_fee = 0.5;
}
}
private void check_voucher() {
if (ID.charAt(3) == 'C')
tax_percentage *= 0.95;
}
private double unit_sell_price() {
return (unit_buy_price + (unit_buy_price * tax_percentage /100.0)
+ (unit_buy_price * transport_fee / 100.0)) * 1.2;
}
public String toString() {
return ID + " " + String.format("%.2f", unit_sell_price());
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int No_order = Integer.parseInt(sc.nextLine());
ArrayList<Order> orders = new ArrayList<>();
for (int i = 0; i < No_order; i++) {
orders.add(new Order(sc.next(), sc.nextInt(), sc.nextInt()));
}
for (Order order : orders) {
System.out.println(order);
}
}
}
Editor is loading...