Write a basic program in Java to calculate the charges for sending parcels when the charges are as follows:
For the first 1kg ₹15.00. For additional weight, for every 500gm or fraction thereof : ₹8.00
Answers
Answer:
Take sum as an input from the user.
import java.io.*;
public class Q1
{
public static void main(String args[])throws IOException
{
InputStreamReader read =new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(read);
int p; double SI1,SI2,SI3,A3;
System.out.println(“Enter the principal”);
p=Integer.parseInt(in.readLine());
SI1=(p*5.0*1)/100.0;
System.out.println(“Interest for the first year =”+SI1);
SI2=((p+SI1)*5.0*1)/100.0;
System.out.println(“Interest for the second year =”+SI2);
SI3=((SI1+SI2+p)*5.0*1)/100;
A3=SI1+SI2+SI3+p;
System.out.println(“Amount after three years =”+A3);
}
}
Sample Input: 10000
Sample Output: Interest for the first year =500.0
Interest for the second year =525.0
Amount after three years =11576.25
Answer: 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
Explanation: hope it helps
please mark me as brainliest