Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by adjit View Post
    I kind of don't get that. What's the point of the modulo? Don't understand why you do xyz/100 and yx%100
    Try it and type out the value of those last two variables (they're 1 and 23) and see if it helps you for your program. Programmers need to be able to experiment a bit ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    Well actually... what if I set up an arraylist in my fields and constructors?
    Java Code:
    import java.util.ArrayList;
    public class Numbers
    {
    private ArrayList<numbers> number;
    public Numbers(ArrayList<numbers>)
    {
    number = new ArrayList<numbers>();
    }
    public int getNumberOfNumbers()
    {
    value = number.size();
    return value;
    }}
    This is just a rough idea, fairly certain the code is wrong in some places, but am I on the right track?
    Last edited by adjit; 06-18-2011 at 07:20 PM.

  3. #23
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Try it and type out the value of those last two variables (they're 1 and 23) and see if it helps you for your program. Programmers need to be able to experiment a bit ...

    kind regards,

    Jos
    OK! I have a good idea now. So if I use the ArrayList idae that I posted followed by a series of ifs
    Like for instance:
    Java Code:
    if(getNumberOfNumbers == 3){
     int x = numbers/100;
     int yz = numbers%100;
    etc. etc.
    have an idea of how the rest of the code should go, kind of like:
    Java Code:
    if(x == 1){
    system.out.println("One hundred")

  4. #24
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    What do you need the ArrayList for? I'm not saying it's a bad idea, it's just that I have no idea why you should need it ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #25
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    take the number that you input and put it into an ArrayList. By doing this you can easily figure out how many numbers are in the entire number that was input.
    i.e. if I type in 123456 and it is placed into an ArrayList, then in the code I can have the ArrayList.size() to figure out how many numbers were input.
    Then you follow that with a bunch of if() statements to help further separate the numbers. if(ArrayList.size() == 3) System.out.println("hundred"), and then within that, throw in your code with the modulo etc.
    with that, you can easily break up the number into more manageable parts. so, I would have several if(ArrayList.size() == x) and each time it would increase to thousand, million, trillion etc.

    Also, do you think it would be wise to consider 2400 as twenty-four hundred?

    Furthermore, do you think it would be better/easier to use an Array[] or ArrayList<>?

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by adjit View Post
    take the number that you input and put it into an ArrayList. By doing this you can easily figure out how many numbers are in the entire number that was input.
    i.e. if I type in 123456 and it is placed into an ArrayList, then in the code I can have the ArrayList.size() to figure out how many numbers were input.
    Then you follow that with a bunch of if() statements to help further separate the numbers. if(ArrayList.size() == 3) System.out.println("hundred"), and then within that, throw in your code with the modulo etc.
    with that, you can easily break up the number into more manageable parts. so, I would have several if(ArrayList.size() == x) and each time it would increase to thousand, million, trillion etc.

    Also, do you think it would be wise to consider 2400 as twenty-four hundred?

    Furthermore, do you think it would be better/easier to use an Array[] or ArrayList<>?
    I would use none of them; I'd use a few simple if statements; ints can't have more than 10 digits and you're only interested in them in groups of three. 2400 is usually pronounced as two-thousand-four-hundred.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #27
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    so how would you go about it? like how would I divide it up into groups of 3?
    have some 'ifs' like if((int x / 1000 > 0) >10) system.out.println("thousand") or something like that?
    Last edited by adjit; 06-18-2011 at 08:47 PM.

  8. #28
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by adjit View Post
    so how would you go about it? like how would I divide it up into groups of 3?
    have some 'ifs' like if((int x / 1000 > 0) >10) system.out.println("thousand") or something like that?
    I might as well give (part of) the code; you'll find it anyway somewhere in this forum:

    Java Code:
    	private static final String[] simple= { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
    					"ten", "evelen", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
    					"eightteen", "nineteen" };
    	
    	private static final String[] tens= { null, null, "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
    	
    	public static String say(int number) { return say(number, true); }
    
    	private static String say(int number, boolean sayZero) {
    		
    		if (number < 0)				return "minus "+say(-number, sayZero);
    		
    		if (number == 0)			return sayZero?simple[number]:"";
    
    		if (number < 20) 			return simple[number];
    		
    		if (number < 100)			return tens[number/10]+say(number%10, false);
    	
    		if (number < 1000) 			return say(number/100, false)+"hundred"+say(number%100, false);
    
    		if (number < 1000000) 		return say(number/1000, false)+"thousand "+say(number%1000, false);
    
    		if (number < 1000000000)	return say(number/1000000, false)+"million "+say(number%1000000, false);
    		
    		return say(number/1000000000, false)+"billion "+say(number%1000000000, false);
    	}
    Please study it and try to understand it, don't just copy and paste it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #29
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    I might as well give (part of) the code; you'll find it anyway somewhere in this forum:

    Java Code:
    	private static final String[] simple= { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
    					"ten", "evelen", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
    					"eightteen", "nineteen" };
    	
    	private static final String[] tens= { null, null, "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
    	
    	public static String say(int number) { return say(number, true); }
    
    	private static String say(int number, boolean sayZero) {
    		
    		if (number < 0)				return "minus "+say(-number, sayZero);
    		
    		if (number == 0)			return sayZero?simple[number]:"";
    
    		if (number < 20) 			return simple[number];
    		
    		if (number < 100)			return tens[number/10]+say(number%10, false);
    	
    		if (number < 1000) 			return say(number/100, false)+"hundred"+say(number%100, false);
    
    		if (number < 1000000) 		return say(number/1000, false)+"thousand "+say(number%1000, false);
    
    		if (number < 1000000000)	return say(number/1000000, false)+"million "+say(number%1000000, false);
    		
    		return say(number/1000000000, false)+"billion "+say(number%1000000000, false);
    	}
    Please study it and try to understand it, don't just copy and paste it.

    kind regards,

    Jos
    I'm sorry, but I have no idea what you did with the private static and all that etc. and is that the whole code that is required?

  10. #30
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by adjit View Post
    I'm sorry, but I have no idea what you did with the private static and all that etc. and is that the whole code that is required?
    Yep that code does it all; it just lacks a class definition and a main( ... ) method to show you that it all works; I leave that to you because I gave it all away already; you should be able to figure out the rest. And please study your text book(s) for that static and private stuff because that is elementary knowledge.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #31
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    well, don't have a textbook atm because this is just something I wanted to do. Is there anyway you could explain it or something? or just point me in the right direction?

    Also, what do the 'say' part of the code mean. Honestly, I am looking at this confused as hell
    Last edited by adjit; 06-18-2011 at 09:47 PM.

  12. #32
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by adjit View Post
    well, don't have a textbook atm because this is just something I wanted to do. Is there anyway you could explain it or something? or just point me in the right direction?
    Complete the code by putting my code in a class; add a main method and try out the say( ... ) method by printing what it returns.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  2. help changing the RGB of a fillRect
    By AnimeKitty in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 06:02 PM
  3. Changing Cursor
    By ridvan in forum AWT / Swing
    Replies: 2
    Last Post: 06-27-2010, 04:11 AM
  4. Changing the values of a map.
    By Onra in forum New To Java
    Replies: 1
    Last Post: 02-26-2010, 12:20 AM
  5. Changing the Jframe
    By Nemo1959 in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •