Write a java program to calculate charge for sending parcel.
For 1st kg - Rs 15
Thereafter for every 500 gm or its fraction - Rs 8
Answers
Answered by
109
hey friend,
public class parcel_price
{
public static void main(int w)
{
int ba=0;
if(w<= 1000)
{
ba=15;
}
else if (w>1000)
{
int ew = w-1000;
int k=ew/500;
if (ew% 500 == 0)
{
ba= 15+k*8;
}
else
{
ba=15+(k+1)*8;
}
}
System.out.println("Bill amount="+ba);
}
}
Here w stands for weight, ba stands for bill amount,ew stands for extra weight and k stands for no. of 500 grams
# hope it helps......
public class parcel_price
{
public static void main(int w)
{
int ba=0;
if(w<= 1000)
{
ba=15;
}
else if (w>1000)
{
int ew = w-1000;
int k=ew/500;
if (ew% 500 == 0)
{
ba= 15+k*8;
}
else
{
ba=15+(k+1)*8;
}
}
System.out.println("Bill amount="+ba);
}
}
Here w stands for weight, ba stands for bill amount,ew stands for extra weight and k stands for no. of 500 grams
# hope it helps......
Answered by
30
Answer:
Explanation:
import java.util.*;
class Parcel
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int w, a, b;
double c, d;
System.out.println("Enter the weight in grams");
w = in.nextInt();
if (w<=1000)
{
System.out.println("Charge = Rs.15");
}
else
{
a = w - 1000;
d = (w - 1000)/500;
b = a % 500;
if (b == 0)
{
c = 15 + (d*8);
System.out.println("Charge = "+c);
}
else
{
c = 15 + (int)d*8;
System.out.println("Charge = "+c);
}
}
}
}
Similar questions