Jump to content

'atiq

Learning
  • Content Count

    7
  • Joined

  • Last visited

Posts posted by 'atiq


  1. [CODE]
    package Saja2;
    import java.io.*;
    import java.text.*;
    import java.text.DecimalFormat;
    public class WK5IA {
    public static void main(String[] args) throws IOException {
    // declare variables
    int loanAmt = 200000; // principal loan amount
    int[] loanTerm = { 84, 180, 360 }; // loan term for 7 years, 15 years,
    // and 30 years
    int loanYears; // indicates the loan term in years
    double[] intRate = { 5.35, 5.50, 5.75 }; // interest rates for 7 years,
    // 15 years, and 30 years
    double newIntRate; // displays interest rate calculation
    double monthlyPay = 0; // displays monthly payment calculation
    DecimalFormat money = new DecimalFormat("$#,###.00"); // displays
    // mortgage in
    // decimal
    // format
    DecimalFormat money2 = new DecimalFormat("0.00%"); // displays interest
    // rate in decimal
    // format
    InputStreamReader reader = new InputStreamReader(System.in);
    BufferedReader object = new BufferedReader(reader);
    double loan = 200000.00; // Array
    int[] length = new int[3];
    length[0] = 7;
    length[1] = 15;
    length[2] = 30;
    double[] interest = new double[3];
    interest[0] = .0535;
    interest[1] = .0550;
    interest[2] = .0575;
    int x = 0;
    do // Do Statement
    {
    double payment = (loan * (interest[x] / 12))
    / (1 - (Math.pow(1 / (1 + (interest[x] / 12)),
    (length[x] * 12)))); // Display Math
    System.out.println("\n\nYour Mortgage Payment " + payment
    + "\n\nfor the " + length[x] + " Year Contract "); // Display
    // Text
    // to
    // explane
    // values
    x++;
    // displays messages to indicate purpose of program and conditions
    // in the console window
    System.out.println();
    System.out.println("Mortgage Payment Calculator");
    System.out.println();
    System.out
    .println("Calculate three separate mortgage payments for a $"
    + loanAmt);
    System.out
    .println("Length of Contract and Interest Rate: (1) 7 years @ 5.35%");
    System.out.println("\t\t\t\t\t (2) 15 years @ 5.50%");
    System.out.println("\t\t\t\t\t (3) 30 years @ 5.75%");
    System.out.println();
    System.out.println("The results:");
    int i;
    for (i = 0; i <= 2; i++) {
    loanTerm[i] = loanTerm[i] / 12;
    intRate[i] = (intRate[i] * .01);
    monthlyPay = loanAmt * intRate[i]
    / (1 - Math.pow(1 + intRate[i], -loanTerm[i]));
    // displays results
    System.out.println();
    System.out.println("Mortgage Payment For $" + loanAmt
    + " Length of Contract " + loanTerm[i] + " years at");
    System.out
    .println("a "
    + (money2.format(intRate[i])
    + " Interest Rate = " + (money
    .format(monthlyPay))));
    }
    } while (x < 3);
    }
    }
    [/CODE]

  2. Eeee.. dah lama tk buat task Java zaman belajar.. time belajar dulu, siyes aku tk reti nak buat.
    Sekarang aku main buat asalkan jalan...
    Aku kasi bulat2... masih tak propernyer cara.. tapi asalkan jalan la dulu. Lepas nih anda boleh inject lagi..
    kasi masuk deposit cash. instead buat constant 1100 tuh.
    Anda dah ada basic yang kuat. So mesti boleh pahamn start belajar dari code orang.

    [CODE]
    import java.io.*;
    import java.util.HashMap;
    import java.util.Map;
    public class HotelSystem {
    private static BufferedReader input = new BufferedReader(
    new InputStreamReader(System.in));
    private static int room, day;
    private static String confirmProceed;
    private static double price, discount, totalDiscount, totalPrice;
    private static double balance = 0;
    private static double result = 0;
    private static double payment = 1100;
    private static Map<Integer, String> ROOMS = new HashMap<Integer, String>();
    public static void main(String args[]) throws IOException {
    ROOMS.put(1, "STANDARD ROOM");
    ROOMS.put(2, "DELUXE ROOM");
    ROOMS.put(3, "EXECUTIVE ROOM");
    header();
    System.out
    .println("\n********************ROOM TYPE*********************\n");
    System.out.println("1:STANDARD ROOM");
    System.out.println("2:DELUXE ROOM");
    System.out.println("3:EXECUTIVE ROOM\n");
    room();
    }
    public static void header() {
    System.out
    .println("**************************************************");
    System.out.println("HOTEL LANGKAWI INN");
    System.out.println("65,JALAN PANDAK MAYAH,KUAH LANGKAWI");
    System.out.println("TEL:04-5678900 FAX:04-5678901");
    }
    public static void room() throws IOException {
    System.out.print("Your Room Type:");
    if (checkRoom()) {
    System.out.print("Staying For (Days):");
    day = Integer.parseInt(input.readLine());
    calc();
    if (confirmation()) {
    System.out
    .println("\n********************COMPLETED*********************\n");
    System.out.println("TOTAL PAYMENT:RM" + result);
    System.out.println("PAYMENT:RM" + payment);
    System.out.println("BALANCE:RM" + balance);
    System.out
    .println("\n********************THANK YOU*********************\n");
    } else {
    System.out
    .println("\n*************************************************\n");
    System.out.println("Cancel Success!. Start Again ");
    room();
    }
    } else {
    room();
    }
    }
    public static boolean confirmation() throws IOException {
    System.out
    .println("\n********************CONFIRMATION DETAIL*********************\n");
    System.out.println("ROOM : " + ROOMS.get(room));
    System.out.println("PRICE ROOM : " + price);
    System.out.println("STAYING FOR (DAYS): : " + day);
    System.out.println();
    System.out.println("ARE SURE WANT TO PROCEED? 1 = Yes, 2 = No");
    return makeConfirm();
    }
    public static boolean makeConfirm() throws IOException {
    confirmProceed = input.readLine();
    try {
    if (confirmProceed.equalsIgnoreCase("1")
    || confirmProceed.equalsIgnoreCase("Yes"))
    return true;
    else if (confirmProceed.equalsIgnoreCase("2")
    || confirmProceed.equalsIgnoreCase("No"))
    return false;
    else
    return false;
    } catch (Exception e) {
    System.out.println("INVALID INPUT");
    return false;
    }
    }
    public static void calc() {
    switch (room) {
    case 1:
    price = 100;
    discount = (0.05);
    totalDiscount = (price) * (discount);
    totalPrice = (price) - (totalDiscount);
    result = (day) * (totalPrice);
    balance = (payment) - (result);
    break;
    case 2:
    price = 120;
    discount = (0.08);
    totalDiscount = (price) * (discount);
    totalPrice = price - totalDiscount;
    result = (day) * (totalPrice);
    balance = (payment) - (result);
    break;
    case 3:
    price = 150;
    discount = (0.12);
    totalDiscount = (price) * (discount);
    totalPrice = (price) - (totalDiscount);
    result = (day) * (totalPrice);
    balance = (payment) - (result);
    break;
    default:
    break;
    }
    }
    public static boolean checkRoom() {
    try {
    room = Integer.parseInt(input.readLine());
    if (room != 1 && room != 2 && room != 3) {
    System.out.println("INVALID INPUT");
    return false;
    } else
    return true;
    } catch (Exception e) {
    System.out.println("INVALID INPUT");
    return false;
    }
    }
    }
    [/CODE]
×
×
  • Create New...