Hi All,
I am currently trying to figure out to finish this project. Below is my code that I have so far. There are some blank methods that I am not sure where to even begin on how to complete them. I have a description of what the methods should do above them, so please help guide me on the blank methods so I can figure them out. Part of what is confusing to me is how to get the data that is read from the file and use it in the conversions since some of the data is inputted through dialog boxes. Thanks for any help in advance.
import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class CurrencyExchange {
final static double MIN_COMISSION = 5;
static double commissionPerCent;
static double buyingRateC;
static double sellingRateC;
static double buyingRateM;
static double sellingRateM;
static double buyingRateE;
static double sellingRateE;
static double amount;
static char code;
static boolean buy;
static double rate;
DecimalFormat format = new DecimalFormat();
/*displays the welcoming message;
*calls readRates( );
*runs a while loop as long as newTransaction( ) returns YES;
*the loop calls the methods input Currency( ), inputAmount( ),
*buyOrSell( ), displayResult( );
*sends the closing message "Exchange is closed for the day."
*to the console and terminates the process.
*/
public static void main(String[] args) throws IOException {
JOptionPane.showMessageDialog(null,"Welcome to the Modest International Currency Exchange Services!", "Modest International",1);
readRates();
while(newTransaction()== true){
inputCurrency();
inputAmount();
buyOrSell();
displayResult();
}
}
/*return type double;
*parameters: double rate, double amount, boolean buy;
*computes and returns the dollar cost of a transaction of the
*given exchange rate 'rate', currency amount 'amount' and buy value true
*for buying and false for selling, respectively;
*/
public static Double priceInDollars(double rate, double amount, boolean buy){
return;
}
/*return type String; no parameters;
*runs a switch controlled by the 'code' data field as its selector;
*for each case of the code and the accompanying buy value the switch determines and
*assigns the current rate of the transaction;
*the method composes and returns the output report to be
*written to the output file; calls the priceInDollars( ) method
*to obtain the dollar value which is to be included in the report;
*/
public static String composeReport(){
return;
}
/*void; no parameter; calls the composeReport( ) method and
* writes the return value to the output file; calls the
* priceInDollars( ) method and displays the output message
*/
public static void displayResult(){
}
/*void; parameter: String line; the parameter must be formatted
* as a line shown in the input file; instantiates a Scanner object to tokenize the
* parameter string; uses a nested if-else sequence to assign the second
* token to the correct rate variable or to the commission
*/
public static void assignRate(String line){
}
/*void; no parameter;
*throws IOException; instantiates a Scanner object and runs a
*while loop to read the lines of the input file; calls the
*assignRate() method for every input line, passing the line to
*the method as the parameter
*/
public static void readRates() throws IOException{
File f = new File("dailyrates.txt");
Scanner y = new Scanner(f);
String com;
String buyC;
String sellC;
String buyM;
String sellM;
String buyE;
String sellE;
while(y.hasNext()){
com = y.next();
commissionPerCent= y.nextDouble();
buyC = y.next();
buyingRateC= y.nextDouble();
sellC = y.next();
sellingRateC=y.nextDouble();
buyM = y.next();
buyingRateM= y.nextDouble();
sellM = y.next();
sellingRateM=y.nextDouble();
buyE = y.next();
buyingRateE= y.nextDouble();
sellE = y.next();
sellingRateE=y.nextDouble();
}
}
/*void; no parameter;
*solicits and assigns the code value; if no input supplied,
*sends the message "N0 currency input. Transaction aborted." to the console
*and assigns character '?' to code upon which the main method opens the window on Figure 9
*and the process starts all over.
*/
public static void inputCurrency(){
String choice = JOptionPane.showInputDialog(null, "We Exchange the following currencies:\nCD (Canadian Dollar) \nMP (Mexican Peso) \nEU (Euro) " +
"\nEnter the currency code:", "Modest International",
JOptionPane.QUESTION_MESSAGE);
}
/*void; no parameter;
*solicits and assigns the amount value; if no input supplied,
*sends the message "N0 amount input. Transaction aborted." to the console and assignes -1
*to amount upon which the main method opens the window
*/
public static void inputAmount(){
String inputAmount = JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest International",
JOptionPane.QUESTION_MESSAGE);
}
/*void; no parameter; solicits and assigns the buy value;
* note that no input validation is necessary if a Confirm Dialog is used
*/
public static void buyOrSell(){
String buyOrSell = JOptionPane.showInputDialog(null, "Please \n type \"b\" or \"buy\" if you want to buy and" +
" \n type \"s\" or \"sell\" if you want to sell the amount.", JOptionPane.QUESTION_MESSAGE);
}
/*return type boolean; no parameter; opens a Confirm Dialog and
*returns true for JOptionPane.YES_OPTION, false otherwise
*/
public static boolean newTransaction(){
int result = JOptionPane.showConfirmDialog(null,"Would you like to make a transaction?", "Modest International",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION){
return true;
}else{
System.out.print("Modest International is closed for the day. See you tomorrow!");
return false;
}
}
}
Thanks again!