|
sy ade 2 soalan assimnt. sape boleh bantu. sy ngaku hanya 2 bulan blaja java(sambung blaja kt oum). x sempat nk pandai pun. x pernah blaja java....sesape sudi bantu bgtau lah ye. 10mac kena hantar.insyaallah ade saguhati pada yg sudi membantu......10q
soalan 1
Write a practical Java program that reads an integer between 0 and 99 and verbalizes it. For example, if the program is given 23 it would display "twenty three".
soalan 2
Design a currency Converter class whose object will handle conversion of three currencies (Dollar, Ringgit, Pound). A single object of the new currency Converter class you design here will handle all these three currencies. Instead of having specific conversion methods such as toDollar, toPound and so forth, the new currency Converter class supports one generic conversion method call exchange. The method has three arguments: fromCurrency, toCurrency and amount. The first two arguments are String and give the names of currencies. The third argument is the amount that need to be converted. For example, to convert RM250 to dollar, we write:
dollar = converter.exchange(‘ringgit”, “dollar”, 250.0);
To set the exchange rate for a currency, we use the setRate method. This method takes three arguments. The first two arguments are the currency names, and the third argument is the rate. For example, if the exchange rate for dollar is 3.4 Dollar to RM1, then we write:
converter.setRate(“dollar”, “ringgit”, 3.4);
In addition, the class also have the following method:
updateRate (“fromCurrency”, “toCurrency”, newRate) - The first two arguments are the currency names, and the third argument is the new exchange rate.
Finally, test your program by creating its object in the main() method.
|
|
|
|
|
|
|
|
soklan 1.
buat array untuk nilai dan verbal
implode nilai yang dimasukkan dalam satu lagi array
echo dengan loop dan beberapa pengecualian seperti ten, eleven, twelve etc yang jadi satu je verbalnya.
soklan 2.
rasanya dia dah bagi apa yang kau perlu ada, berapa file yang kene ada. main sikit dengan objek.
ps. aku dah lama tinggal java. |
|
|
|
|
|
|
|
boleh tolong tunjukkan macam mana untuk soalan 1 |
|
|
|
|
|
|
|
saya baru jer belajar java nie tapi tak berapa paham macam mana nak buat harap ada sesiapa yg sudi membantu
saya sudah start sikit tapi tak boleh jalan ada error
ni sebahagian yg saya buat untuk soalan 1
import java.util.Scanner;
class counter {
public static void main (String [] args) {
//count 0 to 99
int [] counter = new int[100];
System.out.println("please enter a number between 0 to 99:");
Scanner input = new Scanner(System.in);
}
int no;
if (no<20) {
//for numbers 0-19, it is quite straight forwards as shown below
if (no==0) {System.out.println("Zero");}
else if (no==1) {System.out.println("One");}
else if (no==2) {System.out.println("Two");}
else if (no==3) {System.out.println("Three");}
else if (no==4) {System.out.println("Four");}
else if (no==5) {System.out.println("Five");}
else if (no==6) {System.out.println("Six");}
else if (no==7) {System.out.println("Seven");}
else if (no==8) {System.out.println("Eight");}
else if (no==9) {System.out.println("Nine");}
else if (no==10) {System.out.println("Ten");}
else if (no==11) {System.out.println("Eleven");}
else if (no==12) {System.out.println("Twelve");}
else if (no==13) {System.out.println("Thirteen");}
else if (no==14) {System.out.println("Fourteen");}
else if (no==15) {System.out.println("Fifthteen");}
else if (no==16) {System.out.println("sixteen");}
else if (no==17) {System.out.println("Seventeen");}
else if (no==18) {System.out.println("eighteen");}
else if (no==19) {System.out.println("nineteen");}
}
}
tapi error
yg dari 20 keatas tiada idea macam mana nak start |
|
|
|
|
|
|
|
xhanis posted on 28-2-2013 07:38 AM
saya baru jer belajar java nie tapi tak berapa paham macam mana nak buat harap ada sesiapa yg sudi m ...
solan no1 tu kalau python boleh guna dict method. kalu java tak tau la apa equivalent dia. method yang boleh pair
key : value .
sorry kalau tak membantu dgt. aku pun bru je belajar programming . itu pun utk suka2.
|
|
|
|
|
|
|
|
xhanis posted on 28-2-2013 07:38 AM
saya baru jer belajar java nie tapi tak berapa paham macam mana nak buat harap ada sesiapa yg sudi m ...
utk soklan 1
pakai array
String[] ones= {"", "one", "two", "three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
String[] tens= {"", "", "twenty", "thirty","forty","fifty","sixty","seventy","eightyt","ninety"};
lepas tu, pandai2 la...
baca nombor diberi, kira bilangan digit dlm nombor (either 1 digit or 2 digit)
kalo 1 digit, just point direct dalam array ones
kalo 2 digit, split digit, baca digit first, point ke array tens, then baca second digit n point ke array ones
lepas tu sambungkan kedua2 word tens n ones utk form final word, then print.
then, kalo 1st digit tu no 1, direct guna array ones utk dpt jawapan utk nombor belas2...
nak split guna modulo
semoga berjaya
Last edited by craduza on 10-3-2013 08:13 PM
|
|
|
|
|
|
|
|
utk soklan 2
kena buat satu class baru
public class Converter{
//masukkan apa2 yg patut}
dlm kelas ni nanti ada method exchange, SetRate dan UpdateRate
semoga berjaya...nak buat full code x larat nak study balik...kepala dah berkarat..lama x pakai class method nih....hehehehe
|
|
|
|
|
|
|
| |
|