Computer Science, asked by sarthaksingh62, 1 year ago

hi guys please help me.. please
please do this question by using scanner method in Java

Attachments:

sarthaksingh62: thank u brother for helping me out please follow me back. by the way after if we have to use braces {}
sarthaksingh62: please tell
sarthaksingh62: that after else if we have to use braces {......}
rakeshchennupati143: i used braces after my else if
rakeshchennupati143: and there is a slight change in the condition for middle 2 condition there has to be an "=" for "<" and ">" symbolls
sarthaksingh62: ok
sarthaksingh62: can i first find the discount and then write the payable amount..like this ap=cost-discount
rakeshchennupati143: yes you can but it will be more lines you have to do it for every if and else if statement
rakeshchennupati143: so to simplify i gave ( cost - ( 0.05 * cost ) ) first 0.05*cost gives 5% of the cost and that 5% will be deleted from the original cost

Answers

Answered by rakeshchennupati143
1

Program:

import java.util.*;

public class Main{

     public static void main(String[] args) {

           Scanner sc = new Scanner(System.in);

           System.out.println("Enter the cost : ");

           int cost = sc.nextInt();

           if( cost <= 2000 ){

                 System.out.println("The amount to be paid : "+(cost - (0.05 * cost))+" and gift is Calculator");

           }else if(cost > 2000 && cost < 5000){

                 System.out.println("The amount to be paid : "+(cost - (0.1 * cost))+" and gift is School Bag");

           }else if( cost > 5000 && cost < 10000){

                 System.out.println("The amount to be paid : "+(cost - (0.15 * cost))+" and gift is Wall Clock");

           }else{

                 System.out.println("The amount to be paid : "+(cost - (0.2 * cost))+" and gift is Wrist watch");

           }

     }

}

Output:

Enter the cost :

2000

The amount to be paid : 1900.0 and gift is Calculator

Explanation:

  • i took the cost into cost variable of type int
  • and i check if it is upto 2000 or in between 2000 and 5000 or in between 5000 and 10000 or higher than 10000
  • according to the if condition i wrote percentage code which will be deducted from the amount while it is printing
  • and it will print the gift that the customer would get at the cost they mentioned

___hope my program will help you get what you wanted, if you liked my program mark brainliest, i would really help me   :)


sswaraj04: you missed = in cost<5000 and in cost<10000 conditions
rakeshchennupati143: i checked it for first if-else and kept = to it and forgot about other cases, that was silly
rakeshchennupati143: and now i ca't edit
Similar questions