Computer Science, asked by AngshumanRoy, 1 year ago

write a java program which keeps on accepting fares from passengers based on the criteria:
age fare
<5. nil
>=5 but <18. rs10/>=18 but <60. rs20
>60. rs15
find the following:
1) number of passengers of each category.
2) total fare collected.

The program continues until the user enters the age zero.

please it's urgent please?


nitish8089: can you demonstrate your question more
nitish8089: i want to know you want two types of input age and fare it's clear.
nitish8089: but what does mean by string args not by array you want to say about command line args or anything else
AngshumanRoy: please show me how to do

Answers

Answered by nitish8089
3
code...

import java.util.Scanner;
class Fare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int age;
int child_passenger=0;
int young_passenger=0;
int adult_passenger=0;
int old_passenger=0;
int child_passenger_fare=0;
int young_passenger_fare=0;
int adult_passenger_fare=0;
int old_passenger_fare=0;
System.out.println("enter the age of passenger: ");
while((age=sc.nextInt())>0)
{ System.out.println("enter the age of passenger: ");
if(age<5){
child_passenger++;
}
if(age>=5&&age<18){
young_passenger++;
young_passenger_fare=young_passenger*10;
}
if(age>=18&&age<60){
adult_passenger++;
adult_passenger_fare=adult_passenger*20;
}
if(age>=60){
old_passenger++;
old_passenger_fare=old_passenger*15;
}
}
System.out.println(".........Display the Data........");
System.out.println("No. of child_passenger: "+child_passenger);
System.out.println("No. of young_passenger: "+young_passenger);
System.out.println("No. of adult_passenger: "+adult_passenger);
System.out.println("No. of old_passenger: "+old_passenger);
System.out.println("Total No. of passenger: "+(child_passenger+young_passenger+adult_passenger+old_passenger) );
System.out.println("fare collected through child_passenger: Rs."+child_passenger_fare);
System.out.println("fare collected through young_passenger: Rs."+young_passenger_fare);
System.out.println("fare collected through adult_passenger: Rs."+adult_passenger_fare);
System.out.println("fare collected through old_passenger: Rs."+old_passenger_fare);
System.out.println("Total fare collected: Rs."+(child_passenger_fare+adult_passenger_fare+old_passenger_fare+young_passenger_fare));
}
}

AngshumanRoy: thank you very much
AngshumanRoy: great bro
nitish8089: welcome
Similar questions