2 Replies - 127 Views - Last Post: 07 August 2012 - 01:53 AM Rate Topic: -----

#1 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 29-December 11

OOP is freakin hars..

Posted 06 August 2012 - 02:13 PM

Okay, so I'm working on a Calculator using more OOP than my last Calculator.


This is what i got so far:


Main.java
ackage rpg;


public class Main {
    public static void main(String args[]){
     
      Operators choice;
      choice = new Operators();
      
      Welcome choice2;
      choice2 = new Welcome();
     
      choice2.intro();
      
       
       
        
        
  
            
    }
}




I'll not try to program in here, only to include other classes and methods.

Operators.java

package rpg;

public class Operators {
    
    void addition(){
        
    }
    void substraction(){
        
    }
    void divide(){
        
    }
    void multiply(){
        
    }
}



Here will all of the operators be stored.


Welcome.Java
package rpg;
import java.util.Scanner;


public class Welcome {
    
    void intro(){
        Scanner input = new Scanner (System.in);
        System.out.print("Welcome to Calc 2.0");
        System.out.println("This is the main menu");
        System.out.println("1. Addition");
        System.out.println("2. Substraction");
        System.out.println("3. Divide");
        System.out.println("4. Multiply");
        int input2 = input.nextInt();
        
        
    }
    
    
}



Here you'll get question about how you want to do your math.


I'm still looking for a solution on what i should do now with the input and variables that stores the user input. Anyone got some idea?

Is This A Good Question/Topic? 0
  • +

Replies To: OOP is freakin hars..

#2 Ryano121  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1055
  • Posts: 2,234
  • Joined: 30-January 11

Re: OOP is freakin hars..

Posted 06 August 2012 - 02:18 PM

Glad to see you are trying some more OOP than last time :)

What you really need to do is start returning values from your methods (instead of void all over the place).

For example at the moment you intro method should return the integer choice which would then be passed into another method that decides what method in the Operators class to call.

Again you need to return values in the Operators class, not just void. You also should pass in the parameters to the operation to the method from the user input - e.g

int add(int a, int B)/> {
   return a + b;
}


Hopefully that gives you a few pointers.
Was This Post Helpful? 3
  • +
  • -

#3 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 29-December 11

Re: OOP is freakin hars..

Posted 07 August 2012 - 01:53 AM

View PostRyano121, on 06 August 2012 - 02:18 PM, said:

Glad to see you are trying some more OOP than last time :)

What you really need to do is start returning values from your methods (instead of void all over the place).

For example at the moment you intro method should return the integer choice which would then be passed into another method that decides what method in the Operators class to call.

Again you need to return values in the Operators class, not just void. You also should pass in the parameters to the operation to the method from the user input - e.g

int add(int a, int B)/> {
   return a + b;
}


Hopefully that gives you a few pointers.



Yeah I know that i should use something like that. Only thing is that i have not learned that by far as good with other things. But It's coming ! ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1