Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I switch the end function?
    primarykey
    data
    text
    <p>As in, the value as the end where it says "X dollars converts to Y russian ruble" (after the two Digits new Decimal Format) - the problem is that it can be russian ruble, british pound, or euro. How can I differentiate? (text inserted at line in question)</p> <pre><code>import java.awt.*; import java.applet.*; import java.awt.event.*; import java.text.DecimalFormat; public class CurrencyConversion extends Applet implements ItemListener { //declare variables and color double dollars, answer; int empCode; Image dollarSign; Color darkRed = new Color(160, 50, 0); //Create components for applet Label promptLabel = new Label("Enter the dollar amount (do not use commas or dollar signs):"); TextField currencyField = new TextField(20); Label codeLabel = new Label ("Select the desired currency:"); CheckboxGroup codeGroup = new CheckboxGroup () ; Checkbox britishpoundBox = new Checkbox("British Pound",false,codeGroup); Checkbox euroBox = new Checkbox("Euro",false,codeGroup); Checkbox russianrubleBox = new Checkbox("Russian Ruble",false,codeGroup); Checkbox hiddenBox = new Checkbox("",true,codeGroup); Label outputLabel = new Label("Click an option to convert the desired currency."); public void init() { setBackground(darkRed); setForeground(Color.white); add(promptLabel); add(currencyField); currencyField.requestFocus(); currencyField.setForeground(Color.black); add(codeLabel); add(britishpoundBox); britishpoundBox.addItemListener(this); add(euroBox); euroBox.addItemListener(this); add(russianrubleBox); russianrubleBox.addItemListener(this); add(outputLabel); } //This method is triggered by click public void itemStateChanged(ItemEvent choice) { try { dollars = getCurrency(); empCode = getCode(); answer = getComm(dollars,empCode); output(answer, dollars); } catch (NumberFormatException e) { outputLabel.setText("You must enter a dollar amount greater than zero."); hiddenBox.setState(true); currencyField.setText(""); currencyField.requestFocus(); } } public double getCurrency() { double currency = Double.parseDouble(currencyField.getText()); if (currency &lt;= 0) throw new NumberFormatException(); return currency; } public int getCode() { int code = 0; if (britishpoundBox.getState()) code = 1; else if (euroBox.getState()) code = 2; else if (russianrubleBox.getState()) code = 3; return code; } public double getComm(double currency, int code) { double amount = 0.0; switch(code) { case 1: amount = .79610 * currency; break; case 2: amount = .70880 * currency; break; case 3: amount = 35.88240 * currency; break; } return amount; } public void output(double amount, double currency) { DecimalFormat twoDigits = new DecimalFormat("##.00"); outputLabel.setText("Your amount of " + twoDigits.format(currency) + " dollars converts to " + twoDigits.format(amount) RIGHT HERE - what do I do? ); } public void paint(Graphics g) { dollarSign = getImage(getDocumentBase(), "dollarsign.gif"); g.drawImage(dollarSign,12,28,this); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload