Saturday, 19 November 2022

selection Control Structure - Assignment 4

 

Selection Control Structure - Assignment 4


Food Corner home delivers vegetarian and non-vegetarian meals to its customers based on the order.

A vegetarian combo costs $12 per plate and a non-vegetarian combo costs $15 per plate. Apart from the cost per plate of food, customers are also charged for home delivery based on the distance in kms from the restaurant to the delivery point. The delivery charges are as mentioned below:

Given the type of food, quantity (no. of plates) and the distance in kms from the restaurant to the delivery point, implement a program to calculate the final bill amount to be paid by a customer.

The below information must be used to check the validity of the data provided by the customer: 

  • Type of food must be 'V' for vegetarian and 'N' for non-vegetarian.

  • Distance in kms must be greater than 0.

  • Quantity ordered should be minimum 1.

If any of the input is invalid, the bill amount should be displayed as -1.

 

Sample Input and Output

class Tester{

public static void main(String[]args){
char foodType='N';
int quan=0;
int dist=1;
int m=dist;
int output=0;
int total=0;
int extra=0;
int extra1=1;
int extra2=2;
int   cost=0;
int charge=0;
int sona=0;
if(foodType=='N')
{
cost=15;
}
else{
cost=12;
}
if(quan>=1)
{
total=cost*quan;
System.out.println("totalcostis$"+total);
}
else{
System.out.println("Invalidselection");
output=-1;
System.out.println("totalbillamountis:"+output);
System.out.println("ordercannotbeplaced");
}
if(dist>=1)
{
if(dist<=3)
{
System.out.println("nodeliverycharges");
}
else if(dist<=6)
{
System.out.println("Additionaldeliverychargesfor$1perkm");
extra=dist*extra1;
}
else if(dist<=m)
{
System.out.println("Additionaldeliverychargesof$3and$2perkm");extra=3+((dist-6)*extra2);
}
output=total+extra;
System.out.println("yourorderhasbeensuccessfullyplacedworth$"+output);}
else
{
System.out.println("invalidselection"+"ordercannotbeplaced");}
}
}


No comments:

Post a Comment

Free Resume Template

Creating a blog post that discusses the pros and cons of using a resume rule is a great way to provide valuable information to job seekers ...