Hi, I need help with my program written in DrJava. I'm very new to Java and need to write a program where the user inputs any number from -999 to 999 and it inputs it in words. For ex -24 entered would print negative twenty four or 800 entered would be eight hundred. I need to have at least 2 methods that need to be returned to the main method. I have some ideas so far but need help. When i compile, it says that cannot convert from void to java.lang.string for all the word = ... in my case statements. Help me! Please and thank you very much. I appreciate you thoughts and advice!
import java.util.Scanner; public class NumToText { public static void main (String args[]){ Scanner input = new Scanner (System.in) ; System.out.println ("Enter number."); int number = input.nextInt (); if (number > 99 && number < 1000) { int h = number / 100; //find the hundreds only, next step to print tens and ones hundreds(h); //print number // test if they are from 11 to 19 called teens int x = 0; // initialized variable x for calculations x = number % 100; // find remainder of hundreds like 51 if (x > 10 && x < 20) { // ex,is 51 a teens number? teens (x); // print number } // if not teens number -> split up into tens & units if (x > 0 && x < 100) { int tens = x / 10; // find the tens tens(tens); // print number int ones = x % 10; // finding the units (one, two) ones(ones); // print number } } } static String ones (int number) { String word = ""; switch(number) { case 0: word= System.out.print("zero"); break; case 1: word= System.out.print("one"); break; case 2: word= System.out.print("two"); break; case 3: word= System.out.print("three"); break; case 4: word= System.out.print("four"); break; case 5: word= System.out.print("five"); break; case 6: word= System.out.print("six"); break; case 7: word= System.out.print("seven"); break; case 8: word= System.out.print("eight"); break; case 9: word= System.out.print("nine"); break; } return word; } static String teens (int number) { String word = ""; switch(number) { case 11: word= System.out.print("eleven"); break; case 12: word= System.out.print("twelve"); break; case 13: word= System.out.print("thirteen"); break; case 14: word= System.out.print("fourteen"); break; case 15: word= System.out.print("fifteen"); break; case 16: word= System.out.print("sixteen"); break; case 17: word= System.out.print("seventeen"); break; case 18: word= System.out.print("eighteen"); break; case 19: word= System.out.print("nineteen"); break; } return word; } static String tens (int number) { String word = ""; switch(number) { case 10: word= System.out.print("ten"); break; case 20: word= System.out.print("twenty"); break; case 30: word= System.out.print("thirty"); break; case 40: word= System.out.print("fourty"); break; case 50: word= System.out.print("fifty"); break; case 60: word= System.out.print("sixty"); break; case 70: word= System.out.print("seventy"); break; case 80: word= System.out.print("eighty"); break; case 90: word= System.out.print("ninety"); break; } return word; } static String hundreds (int number) { String word = ""; switch(number) { case 10: word= System.out.print("one hundred"); break; case 2: word= System.out.print("two hundred"); break; case 3: word= System.out.print("three hundred"); break; case 4: word= System.out.print("four hundred"); break; case 5: word= System.out.print("five hundred"); break; case 6: word= System.out.print("six hundred"); break; case 7: word= System.out.print("seven hundred"); break; case 8: word= System.out.print("eight hundred"); break; case 9: word= System.out.print("nine hundred"); break; } return word; } }