Ask Experts Questions for FREE Help !
Ask
    samt51577's Avatar
    samt51577 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 13, 2013, 07:10 AM
    java questions
    Modify the application so it will only accept customer type codes r and c. It should also discard any extra entries on the customer type line. If the user enters an invalid code, the application should display an error message and ask the user to enter a valid code. This should be done first before the user enters a subtotal:

    import java.text.NumberFormat;
    import java.util.Scanner;

    public class InvoiceApp
    {
    public static void main(String[] args)
    {
    Scanner sc = new Scanner(System.in);
    String choice = "y";

    while (!choice.equalsIgnoreCase("n"))
    {
    // get the input from the user
    System.out.print("Enter customer type (r/c): ");
    String customerType = sc.next();
    System.out.print("Enter subtotal: ");
    double subtotal = sc.nextDouble();

    // get the discount percent
    double discountPercent = 0;
    if (customerType.equalsIgnoreCase("R"))
    {
    if (subtotal < 100)
    discountPercent = 0;
    else if (subtotal >= 100 && subtotal < 250)
    discountPercent = .1;
    else if (subtotal >= 250)
    discountPercent = .2;
    }
    else if (customerType.equalsIgnoreCase("C"))
    {
    if (subtotal < 250)
    discountPercent = .2;
    else
    discountPercent = .3;
    }
    else
    {
    discountPercent = .1;
    }


    // calculate the discount amount and total
    double discountAmount = subtotal * discountPercent;
    double total = subtotal - discountAmount;

    // format and display the results
    NumberFormat currency = NumberFormat.getCurrencyInstance();
    NumberFormat percent = NumberFormat.getPercentInstance();
    System.out.println(
    "Discount percent: " + percent.format(discountPercent) + "\n" +
    "Discount amount: " + currency.format(discountAmount) + "\n" +
    "Total: " + currency.format(total) + "\n");

    // see if the user wants to continue
    System.out.print("Continue? (y/n): ");
    choice = sc.next();
    System.out.println();
    }
    }
    }

Check out some similar questions!

Where to ask java questions [ 0 Answers ]

--- Rerendring any Richfaces JSF components Disable jQuery --- Facing an Issue ---- if I select any component from whole screen jQuery is not working in richfaces, if I Refresh the page jQuery works fine, but when I select a component jQuery don't work. Further Explanation: I have a page...

Ask questions about java [ 0 Answers ]

How do I measure Cyclomatic complexity for a java code which has abstract classes and packages. Its actually an anagram code and I have no idea how to calculate Cyclomatic complexity nor instability to that code. Please help me!

Ask questions of java [ 0 Answers ]

Hi, I have written the code to read messages from queue.But when I deploy this in weblogic 9.2 after creating a jar file it is showing unmarshaller failed Below is the code MyMdb.java package com.mdb.ejb;

Ask questions regarding java [ 0 Answers ]

) If any situation system is goes in deadlock condition,how you can recover from that situation programmitically. b) How you can decide when to use static class or interface. What is difference between the two. Which one is better to use in which situation.

Java questions - I need the answers [ 3 Answers ]

Declare each of the following: (a) a field of data type boolean and name isFound; (b) a local variable of data type String and name carModel; (c) a field of data type double and name weight; (d) a field of data type Employee and name secretary. 2. Write a declaration for an array variable...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.