473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Numbers in Words

Hi am a begining programmer still in college I wanted to know could I get help on this java program on netbeans I have to write a program that reads a non- negative integer ( 4 digits-max) and writes that number in words. The program must contain two class: Numbers and Test. I can write the test with no errors but the numbers part keep comin up with errors.
Sep 29 '07 #1
6 1678
Ganon11
3,652 Expert 2GB
What errors are you getting?
Sep 29 '07 #2
What errors are you getting?
I have two errors on my else stamtement its saying cant read else without if and my closing } its saying it cant read it I highlighted my errors with the dollar mark $.




Expand|Select|Wrap|Line Numbers
  1. public class Numbers {
  2.  
  3.     /** Creates a new instance of Numbers */
  4.     public Numbers() {
  5.  
  6.     }
  7.  
  8.     private int value;
  9.     public Numbers(int n){
  10.         value = n;
  11.  
  12.     }
  13.  
  14.  
  15.  
  16.  
  17.  
  18.     public String ToString() {
  19.         String w1 = "";
  20.         w1= digitToString(t);
  21.         int d = getOnes();
  22.         int t = getTens();
  23.         w= tensAndOnesToString();
  24.         return w + w1;
  25.  
  26.  
  27.  
  28.  
  29.    }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     private int getOnes(){
  37.         return value % 10;
  38.  
  39.     }
  40.  
  41.  
  42.     private int getTens(){
  43.         return (value % 100)/10;
  44.  
  45.  
  46.     }
  47.  
  48.  
  49.     private int getHundreds(){
  50.         return (value % 1000)/10;
  51.  
  52.     }
  53.  
  54.  
  55.     private int getThousands(){
  56.         return value % 10;
  57.  
  58.     }
  59.  
  60.  
  61.  
  62.    private String digitToString(int d){
  63.         String w = "";
  64.  
  65.         switch (d){
  66.             case 0: w="zero";break;
  67.             case 1: w="one";break;
  68.             case 2: w="two";break;
  69.             case 3: w="three";break;
  70.             case 4: w="four";break;
  71.             case 5: w="five";break;
  72.             case 6: w="six";break;
  73.             case 7: w="seven";break;
  74.             case 8: w="eight";break;
  75.             case 9: w="nine";break;
  76.  
  77.              return w;
  78.  
  79.  
  80.     }
  81.    }
  82.  
  83.  
  84.     private String tensAndOnesToString(int d){
  85.  
  86.         String w= "";
  87.         int dd= getOnes();
  88.         int t = getTens();
  89.           if (t==1){
  90.              switch (t){
  91.             case 0: w="ten";break;
  92.             case 1: w="eleven";break;
  93.             case 2: w="tweleve";break;
  94.             case 3: w="thirteen";break;
  95.             case 4: w="fourteen";break;
  96.             case 5: w="fifteen";break;
  97.             case 6: w="sixteen";break;
  98.             case 7: w="seventeen";break;
  99.             case 8: w="eighteen";break;
  100.             case 9: w="nineteen";break;
  101.  
  102.              return w;
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.            $else if (t > 1){
  110.  
  111.                    switch (t){
  112.             case 2: w="twenty";break;
  113.             case 3: w="thirty";break;
  114.             case 4: w="fourty";break;
  115.             case 5: w="fifty";break;
  116.             case 6: w="sixty";break;
  117.             case 7: w="seventy";break;
  118.             case 8: w="eighty";break;
  119.             case 9: w="ninty";break;
  120.  
  121.                return w;
  122.                  }
  123.                    if(d!=0)
  124.                        w=w + ""+ digitToString(d);
  125.  
  126.           }
  127.  
  128.  
  129.             $ }
Oct 1 '07 #3
r035198x
13,262 8TB
I have two errors on my else stamtement its saying cant read else without if and my closing } its saying it cant read it I highlighted my errors with the dollar mark $.




public class Numbers {

/** Creates a new instance of Numbers */
public Numbers() {

}

private int value;
public Numbers(int n){
value = n;

}





public String ToString() {
String w1 = "";
w1= digitToString(t);
int d = getOnes();
int t = getTens();
w= tensAndOnesToString();
return w + w1;




}






private int getOnes(){
return value % 10;

}


private int getTens(){
return (value % 100)/10;


}


private int getHundreds(){
return (value % 1000)/10;

}


private int getThousands(){
return value % 10;

}



private String digitToString(int d){
String w = "";

switch (d){
case 0: w="zero";break;
case 1: w="one";break;
case 2: w="two";break;
case 3: w="three";break;
case 4: w="four";break;
case 5: w="five";break;
case 6: w="six";break;
case 7: w="seven";break;
case 8: w="eight";break;
case 9: w="nine";break;

return w;


}
}


private String tensAndOnesToString(int d){

String w= "";
int dd= getOnes();
int t = getTens();
if (t==1){
switch (t){
case 0: w="ten";break;
case 1: w="eleven";break;
case 2: w="tweleve";break;
case 3: w="thirteen";break;
case 4: w="fourteen";break;
case 5: w="fifteen";break;
case 6: w="sixteen";break;
case 7: w="seventeen";break;
case 8: w="eighteen";break;
case 9: w="nineteen";break;

return w;






$else if (t > 1){

switch (t){
case 2: w="twenty";break;
case 3: w="thirty";break;
case 4: w="fourty";break;
case 5: w="fifty";break;
case 6: w="sixty";break;
case 7: w="seventy";break;
case 8: w="eighty";break;
case 9: w="ninty";break;

return w;
}
if(d!=0)
w=w + ""+ digitToString(d);

}


$ }
1.) Please use code tags when posting code
2.) Check your braces. You are starting an if inside a switch after a break ...
Oct 1 '07 #4
Ganon11
3,652 Expert 2GB
You are getting an error because you never added a '}' to finish your first case statement - add this right before your first '$' here.
Oct 1 '07 #5
You are getting an error because you never added a '}' to finish your first case statement - add this right before your first '$' here.
thank you i finished and got an A
Oct 10 '07 #6
r035198x
13,262 8TB
thank you i finished and got an A
Congratulations then.
Oct 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: fo | last post by:
Does anyone know if there is a free code available to convert numbers to text and/or text to numbers? Thanks
3
by: Jeff Uchtman | last post by:
I have found a lot of VB on numbers to words, can this also be done in ASP? Would like to convert a formated currency output to words. Thanks Jeff
5
by: dawenliu | last post by:
Hi, I have a file with this content: xxxxxxx xxxxxxxxxx xxxxx xxxxxxx 1 0 0 0 1 1 0 (many more 1's and 0's to follow)
3
by: Matt Smolic | last post by:
Does anyone know where I can get some info on creating customer account numbers, part numbers and such. In other words what the logic is behind their creation. I am not looking for code, just how...
10
by: brainy_muppet | last post by:
Basically, I have a code with is almost finished but I've having difficultly with the last stage of the process. I have a program that gets assigns different words with a different value via...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
3
by: Bouzy | last post by:
I have a list of words and am trying to replace all the numbers in my list with whitespace. for word in words: numbers = re.search('+', word) word = clearup(word) if word in...
5
geolemon
by: geolemon | last post by:
I'm building a small-scale MRP system for an electronics manufacturing business. There are assemblies that are built, and parts that go into those assemblies. The individual component parts that go...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.