Computer Science, asked by vasumaan741785, 9 months ago

Mayur transport company charges for the parcel as per the followibg tariff
weight. charges
upto 10 kg Rs 30 per kg
for next 20 kg Rs 20 per kg
Above 30 kg. Rs 15 per kg
write a program in java to calculate the charge for a parcel taking the weight of the parcel as input

Answers

Answered by oojoj
7

Answer:

mport java.util.Scanner;

class Bill

{

String n;

double w, charge=0.0, tot_charge=0.0;

public void accept(String name, double weight)

{

      n=name;

      w=weight;

}  

public void calculate()

{

if(w<=10)

{

 charge=25*w;

 tot_charge=charge+0.05*charge;

}

if(w>10 && w<=30)

{

 charge=20*w;

 tot_charge=charge+0.05*charge;

}

if(w>30)

{

 charge=10*w;

 tot_charge=charge+0.05*charge;

}

}

public void print()

{

System.out.println("Name");

System.out.println("\t\t");

System.out.println("Weight");

System.out.println("\t\t");

System.out.println("Bill amount");

System.out.println("\n");

System.out.println(n + "\t\t");

System.out.println(w + "\t\t");

System.out.println(tot_charge + "\n");

}

}

class Final_bill

{

public static void main(String[] args)

{

String s;

double wt;

Scanner sc=new Scanner(System.in);

System.out.println("Enetr the name of the customer: ");

s=sc.nextLine();

System.out.println("Enetr the weight of the parcel: ");

wt=sc.nextDouble();

Bill bill_obj=new Bill();

bill_obj.accept(s, wt);

bill_obj.calculate();

bill_obj.print();

}

Explanation:

Answered by pp5886608
4

Answer:

import java.util.Scanner;

public class KboatMayurTpt

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter parcel weight: ");

double wt = in.nextDouble();

double amt = 0;

if (wt <= 10)

amt = 30 * wt;

else if (wt <= 30)

amt = 300 + ((wt - 10) * 20);

else

amt = 300 + 400 + ((wt - 30) * 15);

System.out.println("Parcel Charge = " + amt);

}

}

Similar questions