Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Every parameter in a method definition needs a type:</p> <pre><code>public static int validNumCheck(int num1, int num2, int num3){ </code></pre> <p>but I wonder why you pass all three numbers in, when you only check one at the time. And you want to return if the number is true or not, so the return value should be an boolean: </p> <pre><code>public static boolean validNumCheck(int num){ // test and return true or false </code></pre> <p>Also, if the user enters "abc", you will get an exception from the "Intger.pareInt(String)" method. Maybe you want to store the entered text as a String an give it to validNumCheck, try to convert it and check if it is between 0 and 200.</p> <pre><code>public static boolean isValidNumber(String num){ try { int number = Integer.parseInt(num); return number &gt;= 0 &amp;&amp; number &lt;= 200; }catch(NumberFormatException e){ return false; } } </code></pre> <p><strong>EDIT 1:</strong> For the three tries, you need a loop, that runs till the number is valid or three tries are taken. Simply count the tries with in int.</p> <p>By the way, are you sure you have to use JOptionPane and JMessageDialog? This is GUI stuff and just complicates that hole thing. You also could read and write text to the console by using System.out and System.in</p> <p><strong>EDIT 2:</strong> One more tip, when you create an int array with a given length, every place in the array is filled with 0, so you could write:</p> <pre><code>int[] count= new int [3]; </code></pre> <p>and don't need that:</p> <pre><code>count[0]=0; count[1]=0; count[2]=0; </code></pre> <p>And if you want to use other values than 0, you could use a shorter form like this:</p> <pre><code>int[] count = {1, 5, 2} </code></pre> <p><strong>EDIT 3:</strong> One thing you should do/learn is this: don't write the whole thing and end up with many errors and a not running program. <strong>Code a little, test a little</strong>. Do one part of it, see it run and you are happy.</p> <p>Did this thing ever run? I mean, did you already saw that JOptionPane-InputDialog you try to use? If not, do only this first: (and run it!)</p> <pre><code>public class Assignment3 { public static void main (String[] args){ int[] numbers = new int[3]; for (int i = 0; i &lt; numbers.length; i++) { JOptionPane.showInputDialog("enter something"); } } } </code></pre> <p>Got it to run? Great! Now, try to wrap that line with the JOptionPane in a loop, that runs till the user entered a valid number (using the checkValidNum method you already got) or used his three attempts.</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. 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