Hey everyone,
I am new here and am in a Java class in college. I am trying to make a basic currency converter with a file that has country and currency rates. I want the program to look up the rates by finding the country. So far this is what I have
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class converter {
double usdollars;
String country;
double exchangerate;
String countrym;
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Hello");
System.out.println("Would you like to convert(c) money today, modify(m) or exit(x)");
String answer = keyboard.nextLine();
char answer1 = answer.charAt(0);
while (answer1 != 'x')
{
if (answer1 == 'c')
{
System.out.println("How many U.S. Dollars?");
double usdollars = keyboard.nextDouble();
System.out.println("What countries currency do you want to exchange for? (3 letter country code)");
try
{
BufferedReader inputStream = new BufferedReader(new FileReader("rates"));
String country = keyboard.nextLine();
while (country != null)
{
country = inputStream.readLine();
System.out.println(country);
}
inputStream.close();
}
catch(FileNotFoundException e)
{
System.out.println("error opening rates.");
System.exit(0);
}
catch(IOException e)
{
System.out.println("Error reading from file rates.");
}
}
else if (answer1 == 'm')
{
System.out.println("What country do you want to modify?");
String countrym = keyboard.nextLine();
System.out.println("What is the new exchange rate?");
double exchangerate = keyboard.nextDouble();
}
else if (answer1 == 'x')
{
System.exit(0);
}
else
{
System.out.println("Invalid option");
}
answer = keyboard.nextLine();
answer1 = answer.charAt(0);
}
}
}
I keep getting this error message
java.io.FileNotFoundException: rates.rtf (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.io.FileInputStream.<init>(FileInputStream.jav a:66)
at java.io.FileReader.<init>(FileReader.java:41)
at converter.main(converter.java:50)
I am not to sure what it is trying to tell me
but any help would be greatly apreciated and any tips would be helpful also.
Thanks
Dan