mercredi 30 novembre 2016

Why is my If block not working?

I have to check that the input date remains in a limit 0

import java.util.Scanner;
class Car{

     }


class CarRental{

            }
public class RentalManager {
public static void main (String args[])
{   Scanner sc = new Scanner(System.in);
System.out.println("Choose a car\n1. Porshe\n2. Ferrari");
String choice = sc.nextLine();

System.out.println("Start Date");
int date;
date = sc.nextInt();
if(date<0&&date>31)
{
System.out.println("Enter proper Date");
date = sc.nextInt();
}
System.out.println("Month");
int month = sc.nextInt();
if(month<0&&month>12)
{
System.out.println("Enter proper Month");
month = sc.nextInt();
}

System.out.println("Year");
int year = sc.nextInt();

System.out.println("Daily Rate");
int rate = sc.nextInt();
System.out.println("No of days for which you want to rent?");
int days = sc.nextInt();

System.out.println("You have entered the following information");

System.out.println("Daily Rate : "+rate+"\nRenting for : "+days+" days");
System.out.println("\nYour Bill will be : " + days*rate);





}
}

this is the output i am getting note : i have removed one print statement from the code so don't worry about the extra line in the output image. the two classes are empty right now, i intend to change that but first i need to get the date and month checking process right.

Aucun commentaire:

Enregistrer un commentaire