?
Solved

Homework question?

Posted on 2003-02-24
6
Medium Priority
?
129 Views
Last Modified: 2010-03-31
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
Comment
Question by:NastyDibran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8011369
please post what you have so far and the questions you have... we are not allowed to give you cut and paste code.
0
 

Author Comment

by:NastyDibran
ID: 8011473
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8012760
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:NastyDibran
ID: 8012969
Is it possible to have multiple codes on the same entry?

This was beautiful though. Thank you! My 10 Hours your 10 minutes.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
ID: 8013011
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
 

Author Comment

by:NastyDibran
ID: 8013138
What more can I say? Besides you are the MAN! Life saver.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question