Computer Science, asked by chaitanyapurohpb1gqe, 1 year ago

how to solve this? please help . Cant understand 24th

Attachments:

Ankit02: I can solve it
QGP: You can solve it now

Answers

Answered by QGP
21
/** This is the Code for the Required Program.
 * Copy it entirely into an IDE, like BlueJ or Eclipse or whatever you use.
 * Description and Explanations are given as comments.
 * Screenshots of Program Output are attached.
 *
 * @author Purva
 * @since 2018-06-30
*/


import java.util.Scanner;                                       //Importing Scanner for input
public class Brainly                                            //Creating a Class
{
    public static void main(String[] args)                      //Creating main() function
    {
        Scanner sc = new Scanner(System.in);                    //Declaring Scanner Object

        System.out.println("---KUMAR ELECTRONICS---\n");        //Just Printing Name of Store

        System.out.print("Enter Name: ");                       //Asking User Input for Name
        String name = sc.nextLine();                            //Scanning User Input for Name

        System.out.print("Enter Amount of Purchase: ");         //Asking for Amount of Purchase
        double amount = sc.nextDouble();                        //Scanning User Input for Amount of Purchase

        System.out.print("Enter Type of Purchase [L/D]: ");     //Asking for Type of Purchase
        char type = sc.next().charAt(0);                        //Scanning User Input for Type of Purchase

        if(type=='l' || type == 'd' || type == 'L' || type == 'D')   //If Type of Purchase is valid, only then code will be executed
        {

            System.out.println();                   //Printing a blank line
       
            double discount = 0;                    //Creating a discount variable, initialising it to zero

            if(amount<=25000)                       //Condition of amount<=25,000
            {
                if (type=='l' || type == 'L')       //Condition of Laptop
                {
                    discount = 0*amount;            //Discount = 0% = 0
                }
                else                                //Condition of Desktop Computer
                {
                    discount = 0.05*amount;         //Discount = 5% = 0.05
                }
            }
            else if(amount<=50000)                  //Condition of 25,000 < amount <= 50,000
            {
                if (type=='l' || type == 'L')       //Condition of Laptop
                {
                    discount = 0.05*amount;         //Discount = 5% = 0.05
                }
                else                                //Condition of Desktop Computer
                {
                    discount = 0.075*amount;        //Discount = 7.5% = 0.075
                }
            }
            else if(amount<=100000)                 //Condition of 50,000 < amount <= 100,000
            {
                if (type=='l' || type == 'L')       //Condition of Laptop
                {
                    discount = 0.075*amount;        //Discount = 7.5% = 0.075
                }
                else                                //Condition of Desktop Computer
                {
                    discount = 0.10*amount;         //Discount = 10% = 0.10
                }
            }
            else                                    //Condition of amount > 100,000
            {
                if (type=='l' || type == 'L')       //Condition of Laptop
                {
                    discount = 0.10*amount;         //Discount = 10% = 0.10
                }
                else                                //Condition of Desktop Computer
                {
                    discount = 0.15*amount;         //Discount = 15% = 0.15
                }
            }
           
            double net = amount - discount;         //Calculating Net Amount to be paid
           
           
            System.out.println("Hello "+name);      //Printing a greeting
            System.out.println("The Amount to be Paid is INR "+net);    //Printing Final Net Amount to be paid
        }
        else                                        //Condition of Invalid Type of Purchase
        {
            System.out.println("Invalid Type of Purchase");     //Printing Invalid Purchase Type Message
        }
    }
}


Attachments:

siddhartharao77: Nice work bro!....
Anonymous: great answer bhai! :)
QGP: Thanks :)
Steph0303: Great answer sir
QGP: No "Sir". Only "Purva", or brother, or bro :))
QGP: Well even friend would do :)
Anonymous: bhai jaan Chalega? xD
QGP: Bilkul :)))))
Answered by Ankit02
16
Your Answer :-

import java.util.Scanner;public class ankit {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);        System.out.print("Enter name: ");        String name = scanner.nextLine();        System.out.print("Enter address: ");        String address = scanner.nextLine();        System.out.print("Enter type of purchase: ");        String type = scanner.nextLine();        System.out.print("Enter amount of purchase: ");        int amount = scanner.nextInt();        double discountRate = 0.0;        if (type.equals("L")) {
            if (amount <= 25000) {
                discountRate = 0;            } else if (amount >= 25001 && amount <= 57000) {
                discountRate = 5.0;            } else if (amount >= 57001 && amount <= 100000) {
                discountRate = 7.5;            } else if (amount > 100000) {
                discountRate = 10.0;            }        } else if (type.equals("D")) {
            if (amount <= 25000) {
                discountRate = 5.0;            } else if (amount >= 25001 && amount <= 57000) {                discountRate = 7.6;            } else if (amount >= 57001 && amount <= 100000) {                discountRate = 10.0;            } else if (amount > 100000) {                discountRate = 15.0;            }        }        double discount = (discountRate / 100) * amount;        double netAmount = amount - discount;        System.out.println("Name: " + name);        System.out.println("Address: " + address);        System.out.println("Net Amount: " + netAmount);
    }}

_____________
_____________
ANKIT


Attachments:

Anonymous: amazing answer bhai :))
QGP: Yes The Code and Logic is correct. Great Answer again :)
Ankit02: thanks
Ankit02: thanks dev bhai and purva bhai ::))
QGP: By the way, There is probably I think a small error. In the type "D" , the discount rate is actually 7.5 (and not 7.6). Also amount is mistakenly taken as 57000 instead of 50000. Apart from that, other things look fine
QGP: 57000 amount mistype is there in both "L" and "D"
Ankit02: ok bhai
Ankit02: Between purva bhai and my answer
My Answer is Brainliest .
Means a lot for me .
QGP: It indeed is a great answer :)
Ankit02: ::)))
Similar questions