Javculator v0.1 by 1337snak3

Discussion in 'Programming General' started by 1337Snak3, Feb 12, 2007.

Javculator v0.1 by 1337snak3
  1. Unread #1 - Feb 12, 2007 at 1:56 AM
  2. 1337Snak3
    Referrals:
    0

    1337Snak3 Guest

    Javculator v0.1 by 1337snak3

    okay, if you dont know what this is, it's calculator.
    If u've done anything in java u can use this.
    I hope u get along with my english in the program...

    Code:
    import java.util.Scanner;
    // sythe.org 1337Snak3
    public class Javculator {
    	public static void main(String[] args) throws Exception {
    		Scanner skanneri = new Scanner(System.in);
    
    		System.out.println("please,type the first number(s) example 53 or 8 or anything like that,press enter");
    		int a = skanneri.nextInt();
    		System.out.println("Now, the second number(s),press Enter");
    		int b = skanneri.nextInt();
    		System.out.println("Now,type what you wanna do about the numbers you earlier gave, 1 for plus 2 for minus 3 for times or what do they ever call it and 4 for the example 28/7 = 4 things ");
    		int c = skanneri.nextInt();
    		double x = a;
    		double y = b;
    		int res1 = a+b;
    		int res2 = a-b;
    		int res3 = a*b;
    		double res4 = x/y;
    
    		while (c != 0) {
    			switch (c) {
    				case 1:
    				System.out.println(a + " plus "+ b +" is :"+ res1);
    				break;
    				case 2:
    				System.out.println(a + " minus "+ b +" is :"+ res2);
    				break;
    				case 3:
    				System.out.println(a + " times "+ b +" is :"+ res3);
    				break;
    				case 4:
    				System.out.println(a + " shared "+ b +" is :"+ res4);
    				break;
    				default:
    				System.out.println(" Are you sure you gave a number 1-4 when asking what you want to do?");
    			}
    			System.out.println("now, you can change the way to calculate if you wish to.");
    			c = skanneri.nextInt();
    		}
    	}
    }
    
    
    
    
     
  3. Unread #2 - Feb 12, 2007 at 4:03 PM
  4. bkatz
    Joined:
    Apr 21, 2005
    Posts:
    402
    Referrals:
    0
    Sythe Gold:
    0

    bkatz Forum Addict
    Banned

    Javculator v0.1 by 1337snak3

    Nice program - just thought i'd tell you there's an easier way to get user input using JOptionPane.

    Read about showInputDialog in the java api. :)
     
  5. Unread #3 - Feb 14, 2007 at 7:56 AM
  6. 1337Snak3
    Referrals:
    0

    1337Snak3 Guest

    Javculator v0.1 by 1337snak3

    thx again , u seem to know ur business.
     
  7. Unread #4 - Feb 18, 2007 at 7:36 PM
  8. leon64
    Joined:
    Apr 28, 2006
    Posts:
    610
    Referrals:
    1
    Sythe Gold:
    0

    leon64 Forum Addict
    Banned

    Javculator v0.1 by 1337snak3

    Thanks Im gonna use this program 4ever :)
     
  9. Unread #5 - Feb 26, 2007 at 3:28 AM
  10. pyro 214
    Joined:
    Apr 23, 2006
    Posts:
    334
    Referrals:
    2
    Sythe Gold:
    0

    pyro 214 Forum Addict
    Banned

    Javculator v0.1 by 1337snak3

    why instantiate x to a when u already have a?
    why not just instantiate "a" as a double and forget about x. Not wrong, just a question of mine.
     
  11. Unread #6 - Feb 27, 2007 at 6:53 AM
  12. 1337Snak3
    Referrals:
    0

    1337Snak3 Guest

    Javculator v0.1 by 1337snak3

    Well, i thought that it's there just incase... maybe not needed...
     
  13. Unread #7 - Feb 27, 2007 at 7:46 PM
  14. pyro 214
    Joined:
    Apr 23, 2006
    Posts:
    334
    Referrals:
    2
    Sythe Gold:
    0

    pyro 214 Forum Addict
    Banned

    Javculator v0.1 by 1337snak3

    System.out.println("please,type the first number(s) example 53
    + or anything like that,press enter ");
    int a = skanneri.nextInt();
    System.out.println("Now, the second number(s),press Enter");
    int b = skanneri.nextInt();
    double x = a;
    double y = b;

    if you instantiate a as a int, whats the point of converting it to a double if its value wont have any decimal places anyways? Wouldn't it avoid a lot of trouble to initially instantiate a as a double? Maybe he didn't know that theres a "skanneri.nextDouble()" ?

    (no offence to what you wrote...im just trying to learn more about the language itself still)
     
  15. Unread #8 - Feb 28, 2007 at 4:05 PM
  16. aut0er
    Joined:
    Apr 28, 2005
    Posts:
    131
    Referrals:
    0
    Sythe Gold:
    0

    aut0er Active Member

    Javculator v0.1 by 1337snak3

    good for a starter ... try making it better by using GUI and stuff , i dont feel like looking thru all my files right now, but earlier i made a GUI calc thats alot better then the one that comes with windows =\

    --Aut0er
    Edit:
    i would also make it alot more user friendly
    Code:
    System.out.println("ENTER EQUATION");
    String something = scanner.in;
    String[] r = something.split(" ");
    int firstnum = r[0];
    int secondnum  = r[2];
    String todo = r[1];
    switch todo...
    case "+"
    add
    case "-"
    subtract
    case "x"
    multiply
    case"/"
    divide
    that code is obviously not complete but it will let the user enter stuff such as "5 + 5"
     
  17. Unread #9 - Mar 13, 2007 at 9:28 PM
  18. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    Javculator v0.1 by 1337snak3

    Wait so we take that code (edit it a bit) post it in TextPad and then save as .java or what.... Sry for noobie question new to JAVA =\
     
  19. Unread #10 - Mar 13, 2007 at 9:51 PM
  20. pyro 214
    Joined:
    Apr 23, 2006
    Posts:
    334
    Referrals:
    2
    Sythe Gold:
    0

    pyro 214 Forum Addict
    Banned

    Javculator v0.1 by 1337snak3

    yep, i suggest downloading "BlueJ"
    download, select "start new project" and ull be set from there...its like using hightech notepad with java grammar check.
     
  21. Unread #11 - Mar 15, 2007 at 1:58 AM
  22. Kossity
    Referrals:
    0

    Kossity Guest

    Javculator v0.1 by 1337snak3

    Thanks, I'll be needing this code as a reference once I start on my own calculator.
     
  23. Unread #12 - May 6, 2007 at 8:07 AM
  24. im the pjer
    Joined:
    Apr 29, 2007
    Posts:
    175
    Referrals:
    0
    Sythe Gold:
    0

    im the pjer Active Member
    Banned

    Javculator v0.1 by 1337snak3

    crapp!
     
  25. Unread #13 - May 6, 2007 at 8:07 AM
  26. im the pjer
    Joined:
    Apr 29, 2007
    Posts:
    175
    Referrals:
    0
    Sythe Gold:
    0

    im the pjer Active Member
    Banned

    Javculator v0.1 by 1337snak3

    more crapp!
     
< Redemptions Java Guide #1- Basics Using ObjectDraw! | C++ Introduction >

Users viewing this thread
1 guest


 
 
Adblock breaks this site