Computer Science, asked by rahul87560, 7 months ago

Question 4.
Anshul transport company charges for the parcels of its customers as per the following II5]
specifications given below:

Class name : Atransport

Member variables: String name -to store the name of the customer

W to store the weight of the parcel in Kg

int charge to store the charge of the parcel

Member functions: void accept ) - to accept the name of the customer
weight of the parcel from the user (using
Scanner class)

void calculate ()-to calculate the charge as per the weight
of the parcel as per the following
criteria.

Weight in Kg Charge per Kg
Upto 10 Kgs | Rs.25 per Kg
Next 20 Kgs Rs.20 per Kg
Above 30 Kgs Rs.10 per Kg

Answers

Answered by rahitesh1396
11

Explanation:

public class Atransport()

{

public static String cName;

public static int wParcel;

private static int Pcharge;

public void accept()

{

Scanner name= new Scanner(System.in);

Scanner weight= new Scanner(System.in);

System.out.print("enter Your name");

cName=name.sc.nextLine();

System.out.print("enter Your Weight");

wParcel= weight.nextInt();

}

public void calculate()

{

if(wParcel<=10)

{

pCharge= wParcel*25;

}

else if(wParcel<=20)

{

pCharge=wParcel*20;

}

else if (wParcel>30)

{

pCharge=wParcel*10;

}

else{

System.out.println("Invalid Entry");

}

}

}

Similar questions