lundi 14 novembre 2016

Skip inputs using if

I’m trying to create a program that skips inputs if they are not necessary, to do this I have tried to use if statements, but when I run the program it skips the question "Please input the ..." but still requires an input. Is there other way to do this.

P.S. I am new at java

Here is my code

 import java.util.*;

class TunnelTollChargeUser {

    // ------------------- FIELDS ------------------------    

    // Create instance of Scanner class

    private static Scanner input = new Scanner(System.in);



    // ------------------ METHODS ------------------------  

    public static void main(String[] args) {

    // Input Number of wheels

        System.out.print("Please input the number of wheels --> ");
        double InWheels = input.nextDouble(); 


    // Input length
        if (InWheels>=4)    
        System.out.print("Please input the length of the vehicle in feet --> ");
        double InLength = input.nextDouble(); 



    // Input number of axles
        if (InLength>15)    
        System.out.print("Please input the number of axles --> ");
        double InAxles = input.nextDouble(); 


    // Input weight of the vehicle
        if (axels>2)    
        System.out.print("Please input the weight of the vehicle in metric tons --> ");
        double InWeight = input.nextDouble(); 

    // Input day true(weekday) false (weekend)

        System.out.print("Please input true if travelling on a weekday (Mon-Fri) and false otherwise --> ");
    String InDay = input.next();    



    // Create new TunnelTollCharge instance

    TunnelTollCharge newTunnelTollCharge = new TunnelTollCharge(InWheels, InLength, InAxles, InWeight, InDay );

    // Output vehicle class, vehicle type and calculate vehicle cost

    newTunnelTollCharge.VehicleClass();
    newTunnelTollCharge.VehicleType();

    // Output result

    System.out.println(newTunnelTollCharge);
    }
    }

Aucun commentaire:

Enregistrer un commentaire