Jump to content
Sign in to follow this  
freakery

Masalah Display Harga.

Recommended Posts

Ok, ini salah satu kerja yang diberikan oleh lecturer aku. Setelah habis program coding java ni, aku rasa macam nak letak lagi satu fungsi. Soalan aku, macam mana kah nak display confirmation harga?

Rujuk output, kira macam bila kita pilih nombor 1. Standard room, dia akan papar harga, dan confirmation 1.Yes 2.No.

Setakat ni, apa yang aku buat adalah kiraan secara automatik.

[img]http://i.imgur.com/UdzAA.png[/img]

[img]http://i.imgur.com/OCG83.png[/img]

[CODE]
import java.io.*;
class Room
{
public static void main (String args[])throws IOException
{
BufferedReader input=new BufferedReader (new InputStreamReader(System.in));
System.out.println("**************************************************");
System.out.println("\t\t\t\tHOTEL LANGKAWI INN\n");
System.out.println("\t\t65,JALAN PANDAK MAYAH,KUAH LANGKAWI\n");
System.out.println("\t\t TEL:04-5678900\t\tFAX:04-5678901\n");
System.out.println("\n********************ROOM TYPE*********************\n");
System.out.println("\t\t\t\t1:STANDARD ROOM");
System.out.println("\t\t\t\t2:DELUXE ROOM");
System.out.println("\t\t\t\t3:EXECUTIVE ROOM\n");
int room,day;
double price,discount,totalDiscount,totalPrice;
double balance=0;
double result=0;
double payment=1100;
System.out.print("\t\t\t\tYour Room Type:");
room=Integer.parseInt(input.readLine());
System.out.print("Staying For (Days):");
day=Integer.parseInt(input.readLine());
System.out.println("\n");
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:
System.out.println("INVALID INPUT");
}
System.out.println("\t\t\t\tTOTAL PAYMENT:RM" +result);
System.out.println("\t\t\t\tPAYMENT:RM" +payment);
System.out.println("\t\t\t\tBALANCE:RM" +balance);
System.out.println("\n********************THANK YOU*********************\n");
}
}



[/CODE]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...