I Have A Class And Method Problems....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimgym1989
    New Member
    • Sep 2008
    • 30

    I Have A Class And Method Problems....

    /*MY CONSOLE DOES NOT EXECUTE EVERY TIME I RUN MY PROGRAM
    WHAT HAPPEN? WHERE DID I GO WRONG? BUT THE PROCESS IS COMPLETED...I AM NEW IN JAVA PROGRAM AND THIS IS OUR NEW LESSON IN CLASS*/
    [code=java]
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class FRACTIONagain {

    static Scanner console = new Scanner(System. in);
    public static void main(String[]args) {

    FRACTIONclass oldFraction = new FRACTIONclass() ;



    int num1 = 0,denom1 = 0;
    int num2=0,denom2=0 ;
    String operator=" ",slash=" ";

    System.out.prin tln("Enter two fractions followed by a space");
    num1 = console.nextInt ();
    slash = console.next();
    denom1 = console.nextInt ();
    num2 = console.nextInt ();
    slash = console.next();
    denom2 = console.nextInt ();
    System.out.prin tln();

    oldFraction.get Num(num1, denom1, operator, num2, denom2);

    }
    }[/code]
    //THIS IS MY MAIN
    ----------------------------------------------------------------------------------------------------------
    [code=java]public class FRACTIONclass {

    public FRACTIONclass()
    {
    getNum(0,0," ",0,0);
    }
    public void getNum(int num1,int denom1,String operator,int num2, int denom2)
    {
    if(operator == "+")
    addNum(num1,den om1,num2,denom2 );

    if(operator == "-")
    subNum(num1,den om1,num2,denom2 );

    if(operator == "*")
    mulNum(num1,den om1,num2,denom2 );

    if(operator == "/")
    divNum(num1,den om1,num2,denom2 );

    else
    System.exit(0);
    }

    public static void addNum(int w,int x, int y, int z)
    {
    int numerator= 0,denominator= 0;
    numerator = (w*z)+(x*y);
    denominator = x*z;
    System.out.prin tln("Answer: "+numerator +"/"+" "+denominat or);

    }
    public static void subNum(int w,int x, int y, int z)
    {
    int numerator= 0,denominator= 0;
    numerator = (w*z)-(x*y);
    denominator = x*z;

    System.out.prin tln("Answer: "+numerator +"/"+""+denominato r);
    }

    public static void mulNum(int w,int x, int y, int z)
    {
    int numerator= 0,denominator= 0;
    numerator = w*y;
    denominator = x*z;
    System.out.prin tln("Answer: "+numerator +"/"+""+denominato r);
    }

    public static void divNum(int w,int x, int y, int z)
    {
    int numerator= 0,denominator= 0;
    numerator = w*z;
    denominator = x*y;
    System.out.prin tln("Answer: "+numerator +"/"+""+denominato r);

    }

    }[/code]
    //THIS IS MY CLASS
    Last edited by Nepomuk; Sep 9 '08, 11:24 AM. Reason: Please use [code] tags
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi jimgym1989! Welcome to bytes.com!

    It's great to have you here!

    When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags. (I've added them for you this time, please use them yourself in future.)

    In this post, you have used capital letters in everything you wrote apart from the code. This is against our rules, as the use of capitals is generally considered to be shouting and therefore rather rude. So please, even if you're angry at your code or your computer or whatever, do not use capitals in that way.

    About your question, how do you "run your program"? Are you using an IDE (e.g. Eclipse, Netbeans, ...) or did you write your code in an editor (e.g. Notepad)? Your code is probably correct (as you say it does what it should), but the way you call it may not be.

    Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

    Greetings,
    Nepomuk (Moderator)

    Comment

    • jimgym1989
      New Member
      • Sep 2008
      • 30

      #3
      Originally posted by Nepomuk
      Hi jimgym1989! Welcome to bytes.com!

      It's great to have you here!

      When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags. (I've added them for you this time, please use them yourself in future.)

      In this post, you have used capital letters in everything you wrote apart from the code. This is against our rules, as the use of capitals is generally considered to be shouting and therefore rather rude. So please, even if you're angry at your code or your computer or whatever, do not use capitals in that way.

      About your question, how do you "run your program"? Are you using an IDE (e.g. Eclipse, Netbeans, ...) or did you write your code in an editor (e.g. Notepad)? Your code is probably correct (as you say it does what it should), but the way you call it may not be.

      Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

      Greetings,
      Nepomuk (Moderator)
      Hi Nepomuk!! thank you for your immediate response..im very sorry..i haven't read the post guidelines...an yways it wasn't my intention to be mad on something, i just make it capital so that you'll be able to see my questions properly..heheh e..im using JCreator..I just copy paste my code on this textfield..how do i properly call the method or a class..

      by the way I'm a Happy Person

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by jimgym1989
        Hi Nepomuk!! thank you for your immediate response..im very sorry..i haven't read the post guidelines...
        No problem, as long as you've read them now. ^^
        Originally posted by jimgym1989
        anyways it wasn't my intention to be mad on something, i just make it capital so that you'll be able to see my questions properly..heheh e..
        Well, that's what the [CODE]...[/CODE] tags are for.
        Originally posted by jimgym1989
        im using JCreator..I just copy paste my code on this textfield..how do i properly call the method or a class..
        JCreator should have some kind of "run" button and some kind of console. If you run a very simple class like this:
        Code:
        public class HelloWorld {
           public static void main(String[] args) {
              System.out.println("Hello World");
              System.in.read(); // This is just to make sure, that the console window doesn't close immediately
           }
        }
        then the output "Hello World" must be printed somewhere. That place is a replacement for the command window. You can however start your class from a "proper" console too - open one (in Windows: Start -> Run -> "cmd" -> Enter -> cd /d "path/to/my/project") and then start your program with java -cp yourClasspath youClass
        Originally posted by jimgym1989
        by the way I'm a Happy Person
        Glad to hear that. Happy people are especially welcome here! :-D

        Greetings,
        Nepomuk

        Comment

        Working...