Results 1 to 7 of 7
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Check this code over, and tell me if it's alright or not!

    hey guys i am really just a beginner, but im practicing.
    i tought i should make a program that can convert dollars to euros, or euros to dollars. later on i can improve it so you can enter how many euro/dollars you want to convert etc.
    but is this alright?

    thanks in advance.

    Java Code:
    import java.util.Scanner;
    
    class Eurodollar {
    	public static void main(String args []){
    		Scanner input = new Scanner (System.in);
    		System.out.println("euro > dollar \t or dollar > euro?");
    		String eurodollar = input.nextLine();
    		switch(eurodollar){
    		case "euro > dollar":
    		System.out.println("You chose for: Euro > Dollar ");	
    		System.out.println("\n");
    		System.out.println("Euro"+"\t"+"Dollar");{
    			for(int euro1=1;euro1<=10;euro1++)
    		System.out.println(euro1+ "\t" +euro1 * 0.767636447);
    		}
    		case "dollar > euro":
    			System.out.println("You chose for: Dollar > Euro ");	
    			System.out.println("\n");
    			System.out.println("Dollar"+"\t"+"Euro");{
    				for(int euro1=1;euro1<=10;euro1++)
    			System.out.println(euro1+ "\t" +euro1 / 0.767636447);
    			
    			
    		
    			
    	
    		
    		}
    		}
    	}
    }

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Check this code over, and tell me if it's alright or not!

    If you are asking if there are syntax errors, then it's alright.

    But it is really not a good approach because when you expect a user to type that exact string it is a disaster. For now, better use 0 and 1 and check the integers in a loop
    Also, in the first case add a break; before it ends

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: Check this code over, and tell me if it's alright or not!

    Quote Originally Posted by superhaNds View Post
    If you are asking if there are syntax errors, then it's alright.

    But it is really not a good approach because when you expect a user to type that exact string it is a disaster. For now, better use 0 and 1 and check the integers in a loop
    Also, in the first case add a break; before it ends
    About which string are you talking if i may ask?

    And yes as i already said: im a beginner and im just doing this to practice. I will still improve it so users can enter is more easily

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: Check this code over, and tell me if it's alright or not!

    Quote Originally Posted by superhaNds View Post
    If you are asking if there are syntax errors, then it's alright.

    But it is really not a good approach because when you expect a user to type that exact string it is a disaster. For now, better use 0 and 1 and check the integers in a loop
    Also, in the first case add a break; before it ends
    Oh never mind, figured it out already

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Check this code over, and tell me if it's alright or not!

    The first question should be "does it work"?
    Because I suspect if you enter "euro > dollar" you are not going to get the output you expect.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: Check this code over, and tell me if it's alright or not!

    Why no generalize stuff a bit and make it able to convert from whatever unit A to unit B. A Simple interface and an enum defines most of it:

    Java Code:
    public enum UNIT { dollar, euro, celcius, fahrenheit ... };
    public interface Converter {
       boolean canConvert(UNIT A, UNIT B);
       double convert(UNIT A, UNIT B, double x);
    }
    The first method returns true if the Converter can convert from A --> B or vice versa and the second method does the conversion. Most units have a linear dependency, i.e. B == aA+b and A == (B-b)/a so an abstract superclass that implements the above interface can do most of the job. You can even populate (most of) your converters with a simple text file, so you can even make something usefiull out of this ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: Check this code over, and tell me if it's alright or not!

    guys how can i make this so that it just takes the current wealth of the dollar off a website?

    thanks in advance

Similar Threads

  1. Replies: 4
    Last Post: 05-02-2012, 10:07 AM
  2. code to refresh and check the code of a webpage..
    By vaggelis in forum New To Java
    Replies: 5
    Last Post: 02-07-2012, 02:21 PM
  3. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 04:21 AM
  4. Could you please check my code?
    By Cylab in forum New To Java
    Replies: 2
    Last Post: 08-11-2010, 12:13 PM
  5. Replies: 0
    Last Post: 01-28-2010, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •