fork download
  1.  
  2. คุณส่ง
  3. public class UseCarPrice {
  4. public static void main(String[] args) {
  5. CarPrice car = new CarPrice();
  6.  
  7. double sedanPrice = car.calSedan(550000.00);
  8. System.out.println("Total price of sedan: " + sedanPrice);
  9.  
  10. double pickupPrice = car.calPickup(380000.00);
  11. System.out.println("Total price of pick up: " + pickupPrice);
  12. }
  13. }
  14.  
  15. class CarPrice {
  16. public double calSedan(double price) {
  17. double netPrice = price + (price * 0.05);
  18. return netPrice;
  19. }
  20.  
  21. public double calPickup(double price) {
  22. double netPrice = price + (price * 0.03);
  23. return netPrice;
  24. }
  25. }
Success #stdin #stdout 0.03s 25748KB
stdin
Standard input is empty
stdout
คุณส่ง
public class UseCarPrice {
    public static void main(String[] args) {
        CarPrice car = new CarPrice(); 

        double sedanPrice = car.calSedan(550000.00);
        System.out.println("Total price of sedan: " + sedanPrice);

        double pickupPrice = car.calPickup(380000.00);
        System.out.println("Total price of pick up: " + pickupPrice);
    }
}

class CarPrice {
    public double calSedan(double price) {
        double netPrice = price + (price * 0.05); 
        return netPrice;
    }

    public double calPickup(double price) {
        double netPrice = price + (price * 0.03); 
        return netPrice;
    }
}