Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## help me plz

write a program to calculate the fare of a journey given to input-the class('A','B' or 'C') and the distance in KM.
rate is to be calculated according to the following table:
class rate for first 500 KM rate/KM after 500 KM

A 3.5 10.75
B 2.5 7.5
C 2.0 5.0

USE switch-case to write the above program logic for fare calculation.

3. ## Re: help me plz

write a program to calculate the fare of a journey given to input.docx

--- Update ---

any one can help me in solving this QUESTION ???
I am a new Java student ..

4. ## Re: help me plz

What have you tried?

5. ## Re: help me plz

i tried this >

import java.util.*;
public class calculate{
public static void main(String[]args){
Scanner Kr=new Scanner(System.in);
char Class;
double DistanceinKm,Fare1,Fare2;
System.out.println("Enter Class ");
String s=Kr.next();
Class=s.charAt(0);
System.out.println("Enter the Distance");
DistanceinKm=Kr.nextDouble();
switch(Class){
case'A':
if(DistanceinKm<500){
Fare1=3.5*DistanceinKm;
System.out.println("fare for the first 500Km=+Fare 1");
}
else
Fare1=3.5*DistanceinKm;
if(DistanceinKm>500){
Fare2=Fare1+((DistanceinKm-500)*7.5);
System.out.println("fare for after500Km="+Fare2);
}
break;
case 'B':
Fare1=2.5*DistanceinKm;
if(DistanceinKm<500){
Fare2=Fare1+((DistanceinKm-500)*7.5);
System.out.println("fare for after500Km="+Fare2);
}
break;
case'C':
if(DistanceinKm<500){
Fare1=2.0*DistanceinKm;
System.out.println("fare for after500Km="+Fare1);
}
else
Fare1=2.0*DistanceinKm;
System.out.println("fare for after500Km="+Fare1);
Fare1=2.0*DistanceinKm;
if(DistanceinKm<500){
Fare1=2.0*DistanceinKm;
System.out.println("fare for after500Km="+Fare1);
}
else
Fare1=2.0*DistanceinKm;
if(DistanceinKm>500){
System.out.println("fare for after500Km="+Fare1);
}
break;
}
}
}

waiting 4 u

6. ## Re: help me plz

[code=java]
[/code]
to get highlighting and preserve formatting.

i tried this >
Post any questions you have about the problems you are having with the code.

7. ## Re: help me plz

Soory I can't understand your meaning