Do you call newTransactions() at more than one place?
You should only call it at ONE place.
Ok, I commented it out of the code, not the only place it is called is in the main method, it is also located in the displayResult() method but that is in an if statement to see if it is true or not.
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;
static DecimalFormat df = new DecimalFormat("0.00");
public static void main(String[] args) throws IOException {
JOptionPane.showMessageDialog(null,"Welcome to the Modest International Currency Exchange Services!", "Modest International",1);
readRates();
System.out.println("input currency: " + inputCurrency());
System.out.println("input amount: " + inputAmount());
System.out.println("buy or sell: " + buyOrSell());
System.out.println("rate: "+ rate + " amount: "+ amount + " buy "+ buy);
System.out.println("price in dollars: " + priceInDollars(rate, amount, buy));
if(newTransaction()==1){
displayResult();
}else{
while(newTransaction()==0){
inputCurrency();
inputAmount();
buyOrSell();
displayResult();
}
}
}
public static Double priceInDollars(double rate, double amount, boolean buy){
double rateAmt = rate * amount;
double baseCom = rateAmt * commissionPercent/100;
double commission = Math.min(baseCom, 10);
double dollarValue;
if(buy){
dollarValue = rateAmt += commission ;
}else{
dollarValue = rateAmt -= commission;
}
return dollarValue;
}
public static double composeReport(){
//priceInDollars(rate, amount, buy);
switch (code){
case 'C' : case 'c':
if(buy){
rate = buyingRateC;
}
else{
rate = sellingRateC;
}
break;
case 'M' : case 'm':
if(buy){
rate = buyingRateM;
}
else{
rate = sellingRateM;
}
break;
case 'E' : case 'e':
if(buy){
rate = buyingRateE;
}
else{
rate= sellingRateE;
}
break;
}
return rate;
}
public static void displayResult() throws IOException{
//composeReport();
try{
FileWriter fw = new FileWriter("dailyreport.txt", true);
PrintWriter out = new PrintWriter(fw);
String output = ("Customer " + buyOrSell() + " " + inputAmount() + " " + inputCurrency() + " "
+ priceInDollars(rate, amount, buy) + " dollars" );
out.append(output);
System.out.println("output = " + output);
out.close();
}catch(Exception e){
System.err.println("Error: " + e.getMessage());
}
if(newTransaction()==1){
JOptionPane.showMessageDialog(null,"You receive\n" + priceInDollars(rate, amount, buy)
+ " dollars.\n We appreciate your business!"
, "Payment",1);
}else{
JOptionPane.showMessageDialog(null,"Your charge for the transaction is: \n" + priceInDollars(rate, amount, buy)
+ " dollars.\n " + "We appreciate your business!", "Payment",1);
}
System.out.println("The method was called");
}
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();
}
y.close();
}
public static char inputCurrency() throws IOException{
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);
if(choice.equalsIgnoreCase("CD"))
{
code = 'c';
}else if(choice.equalsIgnoreCase("MP"))
{
code= 'm';
}else if(choice.equalsIgnoreCase("EU"))
{
code = 'e';
}else{
JOptionPane.showMessageDialog(null,"Please enter correct currency code.", "Modest International",1);
//newTransaction();
/*while(newTransaction()==0){
inputCurrency();
inputAmount();
buyOrSell();
displayResult();
}*/
}
composeReport();
return code;
}
public static double inputAmount(){
String inputAmount = JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest International",
JOptionPane.QUESTION_MESSAGE);
if(inputAmount == " "){
JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest International",
JOptionPane.QUESTION_MESSAGE);
} else {
amount = Double.parseDouble(inputAmount);
}
return amount;
}
public static boolean 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);
if(buyOrSell.equalsIgnoreCase("b")||buyOrSell.equalsIgnoreCase("buy"))
{
buy = true;
}else if(buyOrSell.equalsIgnoreCase("s")||buyOrSell.equalsIgnoreCase("sell"))
{
buy = false;
}
return buy;
}
public static int 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 0;
}else{
System.out.print("Modest International is closed for the day. See you tomorrow!");
return 1;
}
}
}