Purchase Solution

Modifying Java Code

Not what you're looking for?

Ask Custom Question

Criterion
EnhancedInvoiceApp.java compiles
Type "R" with subtotal >= $250 and < %500 get 25% discount
Type "R" with subtotal > $500 get 30% discount
Type "C" always get 20% discount
Added new Type "T" with subtotal < $500 get 40% discount
Added new Type "T" with subtotal >= $500 get 50% discount
Types other than "C", "R" or "T" get no discount.
Introduce static method getDiscountPercentwith customer type and subtotal parameters
Move discount calculations to static method
Invoke static method to calculate discounts

Modify code
The code must be open in netbean 7.2

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();
}
}
}

Attachments
Purchase this Solution

Solution Summary

The following posting helps modify java code.

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Networking Questions

This quiz consists of some basic networking questions.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.