Hey guys I need some serious help on a program. I was wondering if anybody could help me convert some code for converting numbers to english text in to some methods that will work in a GUI. Any help will be greatly appreciated! Here is my code I have:
public String getMoneyWords(int number) {
/* special case */
if (number == 0) { return "zero"; }
String prefix = "";
if (number < 0) {
number = -number;
prefix = "";
}
String soFar = "";
int place = 0;
do {
int n = number % 1000;
if (n != 0){
String s = convertLessThanOneThousand(n);
soFar = s + mNames[place] + soFar;
}
place++;
number /= 1000;
} while (number > 0);
return (prefix + soFar).trim();
}
public static void main(String[] args) {
MoneyModel f = new MoneyModel();
System.out.println("*** " + f.getCheckWords(0));
System.out.println("*** " + f.getCheckWords(1));
System.out.println("*** " + f.getCheckWords(16));
System.out.println("*** " + f.getCheckWords(100));
System.out.println("*** " + f.getCheckWords(118));
System.out.println("*** " + f.getCheckWords(200));
System.out.println("*** " + f.getCheckWords(219));
System.out.println("*** " + f.getCheckWords(800));
System.out.println("*** " + f.getCheckWords(801));
System.out.println("*** " + f.getCheckWords(999999));
System.out.println("*** " + f.getCheckWords(-45));
/*
*** Zero
*** One
*** Sixteen
*** One hundred
*** One hundred eighteen
*** Two hundred
*** Two hundred nineteen
*** Eight hundred
*** Eight hundred one
*** Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
*** Fourty Five
*/
}
}
Here is my methods that I need to store information into:
public MoneyModel() for null constructor, not sure how to do this
public double getMoneyAmount()
public void setMoneyAmount(double)
public String getMoneyWords() (return value into english text)
/**
* JButton to let the stuff go
*/
private JButton goButton;
/**
* JTextArea to get the input from the user
*/
private JTextArea inputArea;
/**
* JTextArea to show the output to the user
*/
private JTextArea outputArea;
/**
* Default constructor to setup the window
* @since 1.0
*/
public MoneyGUI() {
//For the application setup the window
if (this instanceof JFrame) {
setSize(500,200);
setLocation(40,40);
setTitle("Check Writer");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
//Initialize instance variables
theModel = new MoneyModel();
goButton = new JButton("Go");
goButton.addActionListener(this);
inputArea = new JTextArea(1,10);
outputArea = new JTextArea(3,40);
outputArea.setEditable(false);
outputArea.setLineWrap(true);
outputArea.setWrapStyleWord(true);
//Setup top panel
JPanel topPanel = new JPanel();
JLabel numLabel = new JLabel("Number to translate: ");
topPanel.add(numLabel);
topPanel.add(inputArea);
//Setup center panel
JPanel centerPanel = new JPanel();
JLabel outLabel = new JLabel("Number as text: ");
centerPanel.add(outLabel);
centerPanel.add(outputArea);
i guess i need to change something in my model to the method getCheckAmount but i not sure what to change in the model, well the GUI was provided for me and can't be changed
> i guess i need to change something in my model to the method getCheckAmount
no you need to add new methods
0
DreamWeaver777Author Commented:
what would I need to put in the getCheckAmount method so I get the same results that I am getting in my model now, everything is coming out fine in the terminal window for my print line in my model now, by the way thanks for consulting with me i appreciate it.
/**
* JButton to let the stuff go
*/
private JButton goButton;
/**
* JTextArea to get the input from the user
*/
private JTextArea inputArea;
/**
* JTextArea to show the output to the user
*/
private JTextArea outputArea;
/**
* Default constructor to setup the window
* @since 1.0
*/
public MoneyGUI() {
//For the application setup the window
if (this instanceof JFrame) {
setSize(500,200);
setLocation(40,40);
setTitle("Check Writer");
setDefaultCloseOperation(E
}
//Initialize instance variables
theModel = new MoneyModel();
goButton = new JButton("Go");
goButton.addActionListener
inputArea = new JTextArea(1,10);
outputArea = new JTextArea(3,40);
outputArea.setEditable(fal
outputArea.setLineWrap(tru
outputArea.setWrapStyleWor
//Setup top panel
JPanel topPanel = new JPanel();
JLabel numLabel = new JLabel("Number to translate: ");
topPanel.add(numLabel);
topPanel.add(inputArea);
//Setup center panel
JPanel centerPanel = new JPanel();
JLabel outLabel = new JLabel("Number as text: ");
centerPanel.add(outLabel);
centerPanel.add(outputArea
this.getContentPane().add(
this.getContentPane().add(
this.getContentPane().add(
}
public void actionPerformed (ActionEvent e) {
try {
String inText = inputArea.getText();
double inValue = Double.parseDouble(inText)
theModel.setCheckAmount(in
outputArea.setText(theMode
}
catch (NumberFormatException except) {
outputArea.setText("You have input a non-numeric value");
inputArea.setText("");
}
}
/**
* Main method to get stuff started
* @since 1.0
*/
public static void main (String args[]) {
MoneyGUI myGUI = new MoneyGUI();
myGUI.show();
}
}