this is the program i have to write
you have to write a program using java language which will realize the following scenario
project scenario:when you run your program it will display a welcome messege (you choose ur welcome messege). then program will ask to input a number beetween 1-9999, once u (user) insert a number the program will output the english words corresponding to the inserted number then ask the user (display the messege),"will u want another try?" if user inser yes then program will ask again to insert a number beetween 1-9999. once u (user) insert another number it will again output in words and this process continues until the user response "No" for the question."will u want another try?". once user inserts "no" program will display "goodbye" and ends the program.


i have tried writing it
but it comes out weird

import javax.swing.*;
public class blahblahblah 
	{
	public static void main (String []args){
	}
boolean cc=true;


String []name= {
		"Zero"*10,"One"*10,"Two"*10,"Three"*10,"Four"*10,"Five"*10, 
		"Six"*10, "Seven"*10, "Eight"*10, "Nine"*10, "Ten"*10,"Eleven"*10,
		"Twelve"*10,"Thirteen"*10,"Fourteen"*10,"Fifteen"*10,"Sixteen"*10,
		"Seventeen"*10,"Eighteen"*10,"Nineteen"*10,"Twenty"*10,"Thirty"*10,
		"Fourty"*10,"Sixty"*10,"Seventy"*10,"Eighty"*10,"Ninety"*10,"One hundred"*10,
		"Two Hundred"*10,"Three Hundred"*10,"Four Hundred"*10,"Five Hundred"*10,
        "Six Hundred"*10,"Seven Hundred"*10,"Eight Hundred"*10"Nine Hundred"*10,
        "One Thousand"*10,"Two Thousand"*10,"Three Thousand"*10,"Four Thousand"*10,
		"Five Thousaand"*10,"Six Thousand"*10,"Seven Thousand"*10,"Eight Thousand"*10,
		"Nine Thousand"*10,"Ten Thousand"*10};
		
int i=0;
name[i]=JOptionPane.showMessageDialog(null,"Welcome to Java Program!!")
String st1=JOptionPane.showInputDialog("Insert a Number between 0-9999");{
i=Integer.parseInt(st1);
System.out.println ("0-9999");
String st2=JOptionPane.showInputDialog ("Do you want another try?");
	
	
	if (st1.equals ("yes"))
	{
	}
else
{

cc=false;
{
}
}

Recommended Answers

All 14 Replies

it comes out weird

Can you explain what happens and perhaps copy and paste here the programs output.

Also don't forget to wrap your codes in code tags and properly indent it cause it's an eyesore

Can you explain what happens and perhaps copy and paste here the programs output.

it doesnt print anything it prints errror

it doesnt print anything it prints errror

post those errors here

Please copy and paste here what ever is printed. All of it.

no the problem is that the program doesnt run when i print thats the error

the program doesnt run

Can you explain what the program does when you try to execute it?
How are you trying to execute it?

Does the program compile? Do you get compiler errors?
Please copy and paste here the compiler errors.

it does run but:

public static void main (String []args){
	}

your main method is empty.

it does run but:

public static void main (String []args){
	}

your main method is empty.

i tried doing this it does not work it gives me a red x
i know how to start the program and do everythin i just want to know how i can put the number to 9000 could u explain that anyone of u

i just want to know how i can put the number to 9000

Please explain what "put the number to 9000" means?
Do you mean to assign the value of 9000 to a variable named number?
int number = 9000;

1) Like Stultuske stated, your main method is empty

public static void main (String []args){
	}

2) Why would you use the * operator on a string?

String []name= {
		"Zero"*10,"One"*10,"Two"*10, ...

3) Why would you set the first String in your array to your welcoming message?

int i=0;
name[i]=JOptionPane.showMessageDialog(null,"Welcome to Java Program!!")

4) Why save the number he entered in the int "i" but never use it again?

String st1=JOptionPane.showInputDialog("Insert a Number between 0-9999");{
i=Integer.parseInt(st1);
System.out.println ("0-9999");

5) Why save the "continue?" answer in st2 then test if st1 is equal to "yes" ?

String st2=JOptionPane.showInputDialog ("Do you want another try?");
	if (st1.equals ("yes"))
	{
	}

6) There is no looping mechanism in your algorithm

7) There is no algorithm to decide which string to print according to the number saved in st1

Asking you to modify this code would be longer than re-writing it , the whole structure is wrong, heres a what it should look like :

import java.awt.Dialog;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

public class Numbers {

	static public void main(String[] args) {
		boolean bKeepGoing = true;
		String sNumber;
		int iNumber;
		int iDialogResult;
		JOptionPane.showMessageDialog(null,"Hello!", "Welcoming title!" , JOptionPane.PLAIN_MESSAGE);
		while(bKeepGoing){
			sNumber = JOptionPane.showInputDialog(null, "Enter a number between 0 and 9999 :", "Input a number!",JOptionPane.QUESTION_MESSAGE);
			try{
				iNumber = Integer.parseInt(sNumber);
				JOptionPane.showMessageDialog(null, getString(iNumber) , "Here it is!" , JOptionPane.INFORMATION_MESSAGE);
				iDialogResult = JOptionPane.showConfirmDialog(null, "Would you like to continue?", "Keep going?", JOptionPane.YES_NO_OPTION);
				if(iDialogResult == JOptionPane.NO_OPTION){
					bKeepGoing=false;
				}
			}
			catch(Exception e){
				JOptionPane.showMessageDialog(null, "Ooops we got an error!\n" + e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
			}
		}
		JOptionPane.showMessageDialog(null, "Good bye stranger!", "Cya", JOptionPane.INFORMATION_MESSAGE);
	}
	
	public static String getString(int n){
		String s = "";
		if(n == 0){
			s += "Zero";
			return s;
		}
		if(n < 0){
			s += "Minus ";
			n *= -1;
		}
		if(n/1000 > 0){
			s+= getNumber(n/1000) + "Thousand ";
		}
		n -= (n/1000)*1000;
		if(n/100 > 0){
			s+= getNumber(n/100) + "Hundred ";
		}
		n -= (n/100)*100;

		if(n/10 > 1){
			s+= getDecade(n/10);
			 n -= (n/10)*10;
			if(n/1 > 0){
				s+= getNumber(n/1);
			}
		}
		else if(n/10 == 1){
			if(n > 13){
				s += getNumber(n-10).trim() + "teen";
			}
			else{
				switch (n) {
				case 10:
					s += "Ten";
					break;
				case 11:
					s += "Eleven";
					break;
				case 12:
					s += "Twelve";
					break;
				case 13:
					s += "Thirteen";
					break;
				}
			}
		}
		else{
			n -= (n/10)*10;
			if(n > 0){
				s+= getNumber(n);
			}
		}
		return s;
	}
	
	public static String getNumber(int n){
		String s = "";
		switch (n) {
		case 9:
			s= "Nine ";
			break;
		case 8:
			s= "Eight ";
			break;
		case 7:
			s= "Seven ";
			break;
		case 6:
			s= "Six ";
			break;
		case 5:
			s= "Five ";
			break;
		case 4:
			s= "Four ";
			break;
		case 3:
			s= "Three ";
			break;
		case 2:
			s= "Two ";
			break;
		case 1:
			s= "One ";
			break;
		}
		return s;
	}

	public static String getDecade(int n){
		String s;
		switch (n) {
		case 9:
			s= "Ninety ";
			break;
		case 8:
			s= "Eightty ";
			break;
		case 7:
			s= "Seventy ";
			break;
		case 6:
			s= "Sixty ";
			break;
		case 5:
			s= "Fifty ";
			break;
		case 4:
			s= "Fourty ";
			break;
		case 3:
			s= "Thirty ";
			break;
		case 2:
			s= "Twenty ";
			break;
		default:
			s = "";
			break;
		}
		return s;
	}
}
commented: Giving too much code -3

@Philippe.Lahaie
1) Forum rules clearly state

Do provide evidence of having done some work yourself if posting questions from school or work assignments

which original poster ignored therefore you should not provided the code
2) Your code? Ouch what a mess that if/else statements and switch statements is something to kill for. Half of that mess can be reduced just by simple use of array or any other collection

fair enough, my mistake.

I was trying to make my post as complete as possible but i definitly understand why i shouldn't have posted the complete code and won't do that mistake twice.

as for the if statement this was done quikly it is probably not the best possible solution nor did i say it was, but it works.

Phil~

PS:I can't edit the older post i made so if any moderator feels like deleting the spoon feeding part feel free.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.