Computer Science, asked by mahima4290, 3 months ago

answer this question (java program) please​

Attachments:

Answers

Answered by adityapramila2007
0

Answer:

Answer:

sir , or whoever u are please study text book or cw . u should not copy in test

Explanation:

samaj mein aya kya

Explanation:

Answered by aaditi2505
0

Explanation:

import java.util.*;

public class fare

{

char mode; double f, total;

Scanner sc=new Scanner(System.in);

void accept()

{

System.out.println("Enter passenger name");

String name= sc.next();

System.out.println("Enter the mode of transport as C or B");

mode=sc.next().chartAt(0);

System.out.println("Enter the distance travelled");

int d=sc.nextInt();

}

double calculate()

{

switch(mode)

case 'C':

{

if(d<=20)

{

f=40*d;

total= (18.55/100)*f;

}

if(d>20 && d<=60)

{

f=40*20+(d-20)*35;

total=(18.55/100)*f;

}

if (d>60))

{

f=60*35+(d-60)*32;

total= (18.55/100)*f;

}

}

break;

case 'B':

{

if(d<=20)

{

f=d*25;

total=(18.55/100)*f;

}

if(d>20 && d<=60)

{

f=20*25+(d-20)*20;

total=(18.55/100)*f;

}

if(d>60)

{

f= 60*20+(d-60)*15;

total=(18.55/100)*f;

}

}

}

void display()

{

System.out.println("passenger name " + name);

System.out.println("mode of transport "+ mode);

System.out.println("distance travelled "+ d);

System.out.println(" total fare "+ total);

}

public static void main(String args[])

{

fare obj= new fare();

obj.accept();

obj.calculate();

obj.display();

}

}

Similar questions