0

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;
		}
	}
}
0

You don't say what the results are. Does it work now?
If not what is wrong with how it executes?
Post the output that shows how it executes and add comments to the output describing what you what it to do differently.

First thing I see is that it is called twice in the main method.

Edited by NormR1: n/a

0

No it does not work properly still.

Output:

input currency: c //stores correct code
input amount: 1000.0 //stores correct amount to be exchanged
buy or sell: true //stores true for buy(also false for sell)
rate: 0.93 amount: 1000.0 buy true //correctly prints rate that is read, amount, and buy/sell
price in dollars: 940.0 //correctly computes transaction

//then when I click no for new transaction buy/sell dialog pops up again among the others in the loop
//If I keep click no/cancel program finally end but all of the following is shown as output to console
Modest International is closed for the day. See you tomorrow!Error: null
Modest International is closed for the day. See you tomorrow!The method was called// even though it says displayResult() method is called it does not write to file

What is wrong when it executes: program is not ending when user selects no for new transaction and loop continues.

0

Error: null

Did you see this? You have a null variable causing an exception.

While you are debugging your code you should call the printStackTrace() method in your catch blocks to show the full text of the error messages.

0

The only way I debug my code is by looking at what I have written and moving stuff around. I do not know how to use the actual debugger. I've watched tutorial videos on the eclipse debugger but still do not fully understand it. I am not familiar with how to use the printStackTrace() method, I will google it.

0

By debugging I meant the time you spend getting your code to work. I was not referring to what tools you use.

You need to add the printStackTrace() call to the Exception's catch block to get the details on the error.

0

By debugging I meant the time you spend getting your code to work. I was not referring to what tools you use.

You need to add the printStackTrace() call to the Exception's catch block to get the details on the error.

Ok I think I called it right:

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){
				e.printStackTrace();// called here
				System.err.println("Error: " + e.getMessage());
			}

This is what printed to console then:

input currency: c
input amount: 1000.0
buy or sell: true
rate: 0.93 amount: 1000.0 buy true
price in dollars: 940.0
Modest International is closed for the day. See you tomorrow!java.lang.NullPointerException
	at CurrencyExchange.buyOrSell(CurrencyExchange.java:199)
	at CurrencyExchange.displayResult(CurrencyExchange.java:99)
	at CurrencyExchange.main(CurrencyExchange.java:33)
Error: null
Modest International is closed for the day. See you tomorrow!The method was called
0

These are the lines of code that the error message numbers correlate to:

Modest International is closed for the day. See you tomorrow!java.lang.NullPointerException
	at CurrencyExchange.buyOrSell(CurrencyExchange.java:199)
	at CurrencyExchange.displayResult(CurrencyExchange.java:99)
	at CurrencyExchange.main(CurrencyExchange.java:33)
Error: null
if(buyOrSell.equalsIgnoreCase("b")||buyOrSell.equalsIgnoreCase("buy"))// line :199
String output = ("Customer " + buyOrSell() + " " + inputAmount() + " " + inputCurrency() + " " 
					+ priceInDollars(rate, amount, buy) + " dollars" );// line: 99(also 100)
displayResult();//line: 33
0

Ok based off of the errors on the lines that were shown, I removed the if statement in the main method so it looks like this now:

while(newTransaction()==0){
			inputCurrency();
			inputAmount();
			buyOrSell();
			displayResult();
		}	
		/*if(newTransaction()==1){
			displayResult();
		}else{	
		}*/
		
	}

Now only the while loop remains, so if I complete the initial loop of user input and when asked if I want a new transaction and click no, the program ends correctly and no more error messages in the console. But it still does not write data to the file.

0

It won't write data to the file unless you call the method that does the writing.
Does your code call that method?

Did you find the variable with the null value?

0

This is the method that writes the file:

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){
				e.printStackTrace();
				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");
		
	}

And it is called in the main method here:

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));
		
		while(newTransaction()==0){
			
			inputCurrency();
			inputAmount();
			buyOrSell();
			displayResult();//called here in the while loop
		}
		
		/*if(newTransaction()==1){
			displayResult();
			
		}else{
			
		}*/
		
	}
0

It depends on the while() loop condition testing true.
What if the while() test is false? Then it is not called.

You are still using GLOBAL variables.
None of the methods you show in your last post return a value to a variable.

I thought you were going to remove the usage of GLOBAL variables and have the methods return values.

I suggest that you do that now. Get RID of your usage of GLOBAL variables.

Edited by NormR1: n/a

0

Ok I will do that now, then post my updated code reflecting the changes. The following explains how the main method is supposed to be ran.

Main Method Description:
calls displayResult();
calls readRates();
runs a while loop until newTransaction() returns YES;
in while loop displayResult() is called;
terminates the process.

0

Your description should be in terms of what is supposed to happen, not the names of methods.

Your list of the order of events does NOT make sense.
What results are there to display before anything else has been done.

0

Your description should be in terms of what is supposed to happen, not the names of methods.

Your list of the order of events does NOT make sense.
What results are there to display before anything else has been done.

That is what is also confusing to me, but that is exactly what the assignment says in it's given method description.

0

that is exactly what the assignment says

The assignment says that you are to call the named methods in the order that you listed them?

What results are there to display when the program starts?

0

I thought you were going to remove the usage of GLOBAL variables and have the methods return values.
I suggest that you do that now. Get RID of your usage of GLOBAL variables.

Ok I have removed the global variable being assigned and returned as values from the methods. Here is the code now:

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));
		
		while(newTransaction()==0){
			
			inputCurrency();
			inputAmount();
			buyOrSell();
			displayResult();
		}
		
		/*if(newTransaction()==1){
			displayResult();
			
		}else{
			
		}*/
		
	}

	public static Double priceInDollars(double rate, double amount, boolean buy){
		rate = composeReport();//assigns value to rate
		amount = inputAmount();//assigns value to amount
		buy = buyOrSell();//assign value to buy
		//but since these are the parameters, it is not being stored globally?

		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);
		double getRate = 0;// creates local variable
		switch (code){
		case 'C' : case 'c':
			if(buy){
				getRate = buyingRateC;
			}
			else{
				getRate = sellingRateC;
			}
			break;
		case 'M' : case 'm':
			if(buy){
				getRate = buyingRateM;
			}
			else{ 
				getRate = sellingRateM;
			}
			break;
		case 'E' : case 'e':
			if(buy){
				getRate = buyingRateE;
			}
			else{
				getRate= sellingRateE;
			}
			break;
		}
		
		return getRate;
	}

	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){
				e.printStackTrace();
				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);
		char getCode = 0;// creates local variable
		if(choice.equalsIgnoreCase("CD")||choice.equalsIgnoreCase("Canadian Dollar")||choice.equalsIgnoreCase("C")||choice.equalsIgnoreCase("CC"))
		{
			getCode= 'c';
		}else if(choice.equalsIgnoreCase("MP")||choice.equalsIgnoreCase("MM")||choice.equalsIgnoreCase("Mexican Peso")||choice.equalsIgnoreCase("M"))
		{
			getCode= 'm';
		}else if(choice.equalsIgnoreCase("EU")||choice.equalsIgnoreCase("EE")||choice.equalsIgnoreCase("Euro")||choice.equalsIgnoreCase("E"))
		{
			getCode = 'e';
		}else{
			JOptionPane.showMessageDialog(null,"Please enter correct currency code.", "Modest International",1);
			
			//newTransaction();
			/*while(newTransaction()==0){
				inputCurrency();
				inputAmount();
				buyOrSell();
				displayResult();
			}*/

		}
		
		composeReport();
		return getCode;
	}


	public static double inputAmount(){
		String inputAmount = JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest International", 
				JOptionPane.QUESTION_MESSAGE);
		double getAmt = 0;// creates local variable
		if(inputAmount == " "){
			JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest International", 
					JOptionPane.QUESTION_MESSAGE);
		} else {
			getAmt = Double.parseDouble(inputAmount);
		}
		return getAmt;

	}

	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);
		boolean getBuy = false;
		if(buyOrSell.equalsIgnoreCase("b")||buyOrSell.equalsIgnoreCase("buy"))
		{
			getBuy = true;
		}else if(buyOrSell.equalsIgnoreCase("s")||buyOrSell.equalsIgnoreCase("sell"))
		{
			getBuy = false;	
		}
		return getBuy;	
	}

	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;
		}
	}
}

Since I tried to change the values to local variable and pass them to the global variable no values are being passed.

0

no values are being passed

What does that mean?

In your code, none of the vales returned by these methods are stored into variables.

inputCurrency();
			inputAmount();
			buyOrSell();
			displayResult();

Edited by NormR1: n/a

0

How do I get a global variable to store values from a method that is returning a value?

0

Ok that is what I was attempting to do here, but since it was the parameters of the method is was not working:

rate = composeReport();//assigns value to rate
		amount = inputAmount();//assigns value to amount
		buy = buyOrSell();//assign value to buy
		//but since these are the parameters, it is not being stored globally?
0

I went back and looked at the doc file for your assignment.
I have a basic philosophical disagreement with the techniques that the assignment says you are to use. You are using the old procedural programming technique with global variables vs the newer object oriented approach with local variables and classes to hold and pass data.

Forget everything I have been saying if you want to please whoever gave you the assignment. They are not asking you to use object oriented programming techniques in this assignment.

0

I would rather just keep working how we have been, so progress will not have been lost.

0

You won't be able to satisfy the assignment as shown in the doc.
It clearly requires globals.

0

Shoot! lol. Do you have any suggestion? Should I change it back to the globals like I had it?

0

Reread your assignment doc. It defines all the variables as static which means that they are supposed to be global.

0

Ok here is my code much redone from what it was before. Many of the errors are out now:

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 String report = "";
	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();
		do{
			displayResult();
		}
		while(newTransaction()==JOptionPane.YES_OPTION);
		JOptionPane.showMessageDialog(null, "bye");
	}

	public static Double priceInDollars(double rate, double amount, boolean flag){
		
		double rateAmt = rate * amount;
		double baseCom = rateAmt * commissionPercent/100;
		double commission = Math.min(baseCom, 10);
		double dollarValue;
		if(flag){
			dollarValue = rateAmt += commission ;
		}else{
			dollarValue = rateAmt -= commission;
		}
		return dollarValue;
	}


	public static double composeReport(){
		
		code = inputCurrency();
		amount = inputAmount();
		buy = buyOrSell();
		switch (code){
		case 'C' : case 'c':
			if(buy){
				rate = buyingRateC;
				report = report + "buys " + df.format(amount) + " CD ";
			}
			else{
				rate = sellingRateC;
				report = report + "sells " + df.format(amount) + " CD ";
			}
			break;
		case 'M' : case 'm':
			if(buy){
				rate = buyingRateM;
				report = report + "buys " + df.format(amount) + " MP ";
			}
			else{ 
				rate= sellingRateM;
				report = report + "sells " + df.format(amount) + " MP ";
			}
			break;
		case 'E' : case 'e':
			if(buy){
				rate = buyingRateE;
				report = report + "buys " + df.format(amount) + " EU ";
			}
			else{
				rate= sellingRateE;
				report = report + "sells " + df.format(amount) + " EU ";
			}
			break;
		}
		return priceInDollars(rate, amount, buy);
	}

	public static void displayResult() throws IOException{
		double cost = composeReport();
		try{
			FileWriter fw = new FileWriter("dailyreport.txt", true);
			PrintWriter out = new PrintWriter(fw);
			String output = ("Customer " + report + " for "+ cost + " dollars.");
			JOptionPane.showMessageDialog(null, "Your charge for the transaction is:\n"
												+ cost + "\n"
												+ "We appreciate your business!");
			out.append(output);
			out.close();
			}catch(Exception e){
				e.printStackTrace();
				System.err.println("Error: " + e.getMessage());
			}
	}

	public static void readRates() throws IOException{
		File f = new File("dailyrates.txt");	
		Scanner y = new Scanner(f);
		@SuppressWarnings("unused")
		String com;
	
		while(y.hasNext()){
			com = y.next();
			commissionPercent= y.nextDouble();
			com = y.next();
			buyingRateC= y.nextDouble();
			com = y.next();
			sellingRateC=y.nextDouble();
			com = y.next();
			buyingRateM= y.nextDouble();
			com = y.next();
			sellingRateM=y.nextDouble();
			com = y.next();
			buyingRateE= y.nextDouble();
			com = y.next();
			sellingRateE=y.nextDouble();
		}	
		y.close();
	}

	public static char inputCurrency(){
		char c = 0;
		String choice = "";
		while(true){
			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 != null || choice != "")
				break;
		}
		if(choice.charAt(0) == 'c' || choice.charAt(0) == 'C'){
			c = 'c';
		}
		else if(choice.charAt(0) == 'e' || choice.charAt(0) == 'E'){
			c = 'e';
		}
		else if(choice.charAt(0) == 'm' || choice.charAt(0) == 'M'){
			c = 'm';
		}	
		return c;
	}
	public static double inputAmount(){
		String inputAmount = ""; 
		while(true){
			inputAmount = JOptionPane.showInputDialog(null, "Please Enter Amount", "Modest    International", JOptionPane.QUESTION_MESSAGE);
			if(inputAmount != null || inputAmount != "")
				break;
		}
		return Double.parseDouble(inputAmount);
	}

	public static boolean buyOrSell(){
		String buyOrSell = "";
		while(true){
		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 != null || buyOrSell != "")
				break;
		}
		if(buyOrSell.charAt(0) == 'b'){
			buy = true;
		}
		else if(buyOrSell.charAt(0) == 's'){
			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);
		return result;
	}
}

Edited by javaNooblet: n/a

0

Yes it's working minus one thing, trying to get that now and thinking of how to word it.

0

Your code structure is poor. It is very hard to understand what the code does because you hide important method calls inside of other methods.
The code in the main loop should call each of the required methods one after the other.
With your code structure, there is no way you could reuse any of the methods in another programming project. They are too tightly connected. Each method should do one thing and return a result (or set global variables). The name of the method should be a verb describing what the method does. Some of yours follow this rule, many don't.

Edited by NormR1: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.