lundi 20 novembre 2017

Java. Output errors

package assignmentone;

import java.util.Scanner;

public class AssignmentOne {

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

        System.out.println("Welcome to the University Credit Checker");
        System.out.println("Enter Pass Credits");

        if (in.hasNextInt()) {
            int passCredits = in.nextInt(); //Correct

            if (passCredits != 0 || passCredits != 20 || passCredits != 40
                    || passCredits != 60 || passCredits != 80 || passCredits != 100 || passCredits != 120)
            {
                System.out.println("Error: Enter Valid Input Type: 0, 20, 40, 60, 80, 100 or 120");
            } // Correct

            else if (passCredits == 0 || passCredits == 20 || passCredits == 40 || passCredits == 60
                    || passCredits == 80 || passCredits == 100)
            {
                System.out.println("Enter Defer Credits");
            }
           // Get rid of output Error: Enter Valid Input Type: 0, 20, 40, 60, 80, 100 or 120

            else if (passCredits == 120){
                System.out.println("Progress");
            }
            // Get rid of output Error: Enter Valid Input Type: 0, 20, 40, 60, 80, 100 or 120

        } else {
            System.out.println("Error: Enter Valid Input Type: Integer");
        } //Correct

    }
}

Hello all.

I am new to Java and am trying to create a program that uses user input, alongside user validation. I have created the first part.

For this part I have a user validation to make sure they enter an integer type. Which is working correctly

After this, I have a user validation to make sure they enter 0, 20, 40, 60, 80, 100 and 120. This will come up with an error. This too also works correctly.

What is not working correctly is when they enter a number that is 0, 20, 40, 60, 80 or 100, I wish for a simple output of "Enter Defer Credits" to display. With this, I want it when the user enters 120 a simple output of "Progress" displays.

With both parts, "Error: Enter Valid Input Type: 0, 20, 40, 60, 80, 100 or 120" displays instead of the intended "Enter Defer Credits" or "Progress".

Looking at my code above, I was wondering why this would be? As at the moment I am completely stuck to why this is the case.

Thanks in advance. :)

Aucun commentaire:

Enregistrer un commentaire