• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

Homework question?

I have a hw assignment that I have spent about 10 hours on and still have gotten nowhere.
I have to have a user be able to type a 3 letter code for the countries currency to convert to the Euro.
It should be a basic non gui app. The Euro conversion only needs to go 1 to 20. It should print out with as many columns as codes entered. 4 should be maximum amount of codes entered on the console.
Any hints?
0
NastyDibran
Asked:
NastyDibran
  • 3
  • 3
1 Solution
 
bobbit31Commented:
please post what you have so far and the questions you have... we are not allowed to give you cut and paste code.
0
 
NastyDibranAuthor Commented:
package EuroTable;

import java.io.*;
public class EuroTable {
    public static void main(String args[]) throws IOException {
        BufferedReader stdin = new BufferedReader(
        new InputStreamReader(System.in ));
        int euro = 1;
        String BEF = "40.3399";
        String DEM = "1.95583";
        String ESP = "166.386";
        String FRF = "6.55957";
        String IEP = "0.787564";
        String ITL = "1936.27";
        String LUF = "40.3399";
        String NLG = "2.20371";
        String ATS = "13.7603";
        String PTE = "200.482";
        String FIM = "5.94573";
        double answer = 0;
        double number;
        for (int i = 0; i < args.length; i++) {
       
            number = Double.parseDouble(args[i]);
            System.out.println("EURO" + "   " + number);/** Table Header */
            double y = Double.parseDouble( stdin.readLine().trim() );
            for (euro = 1; euro <=20; euro++){
                System.out.println(euro + "      " + euro * number);
            }
        }
    }
}
0
 
bobbit31Commented:
i still don't get it...

what parameter(s) are you passing to your class?

ie:
EuroTable <param1> <param2>?

then: what are you supposed to be reading in from user input? strings specifiying currency you want converted?

ie:
FIM PTE ATS
or is it one at a time?

either way,
double y = Double.parseDouble( stdin.readLine().trim() );

should probably be
String y = stdin.readLine().trim();

if (y.toUpperCase().equals("FIM")) {
   // do conversion for FIM
}

if you don't want to pass anything to your class:
 for (int i = 0; i < args.length; i++) {
is unnecessary.

maybe this will help...

run this, and at the prompt enter the three letter string for the currency you want converted:

import java.io.*;
import java.util.Hashtable;

public class EuroTable {
   public static void main(String args[]) throws IOException {
       BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
       int euro = 1;

          Hashtable rates = new Hashtable();
          rates.put("BEF", new Double("40.3399"));
          rates.put("DEM", new Double("1.95583"));
          rates.put("ESP", new Double("166.386"));
          rates.put("FRF", new Double("6.55957"));
          rates.put("IEP", new Double("0.787564"));
          rates.put("ITL", new Double("1926.27"));
          rates.put("LUF", new Double("40.3399"));
          rates.put("NLG", new Double("2.20371"));
          rates.put("ATS", new Double("13.7603"));
          rates.put("PTE", new Double("200.482"));
          rates.put("FIM", new Double("5.94573"));

/*
       String BEF = "40.3399";
       String DEM = "1.95583";
       String ESP = "166.386";
       String FRF = "6.55957";
       String IEP = "0.787564";
       String ITL = "1936.27";
       String LUF = "40.3399";
       String NLG = "2.20371";
       String ATS = "13.7603";
       String PTE = "200.482";
       String FIM = "5.94573";
*/
//       double answer = 0;
//       double number;
//      for (int i = 0; i < args.length; i++) {

//           number = Double.parseDouble(args[i]);
//           System.out.println("EURO" + "   " + number);/** Table Header */
           System.out.print("Enter currency to convert: ");
           String y = stdin.readLine().trim();
           for (euro = 1; euro <=20; euro++){
               System.out.println(euro + " euros = " + euro * ((Double) rates.get(y.toUpperCase())).doubleValue());
               // System.out.println(euro + "      " + euro * number);
           }
//       }
   }
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
NastyDibranAuthor Commented:
Is it possible to have multiple codes on the same entry?

This was beautiful though. Thank you! My 10 Hours your 10 minutes.
0
 
bobbit31Commented:
more like 5 minutes ;)

but:
import java.io.*;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class EuroTable {
   public static void main(String args[]) throws IOException {
       BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
       int euro = 1;

          Hashtable rates = new Hashtable();
          rates.put("BEF", new Double("40.3399"));
          rates.put("DEM", new Double("1.95583"));
          rates.put("ESP", new Double("166.386"));
          rates.put("FRF", new Double("6.55957"));
          rates.put("IEP", new Double("0.787564"));
          rates.put("ITL", new Double("1926.27"));
          rates.put("LUF", new Double("40.3399"));
          rates.put("NLG", new Double("2.20371"));
          rates.put("ATS", new Double("13.7603"));
          rates.put("PTE", new Double("200.482"));
          rates.put("FIM", new Double("5.94573"));

/*
       String BEF = "40.3399";
       String DEM = "1.95583";
       String ESP = "166.386";
       String FRF = "6.55957";
       String IEP = "0.787564";
       String ITL = "1936.27";
       String LUF = "40.3399";
       String NLG = "2.20371";
       String ATS = "13.7603";
       String PTE = "200.482";
       String FIM = "5.94573";
*/
//       double answer = 0;
//       double number;
//      for (int i = 0; i < args.length; i++) {

//           number = Double.parseDouble(args[i]);
//           System.out.println("EURO" + "   " + number);/** Table Header */
           System.out.print("Enter currency/currencies: ");
           String y = stdin.readLine().toUpperCase().trim();
           StringTokenizer st = new StringTokenizer(y, " ");
           String cur = null;
           while (st.hasMoreTokens()) {
                     cur = st.nextToken();
                for (euro = 1; euro <=20; euro++){

                    System.out.println(euro + " euros = " + euro * ((Double) rates.get(cur)).doubleValue() + " " + cur);
                    // System.out.println(euro + "      " + euro * number);
                     }
                 }
   }
}

when it prompts you to enter currencies, just separate them by spaces:

ie:
> enter currency/currencies: FIM DEM NLG
0
 
NastyDibranAuthor Commented:
What more can I say? Besides you are the MAN! Life saver.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now