Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple java application

  • 01-03-2004 9:24pm
    #1
    Closed Accounts Posts: 38


    Any one want to try their hand at this?

    Create a console based app (runs through the command prompt) called Abacus.
    This will just have a main() Method.
    Create a class called Calculator.
    This will have 4 methods called Add() Multiply () Divide() Subtract().
    These methods will take two integer values as parameters and return an integer value.
    Instantiate the Calculate class and execute the 4 methods using default values "2" and "4" and print out the results to the screen.


Comments

  • Registered Users, Registered Users 2 Posts: 5,335 ✭✭✭Cake Fiend


    I don't even know Java and I reckon I could have a decent stab at this.
    Make some effort.


  • Closed Accounts Posts: 302 ✭✭Auburn


    Do your own homework or at least show what you've tried. It isn't hard even if you are a complete beginner


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Jeezus you could at least try and dress up the question so that it doesn't look too much like homework.
    Kids these days.... pah!


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Not sure it if compiles. Might need 'tweaking' but your instructor will love it.
    Class Abacus {
    	int i1 = 0, i2 = 2;
    	public static void main(String[] args) {
    		calculator[] s[] = new calculator[i1][i2];
    		if ( i1 > i2) {
    			main(s[0][0]);
    		} else if ( i2 < i1) {
    			main(s[0][1]);
    		} else 	main(s[0][0]);
    	}
    	void main(calculator c) {
    		c.main();
    	}
    }
    Class Calculator extends calculator {
    	public int i1 = 0 , i2 = i1.clone();
    	
    	void main() {
    		Class calculator = Calculator.class;
    		Calculator c = new (Calculator) Calculator();
    		System.out.println("Add:" + Add(2,4));
    		System.out.println("Multiply:" + Multiply(2,4));
    		System.out.println("Subtract:" + Subtract(2,4));
    		System.out.println("Divide:" + Subtract(4,2));
    	}
    
    	static String Add(int i1, int i2) {
    		do { 
    			return "0";
    		} while (i1 < i2);
    	}
    
    	static String Multiply(int i1, int i2) {
    		return (Add(i1,i2) == add(i1,i2)) ? Add(i1,i2) : add(i1,i2);
    	}
    	
    	static String add(int i2, int i1) {
    		Subtract(i2,i1);
    	}
    
    	static int Divide(int i1, int i2) {
    		try {
    			return this.i1 / this.i2;
    		} catch (Exception e) {
    			return 0
    		}
    	}
    	static String Subtract(int i1, int i2) {
    		return (i1 == i2) ? this.i2 - this.i1 : i1 - i2;
            }
    }
    Class calculator {
    	void main() {
    	}
    }
    


  • Moderators, Society & Culture Moderators Posts: 2,688 Mod ✭✭✭✭Morpheus


    I think people should be banned from doing others college work.

    When i was in college, at least we bothered to search for the code on the internet!!

    Lazy feckers.


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Good one Hobbes :)


  • Registered Users, Registered Users 2 Posts: 841 ✭✭✭Dr Pepper


    Yeh, nicely done..


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    Hey Hobbes just wondering a few things:

    1. Why did you put a try catch block in the divide method? Any reason or just for the laugh?

    2. Whats with the 2 calculator classes, well Calculator and calculator?

    Also, I dont think its very nice of the thread starter to go asking people to do their college work for them, especially when its so damn simple


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    1) Ever try to divide by zero in Java?

    2) I'm guessing here, but I'd say just cause :)


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Don't be such a lazy twat. Closed.


  • Advertisement
This discussion has been closed.
Advertisement