Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your main class you have:</p> <pre><code>Rational r1 = new Rational ( rationalNum1, rationalDen1); Rational r2 = new Rational ( rationalNum2, rationalDen2); </code></pre> <p>you are passing 2 integers to a constructer that recives void, so you have to change your constructer (of Rational class) like this:</p> <pre><code> public Rational(int rationalNumber, int rationalDen){ Numerator = rationalNumber; Denominator = rationalDen; } </code></pre> <p>Hope it helps, let me know if it worked or if there is more something wrong...</p> <p>Edit: your Scanner and print error. You have this:</p> <pre><code>public void question() { System.out.println("Do you want to exit? [y/n]"); // ask user if they want to quit with yes or no option Scanner q = new Scanner(System.in); switch (q.nextInt()) // here you are assuming that you are reading a int in step { // of a string case 'y' : // ' ' arent used for strings... System.out.println ("Thank you and goodbye."); break; case 'n' : InputMenu(); break; default: System.err.println ( "Unrecognized option" ); break; } } </code></pre> <p>so, what you need is:</p> <pre><code> public void question() { System.out.println("Do you want to exit? [y/n]"); // ask user if they want to quit with yes or no option Scanner q = new Scanner(System.in); switch (q.nextLine()) // change nextInt to nextLine, that is the string method { // of a string case "y" : //change ' ' to " " System.out.println ("Thank you and goodbye."); break; case "n" : //change ' ' to " " InputMenu(); break; default: System.err.println ( "Unrecognized option" ); break; } } </code></pre> <p>Hope it help :)</p> <p>Edit 3:</p> <p>in your code you have: ` public class RationalDriver{ public static void main(String[] args){</p> <pre><code> int rationalNum1, rationalDen1, rationalNum2, rationalDen2; // this are local variables, they only exist inside main method ...` } </code></pre> <p>So, what you can do is:</p> <pre><code> public class RationalDriver{ private static int rationalNum1, rationalDen1, rationalNum2, rationalDen2; public static void main(String[] args){ // your main } </code></pre> <p>what i did was take your local variables that <strong>only exists</strong> in your main and turn them in global variables so when you want change their value or give them a value you just do:</p> <pre><code>rationalNum1 = your valor; </code></pre> <p>Please note that if you use any variable without initialize it with a value you will get a null point exception...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload