Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
example java program for currency convertor in simple method using functions


What I have tried:

import java.util.Scanner;
class coin{
	public  void 
		coin obj=new coin();
		Scanner sc=new Scanner(System.in);
		System.out.println("Welcome to currency convertor");
		System.out.println("enter your amount");
		int num=sc.nextInt();
		System.out.println("1 for canadian dollar to Indian rupees");
		System.out.println("2 for American dollar to Indian rupees"); 
		int choice=sc.nextInt();
		switch(choice){
			case 1:{
				obj.iscanadiandollartoIndianrupees(num);
				break;
			}
			case 2:{
				obj.isAmericandollartoIndianrupees(num);
				break;
			}
			
		}
	}
	public void iscanadiandollartoIndianrupees(int num){
		
		
		Scanner amt=new Scanner(System.in);
		int coverting=0;
		int num1=amt.nextInt;
		double canadian=62.74;
		double converting=num1*canadian;
		System.out.println(converting);
		
	}
	void isamericandollartoIndianrupees(int num){
		
		
		Scanner dol=new Scanner(System.in);
		int covert=0;
		int dol=amt.nextInt;
		double canadian=83.17;
		double converting=dol*convert;
		System.out.println(converting);
		
	}

}
Posted
Updated 19-Jan-24 5:44am
Comments
CHill60 19-Jan-24 11:44am    
You've forgotten to ask a question
OriginalGriff 19-Jan-24 12:06pm    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are having problems with.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Richard MacCutchan 19-Jan-24 12:30pm    
Lots of simple errors which you can easily correct by reading the code. You are also missing a main method, so I doubt this will even compile.
[no name] 19-Jan-24 12:50pm    
You should be using "codes" / dictionaries for context; not combining currency "names" with function names. How do support 100+ currencies and country codes?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900