ano po buh ang switch case master?google it. mahirap ito ng mano mano yan dito.
do while loop
while loop
do while infinite loop
etc..
switch case nakikita ko s kanilang code eh hindi pa naman kami tinuruan yan ng aming guro.ano po buh ang switch case master?
salamat po sa idea...Ganito yung concept na ibibigay ko.
Diba kunyare 4890
May method kasi na ginagamit (nakalimutan ko na) paramakuha si 4000
Then si 800
Then si 90
Tapos gawa ka ng txt file at gamit ang parsing eh dun ka kumuha nung kumparison sa for every tens hundreds at thousands mo.
So
If thouVar == 4000
thouWord = Four Thousand
If hundVar == 800
HundWord = etc etc
Tapos concat na lang ng strings .
Sana nakatulong po
Walang anuman.salamat po sa idea...
import java.util.HashMap;
import java.util.Map;
public class MainApp {
static String oneString = "1,one,2,two,3,three,4,four,5,five,6,six,7,seven,8,eight,9,nine";
static String tenString = "10,ten,20,twenty,30,thirty,40,forty,50,fifty,60,sixty,70,seventy,80,eighty,90,ninety";
static Map<Integer,String> onesMap;
static Map<Integer,String> tensMap;
public static void main(String[] args) {
createMaps();
//test number
//assuming TENS lang muna numbers 20 and up to 99
//if you try 19 or 15 or 12 - katawa tawa ang lalabas (error)
int num = 29;
System.out.println(convertNumberToWords(num));
}
static String convertNumberToWords(int number) {
return readFirstDigit(number) + readLastDigit(number);
}
//READ the leftmost digit
static String readFirstDigit(int number) {
String word = ""+number;
int digit = Integer.parseInt(""+word.charAt(0)) * 10;
word = tensMap.get(digit);
return word;
}
//READ the rightmost digit
static String readLastDigit(int number) {
String word = " - ";
if(number != 0) {
String numString = ""+ number;
int digit = Integer.parseInt(""+numString.charAt(1));
String mapWord = onesMap.get(digit);
if(mapWord==null) {
word="";
} else {
word = " " + mapWord;
}
}
return word;
}
//mga initialization methods lang mga mga ito
//pang prepare lang ng mga MAP arrays
static void createMaps() {
//ones
onesMap = splitToMap(oneString);
//tens
tensMap = splitToMap(tenString);
}
static String getWord(Map<Integer,String> map, int number) {
String theWord = "";
theWord = map.get(number);
return theWord;
}
static HashMap<Integer,String> splitToMap(String string) {
HashMap<Integer,String> theMap = new HashMap<>();
String[] stringArray = string.split(",");
for(int i=0; i<stringArray.length; i=i+2) {
String key = stringArray[i];
String value = stringArray[i+1];
theMap.put(Integer.parseInt(key), value);
}
return theMap;
}
}
hindi po ako senior high. College na po ako BSIT... Hirap kase wla p akong background s programming..Walang anuman.
Btw matanong ko . ICT ng SHS ka no?
relatively easy lang ito... may konting trabaho lang ito tapos ang logic ay relatively easy.
- gamit ka ng KEY-VALUE pair array (or MAP)...or parang ganito (1,"one")
- pero hindi mo gagawin lahat from 1 to 5000..
- gagawa ka ng MAP ARRAY based on DIGIT places (like ones, tens, hundreds and thousands)
**parang ganito**
[1,"one", 2,"two" up 9] and call it ONES_ARRAY
- take note, merong mga "unsual" like ten, 11, 12, 13, up to 19...all the "teens"... you can use LOGIC sa mga ito or gawa ka ng MAP array din dahil konti lang naman sila. Konti lang ang mga un-usual. I think nasa range lang ng tens up to 99.
- pagdating sa HUNDREDS and THOUSANDS... puwedeng wala ng MAP array ito... gamitin mo lang LOGIC
***halimbawa***
501 = "five HUNDRED one"
- yung "five" get it from your ONES_ARRAY
- yung HUNDRED...ay logic
- yung "one" get it from your ONES_ARRAY
4302 = "four THOUSAND three HUNDRED two
- yung "four" get it from your ONES_ARRAY
- yung THOUSAND..ay logic
- yung "three" get it from your ONES_ARRAY
- yung HUNDRED..ay logic
- yung "two" get it from your ONES_ARRAY
33 = thirty three
- yung "thirty" is from your TENS_ARRAY (like 10, 20, 30, 40...up to 90)
- yung "three" is from your ONES_ARRAY
233 = two HUNDRED thirty three
- yung two is from your ONES_ARRAY
- HUDRED is logic
- thirty is from your TENS_ARRAY
- three is from your ONES_ARRAY
Kuha mo na? It's array + logic + string concatenation
Parang ganito na yung whole logic niya.
GIVEN: 699
- find out if GIVEN is in the ONES, TENS, HUNDREDS, THOUSANDS
- read FIRST DIGIT ("6"), get word from ONES_ARRAY, concatenate word HUNDRED
- read SECOND DIGIT, skip if zero, get word from ONES-ARRAY, concatenate TY
- read THIRD DIGIT, skip if zero, get word from ONES_ARRAY
- exit
and just to prove my point (na it simplier that you might think). Heto ang initial code ko pang 20 to 99.
TAKE NOTE: initial lang ito at puwedeng may mga errors pa....and in JAVA.
Code:import java.util.HashMap; import java.util.Map; public class MainApp { static String oneString = "1,one,2,two,3,three,4,four,5,five,6,six,7,seven,8,eight,9,nine"; static String tenString = "10,ten,20,twenty,30,thirty,40,forty,50,fifty,60,sixty,70,seventy,80,eighty,90,ninety"; static Map<Integer,String> onesMap; static Map<Integer,String> tensMap; public static void main(String[] args) { createMaps(); //test number //assuming TENS lang muna numbers 20 and up to 99 //if you try 19 or 15 or 12 - katawa tawa ang lalabas (error) int num = 29; System.out.println(convertNumberToWords(num)); } static String convertNumberToWords(int number) { return readFirstDigit(number) + readLastDigit(number); } //READ the leftmost digit static String readFirstDigit(int number) { String word = ""+number; int digit = Integer.parseInt(""+word.charAt(0)) * 10; word = tensMap.get(digit); return word; } //READ the rightmost digit static String readLastDigit(int number) { String word = " - "; if(number != 0) { String numString = ""+ number; int digit = Integer.parseInt(""+numString.charAt(1)); String mapWord = onesMap.get(digit); if(mapWord==null) { word=""; } else { word = " " + mapWord; } } return word; } //mga initialization methods lang mga mga ito //pang prepare lang ng mga MAP arrays static void createMaps() { //ones onesMap = splitToMap(oneString); //tens tensMap = splitToMap(tenString); } static String getWord(Map<Integer,String> map, int number) { String theWord = ""; theWord = map.get(number); return theWord; } static HashMap<Integer,String> splitToMap(String string) { HashMap<Integer,String> theMap = new HashMap<>(); String[] stringArray = string.split(","); for(int i=0; i<stringArray.length; i=i+2) { String key = stringArray[i]; String value = stringArray[i+1]; theMap.put(Integer.parseInt(key), value); } return theMap; } }
salamat lodi... Nadagdagan na naman ang idea ko.. Hahanapin ko muna sinasabe mong map ray.. Wla pa kse kami dyan na topic.. Hehheerelatively easy lang ito... may konting trabaho lang ito tapos ang logic ay relatively easy.
- gamit ka ng KEY-VALUE pair array (or MAP)...or parang ganito (1,"one")
- pero hindi mo gagawin lahat from 1 to 5000..
- gagawa ka ng MAP ARRAY based on DIGIT places (like ones, tens, hundreds and thousands)
**parang ganito**
[1,"one", 2,"two" up 9] and call it ONES_ARRAY
- take note, merong mga "unsual" like ten, 11, 12, 13, up to 19...all the "teens"... you can use LOGIC sa mga ito or gawa ka ng MAP array din dahil konti lang naman sila. Konti lang ang mga un-usual. I think nasa range lang ng tens up to 99.
- pagdating sa HUNDREDS and THOUSANDS... puwedeng wala ng MAP array ito... gamitin mo lang LOGIC
***halimbawa***
501 = "five HUNDRED one"
- yung "five" get it from your ONES_ARRAY
- yung HUNDRED...ay logic
- yung "one" get it from your ONES_ARRAY
4302 = "four THOUSAND three HUNDRED two
- yung "four" get it from your ONES_ARRAY
- yung THOUSAND..ay logic
- yung "three" get it from your ONES_ARRAY
- yung HUNDRED..ay logic
- yung "two" get it from your ONES_ARRAY
33 = thirty three
- yung "thirty" is from your TENS_ARRAY (like 10, 20, 30, 40...up to 90)
- yung "three" is from your ONES_ARRAY
233 = two HUNDRED thirty three
- yung two is from your ONES_ARRAY
- HUDRED is logic
- thirty is from your TENS_ARRAY
- three is from your ONES_ARRAY
Kuha mo na? It's array + logic + string concatenation
Parang ganito na yung whole logic niya.
GIVEN: 699
- find out if GIVEN is in the ONES, TENS, HUNDREDS, THOUSANDS
- read FIRST DIGIT ("6"), get word from ONES_ARRAY, concatenate word HUNDRED
- read SECOND DIGIT, skip if zero, get word from ONES-ARRAY, concatenate TY
- read THIRD DIGIT, skip if zero, get word from ONES_ARRAY
- exit
and just to prove my point (na it simplier that you might think). Heto ang initial code ko pang 20 to 99.
TAKE NOTE: initial lang ito at puwedeng may mga errors pa....and in JAVA.
Code:import java.util.HashMap; import java.util.Map; public class MainApp { static String oneString = "1,one,2,two,3,three,4,four,5,five,6,six,7,seven,8,eight,9,nine"; static String tenString = "10,ten,20,twenty,30,thirty,40,forty,50,fifty,60,sixty,70,seventy,80,eighty,90,ninety"; static Map<Integer,String> onesMap; static Map<Integer,String> tensMap; public static void main(String[] args) { createMaps(); //test number //assuming TENS lang muna numbers 20 and up to 99 //if you try 19 or 15 or 12 - katawa tawa ang lalabas (error) int num = 29; System.out.println(convertNumberToWords(num)); } static String convertNumberToWords(int number) { return readFirstDigit(number) + readLastDigit(number); } //READ the leftmost digit static String readFirstDigit(int number) { String word = ""+number; int digit = Integer.parseInt(""+word.charAt(0)) * 10; word = tensMap.get(digit); return word; } //READ the rightmost digit static String readLastDigit(int number) { String word = " - "; if(number != 0) { String numString = ""+ number; int digit = Integer.parseInt(""+numString.charAt(1)); String mapWord = onesMap.get(digit); if(mapWord==null) { word=""; } else { word = " " + mapWord; } } return word; } //mga initialization methods lang mga mga ito //pang prepare lang ng mga MAP arrays static void createMaps() { //ones onesMap = splitToMap(oneString); //tens tensMap = splitToMap(tenString); } static String getWord(Map<Integer,String> map, int number) { String theWord = ""; theWord = map.get(number); return theWord; } static HashMap<Integer,String> splitToMap(String string) { HashMap<Integer,String> theMap = new HashMap<>(); String[] stringArray = string.split(","); for(int i=0; i<stringArray.length; i=i+2) { String key = stringArray[i]; String value = stringArray[i+1]; theMap.put(Integer.parseInt(key), value); } return theMap; } }
salamat lodi sa paalala..hindi ka matututo kung aasa ka lang "kung" ano lang ang tinuturo sayo ng teacher mo. advance advance dahil hindi lahat ng about sa programming ay tinuturo sa school.
salamat lodi..Si mr google at yôutubê kakampi mo jan