How would I display a shape in JOptionPane.showMessageDialog() in Processing? - java

Part of the requirement is to replicate the bar graph in https://imgur.com/a/Gx2XOql
I tried this to see if I could rectangle in the dialogue window (obviously it didn't work):
rectMode(CENTER);
// Alberta
if ( prov_id.equals("AB") || prov_id.equals("ab"))
{
if (gross_income>=0&&gross_income<=40000)
{
tax_rate=0.25;
JOptionPane.showMessageDialog(frame,"Province: "+ prov_id + "\nGross Income: "+ gross_income + "\nTax Rate: "+ tax_rate+ "\nTax Amount: "+ tax_amount+"\nNet Income: "+ net_income + rect(10,10,10,10));
}
The rest of my code:
import javax.swing.JOptionPane;
//Input Variables
String prov_id = ""; //province_id will contain the user input for the province (E.g. 'AB').
float gross_income = 0; //gorss_income contains the user input for gross income (E.g. 30000).
//Output Variables:
//You will store the result of your analysis and calculations in these variables
float tax_rate = 0; //Variable tax_rate will hold the tax_rate percentage. You will assign a value for tax_rate based on the Taxable Income (Table 1) table given in the studio project document.
//The value of tax ranges between 0 to 1 (E.g. for Alberta, income of equal or less than $40000 tax = 0.25)
float net_income = 0; //Net income is calculated based on tax_rate. It is the take-home income after taxes are deducted.
//i.e. net_income = gross_income * (1 - tax_rate);
float tax_amount = 0; //tax amount is the amount of taxes paid based on gross income depending on the province.
//i.e. tax_amount = gross_income * tax_rate;
// prompt for and read the province id
prov_id = JOptionPane.showInputDialog("Please enter your province's two-letter abbreviation (e.g., AB for Alberta): ");
// prompt for and read the gross income
String answer = JOptionPane.showInputDialog("Please enter your taxable income: ");
//convert user input to folat
gross_income = Float.parseFloat(answer);
net_income=gross_income*(1-tax_rate);
tax_amount=gross_income*tax_rate;
rectMode(CENTER);
// Alberta
if ( prov_id.equals("AB") || prov_id.equals("ab"))
{
if (gross_income>=0&&gross_income<=40000)
{
tax_rate=0.25;
JOptionPane.showMessageDialog(frame,"Province: "+ prov_id + "\nGross Income: "+ gross_income + "\nTax Rate: "+ tax_rate+ "\nTax Amount: "+ tax_amount+"\nNet Income: "+ net_income);
}
}
The expected out put is supposed to be this: https://imgur.com/a/Gx2XOql
So far my code displays this: https://imgur.com/a/Gx2XOql

The window where the bar graphs are shown is Processing's not one from JOptionPane.showMessageDialog() since the window is named "TaxCalculator_kEY", which i assume is the name of the file, not "Message".

Related

Sales receipt, multiple choices (if/else), while loop, customer ability to change selections

None of the other posts seemed to fit accordingly.
I'm really struggling with producing this program without errors. I've come up with this below, however, if you run the program it is not adequately looping and if you choose the same candy twice the math isn't adding to the previous selection.
For the second part, I need to recode to adjust so that the customer may change the current selections if they'd like. So, I need the first part running perfectly.
import java.util.Scanner; //Program uses Scanner
import java.util.Calendar; //Program uses calendar
public class ClairAndreaG005PA2
{//Begin class ClairAndreaG005PA2
public static void main(String[] args)
{
/**Begin method. The customer is asked whether to proceed with a candy purchase.
* As long as the candy choice is in the proper range, prompt for the quantity,
* calculate the item total and subtotal; otherwise, print an error message. If it’s
* the first item in the purchase, ass it to the sales, a receipt with a $ sign for the
* item total. If not format the item without a $ sign for the item total
* and add it to the sales receipt. Start the process again when the customer wants
* to add another candy purchase. When the customer is done, the sales tax and the
* total calculated, the sales receipt is finalized and printed.
*/
int quantity = 0,
formatFirstItem = 1,
choice = 0;
final double TAX_RATE = .0825; //tax rate declared
double price = 0,
itemTotal = 0,
subtotal = 0,
taxAmount = 0,
total = 0;
char proceed = ' '; //proceed variable for loop
String candy = new String();
Calendar dateTime = Calendar.getInstance(); //situational date and time
Scanner input = new Scanner(System.in);
String salesReceipt = String.format("%n%nFAIRYTALE SWEETS%n"
+ "North Star Mall%n"
+ "San Antonio, TX%n"
+ "Date: %n", dateTime
+ "Time: %n", dateTime);
//Initiating variables and calculations
System.out.printf("%nDo you want to proceed with your candy purhase? \'Y\' or \'N\': ");
proceed = input.nextLine().charAt(0);
//End Prompt 1
while(Character.toUpperCase(proceed) == 'Y')
{
System.out.printf("%nFAIRYTALE SWEETS"
+ "%n%n1. Arabian Nights Chocolate Coins - 1 lb. Bag %5s%,7.2f"
+"%n2. Beauty and the Beast Lollipops - 1 lb. Bag %,12.2f"
+"%n3. Mad Hatter Jelly Beans - 1 lb. Bag %,20.2f"
+"%n4. Pinocchio's Candy Cones - Each %,23.2f"
+"%n5. Sleeping Beauty Caramel Apples - Each %,17.2f"
+"%n%nEnter your choice: ", "$", 2.25, 2.50, 1.75, 0.75, 1.25);
choice = input.nextInt();
//Prompt 2 Candy Menu
if(choice > 0)
{if(choice < 6)
{if(choice == 1)
{candy = "Arabian Nights Chocolate Coins";
price = 2.25;
}
else
{if(choice == 2)
{ candy = "Beauty and the Beast Lollipops";
price = 2.50;
}
else
{if(choice == 3)
{candy = "Mad Hatter Jelly Beans";
price = 1.75;
}
else
{if(choice == 4 )
{candy = "Pinocchio's Candy Cones";
price = 0.75;
}
else
{candy = "Sleeping Beauty Caramel Apples";
price = 0.75;
}
}
}
}
System.out.printf("%nQuantity for %s: ", candy);
quantity = input.nextInt();
//quantity of selections
}
else
{ System.out.println("Invalid candy choice! Try again.");
}
//Choices and selections
itemTotal = quantity * price; //calculation 1
subtotal += itemTotal; //calculation 2
System.out.printf("%nWould you like to make another candy purchase? \'Y\' or \'N\': ");
proceed = input.next().charAt(0);
if(formatFirstItem == 1 )
{
salesReceipt += String.format("%n%s"
+ "%n %d # $%.2f ex. %-24s $%,10.2f%n", candy,
quantity, price, " ", itemTotal);
formatFirstItem = 0;
}
else
{
salesReceipt += String.format("%s"
+ "%n %d # $%.2f ea. %-25s %,10.2f%n", candy,
quantity, price, " ", itemTotal);
}
//End if FormatFIrst Item is 1 or else formatFirstItem NOT 1
}
}//End while loop selection
taxAmount = TAX_RATE * subtotal;// calculation 3
total = taxAmount + subtotal; // calculation 4
salesReceipt += String.format("%n%36s %-6s $%,10.2f"
+ "%n%36s %-7s %,10.2f"
+ "%n%n%36s %-6s $%,10.2f%n", "SUBTOTAL: ", " ",
subtotal, "TAX # 8.250%: ", " ", taxAmount,
"TOTAL: ", " ", total);
System.out.printf("%s", salesReceipt);
}
}
Let me know!

Program won't display output correctly

I'm writing a program that is supposed to display the output based off of some numbers that are typed in. I'm ending up with an output and it is completely blank, and none of the calculations are being performed
/**
*
* #NMATA003PA1.java
* #author Nicholas Mata
* #version 1.00 2015/09/25
*
* Program Purpose: This program controls whether a customer can calculate the cost of his/her stock purchases.
*
*/
import java.util.Scanner; //Scanner is imported to capture user input
import java.util.Calendar;//Calendare is imported to reflect the current date when necessary
public class MataN003PA1
{
public static void main(String[] args)//Customer will be able to calculate costs of multiple trades
{
String customerName = "", date = "";//Customer name and date are declared as Strings
int shares = 0, noOfStocks = 0;//shares and noOfShares are declared as integers, they are set to zero
double sharePrice = 0, stockCost = 0, commission = 0, totalCost = 0, onlineFee = 0, totalStockCost = 0, totalCommissions = 0, totalOnlineFees = 0;
/**
* sharePrice, stockCost, commission, totalCost, onlineFee, totalStockCost, totalCommissions, totalOnline Fees are declared
* as double, they are also set to zero
*/
char onlineTrade = ' ', brokerAssisted = ' ', another = ' '; // onlineTrade and brokerAssisted are declared as char variables, set to blank
Calendar dateTime = Calendar.getInstance(); //dateTime is declared
Scanner input = new Scanner(System.in);
System.out.printf("%nYEE-TRADE, INC. - The Wild West of Electronic Trading"
+"%n%nWelcome to Yee-Trade's stock purchase calculator.%n");
System.out.printf("%n%nWhat is your name? ");
customerName = input.nextLine();
System.out.printf("%nDo you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: ");
another = input.nextLine().charAt(0);
while (Character.toUpperCase(another) == 'Y')
{
noOfStocks = noOfStocks + 1;
System.out.printf("%nHow many shares did you purchase? ");
shares = input.nextInt();
System.out.printf("%nWhat is the price per share? ");
sharePrice = input.nextDouble();
input.nextLine();
stockCost = shares * sharePrice;
totalStockCost = totalStockCost + stockCost;
totalCost = totalCost + stockCost;
System.out.printf("%nIs this an online trade? Enter 'Y' or 'N': ");
onlineTrade = input.nextLine().charAt(0);
if (Character.toUpperCase(onlineTrade) == 'Y')
{
onlineFee = 5.95;
totalOnlineFees = totalOnlineFees + onlineFee;
totalCost = totalCost + onlineFee;
}//END if_1
else
{
System.out.printf("%nIs this a broker assisted trade? Enter 'Y' or 'N': ");
brokerAssisted = input.nextLine().charAt(0);
if (Character.toUpperCase(brokerAssisted) == 'Y')
{
commission = stockCost * .02;
totalCommissions = totalCommissions + commission;
totalCost = totalCost + commission;
}//END if_2
else
{
System.out.printf("%nINVALID TRADE TYPE! %n");
noOfStocks = noOfStocks - 1;
totalStockCost = totalStockCost - stockCost;
totalCost = totalCost - stockCost;
}//end else_2
}//end else_1
System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase or 'N' to exit: ");
another = input.nextLine().charAt(0);
}//END WHILE LOOP
if (noOfStocks > 0);
{
System.out.printf("%nYEE-TRADE, INC."
+"%nTOTAL COST OF STOCK PURCHASES"
+"%nFOR %s", customerName);
System.out.printf("%nAS OF ");
System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime);
System.out.printf("%nTotal Stock Cost: $", totalStockCost);
System.out.printf("%nTotal Online Fees: $", totalOnlineFees);
System.out.printf("%nTotal Commissions: $", totalCommissions);
System.out.printf("%n%nTOTAL COST: $", totalCost);
}//END if_3
System.out.printf("%nThank you for using Yee-Trade's stock purchase calculator! ");
noOfStocks = 0;
System.exit(0);}//END MAIN
}//END CLASS
You should not always try to format the output if it is not necessary.
Here's your problem :
System.out.printf("%nAS OF ");
System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime);
System.out.printf("%nTotal Stock Cost: $" + totalStockCost);
System.out.printf("%nTotal Online Fees: $", totalOnlineFees);
System.out.printf("%nTotal Commissions: $", totalCommissions);
System.out.printf("%n%nTOTAL COST: $", totalCost);
You'll have to replace most of these with the following
System.out.printf("%nAS OF ");
System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime);
System.out.println("Total Stock Cost: $" + totalStockCost);
System.out.println("Total Online Fees: $" + totalOnlineFees);
System.out.println("Total Commissions: $" + totalCommissions);
System.out.println("TOTAL COST: $" + totalCost);
Here is the output I get :
YEE-TRADE, INC. - The Wild West of Electronic Trading
Welcome to Yee-Trade's stock purchase calculator.
What is your name? Yassin
Do you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: Y
How many shares did you purchase? 50
What is the price per share? 50
Is this an online trade? Enter 'Y' or 'N': Y
Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: N
YEE-TRADE, INC.
TOTAL COST OF STOCK PURCHASES
FOR Yassin
AS OF OCTOBRE 04, 2015
Total Stock Cost: $2500.0
Total Online Fees: $5.95
Total Commissions: $0.0
TOTAL COST: $2505.95
Thank you for suing Yee-Trade's stock purchase calculator!

Java Lemonade Calculator

Assignment is to:
Display any welcome message at the top of the output screen
Create variables to hold the values for the price of a cup of lemonade.
Display the price per glass.
Ask the user for their name, and store it as a String object. Refer to the user by name, whenever you can.
Ask the user how many glasses of lemonade they would like to order. Save this as a variable with the appropriate data type.
Store the San Diego tax rate of 8% as a constant variable in your program.
Calculate the subtotal, total tax, and total price, and display it on the screen.
Ask the user how they would like to pay for the lemonade, and save the input as a char variable.
Ask the user to enter either 'm' for money, 'c' for credit card, or 'g' for gold
Using the DecimalFormat class, make all currency data printed to the screen display 2 decimal places, and also a '$" sign.
Need help figuring out how to get tax rate of 8% as a constant variable in my program
that way I can calculate the subtotal, total tax, and total price, and display it on the screen
So far this is what I have:
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class FirstProgram {
public static void main(String[] args) {
double cost = 7.55;
double amount = 7.55;
final double CA_SALES_TAX = 0.08;
int tax, subtotal, total;
subtotal = (int) (amount * cost);
tax = (int) (subtotal * CA_SALES_TAX);
total = tax + subtotal;
Scanner input = new Scanner(System.in);
double fnum = 7.55, tax1 = fnum * 0.08, answer = tax1 + fnum;
System.out.println("Welcome to the best Lemonade you'll ever taste! ");
System.out.println("My lemonade would only cost you a measly: $" + amount);
System.out.println("What is your name?");
String first_name;
first_name = input.nextLine();
System.out.println("Hi " +first_name+ ", how many glasses of lemonade would you like?");
fnum = input.nextDouble();
System.out.println("Subtotal: $" + (amount * fnum));
System.out.println("Tax: $" + (tax1 * CA_SALES_TAX));
tax1 = input.nextDouble();
Any help is appreciated
It looks like you already have the sales tax set as constant that is what the "final" keyword is being used for. As for your code i see some redundancies and am not sure as to why you are casting to integers. I made some mods for what I think you want it to do.
public static void main(String[] args) {
double cost = 7.55;
final double CA_SALES_TAX = 0.08;
double subtotal,tax,total;
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the best Lemonade you'll ever taste! ");
System.out.println("My lemonade would only cost you a measly: $" + cost);
System.out.println("What is your name?");
String first_name = input.nextLine();
System.out.println("Hi " +first_name+ ", how many glasses of lemonade would you like?");
int fnum = input.nextInt();
//calc subtotal, tax, total
subtotal = fnum * cost;
tax = subtotal *CA_SALES_TAX;
total = tax + subtotal;
// print them all out
System.out.println("Subtotal: $" + (subtotal));
System.out.println("Tax: $" + (tax));
System.out.println("Total Price: $" + (total));
}

Writing for loops/while loops?

I'm in a programming class in high-school, and I was given an assignment to make a basic subtotal and top calculator, but I work at a restaurant, so it seemed a little pointless to make a calculator that only let you read in one food. So I tried to make it able to take in multiple food items and add them to one price variable. Sorry if some of this code may seem inefficient or redundant. It's only high-school of course.
The issue is, when I run it, it gets up to the asking if there was another food item the user would like to add, and when I type in "Yes" or "No", the program does nothing. Keeps running, but goes no further. Any explanations?
import java.text.NumberFormat;
import java.util.Scanner;
public class Price {
/**
* #param args
*/
public static void main(String[] args) {
final double taxRate = .0887; //8.87% Tax Rate
double tipRate;
int quantity1;
Scanner kb = new Scanner(System.in);
double subtotal, tax, tip, totalCost1, unitPrice1 = 0;
String done;
System.out.println ("How many of the first item did you get?: ");
quantity1 = kb.nextInt();
for (int i = 0; i < quantity1; i++)
{
System.out.println ("What was the price of that single item "+(i+1) + ": ");
unitPrice1 = kb.nextDouble();
System.out.println ("Was there another food item you'd like to add?: ");
done=kb.next();
while (done.equalsIgnoreCase("Yes"));
}
System.out.println ("What percent would you like to tip? (Formatted like 0.10 for 10%, 0.20 for 20%, etc.): ");
tipRate = kb.nextDouble();
subtotal= quantity1 * unitPrice1;
tax = subtotal * taxRate;
totalCost1 = subtotal + tax;
tip = totalCost1 * tipRate;
totalCost1 = totalCost1 + tip;
//Formatting
NumberFormat money = NumberFormat.getCurrencyInstance();
NumberFormat tipMoney = NumberFormat.getCurrencyInstance();
NumberFormat taxPercent = NumberFormat.getPercentInstance();
NumberFormat tipPercent = NumberFormat.getPercentInstance();
System.out.println ("Your total before tax is: " + money.format(subtotal));
System.out.println ("The tax is " + money.format(tax) + " at " + tipPercent.format(taxRate));
System.out.println ("The tip at " + tipPercent.format(tipRate) + " is " + tipMoney.format(tip));
}
}
You have an infinite loop here:
while (done.equalsIgnoreCase("Yes"));
Once you enter Yes, it will keep sitting there and doing nothing because the value of done is Yes and never changes.
Also your loop structure is a bit odd. Your outer for loop runs as many times as the quantity of the first item. But shouldn't you only be multiplying that number to the cost? Because you are either running the loop for as long as the number of items the user entered (by asking them up front) or you don't ask them the total number of items and simply ask them to enter Yes if they want to add more items; you can't really do both.
Your loop should probably look something like this:
String input = "Yes";
while(input.equalsIgnoreCase("Yes")) {
System.out.println ("How many of the first item did you get? ");
quantity1 = kb.nextInt();
System.out.println ("What was the price of that single item? ");
unitPrice1 = kb.nextDouble();
//total += unitPrice1 * quantity1 - you don't have this in your code, but this is where you would be calculating the running total
System.out.println("Was there another food item you'd like to add? ");
input = kb.next();
}
you need to exit for loop when user enters yes, so you can use label here like below:
outerloop:
for (int i = 0; i < quantity1; i++)
{
System.out.println ("What was the price of that single item "+(i+1) + ": ");
unitPrice1 = kb.nextDouble();
System.out.println ("Was there another food item you'd like to add?: ");
done=kb.next();
while (done.equalsIgnoreCase("Yes")){
break outerloop;
}
}
Your current code does not do anything inside the while loop if you don't enter yes. And if you enter yes it will be stuck in infinite loop because of your while loop. This is not the efficeint way of looping, but this code will have least change in your current code.
You're while loop is doing nothing, you had given it a condition, but it has no instruction.
Try something like this..(sorry for my rusty java)
'public static void main(String[] args) {
//variable declaration
bool running = true
final double taxRate = .0887; //8.87% Tax Rate
double tipRate;
int quantity1;
Scanner kb = new Scanner(System.in);
double subtotal, tax, tip, totalCost1, unitPrice1 = 0;
String done;
while(running = true){
System.out.println ("How many of the first item did you get?: ");
quantity1 = kb.nextInt();
for (int i = 0; i < quantity1; i++)
{
System.out.println ("What was the price of that single item "+(i+1) + ": ");
unitPrice1 = kb.nextDouble();
System.out.println ("Was there another food item you'd like to add?: ");
done=kb.next();
if(done.equalsIgnoreCase("No")){
running = false
//Allows you to break out of the while loop if the user does not want to add anything else
//DO NOT USE BREAK STATMENTS, IT IS A POOR PROGRAMMING PRACTICE.
};//end if
}//end for
}//end while
System.out.println ("What percent would you like to tip? (Formatted like 0.10 for 10%, 0.20 for 20%, etc.): ");
tipRate = kb.nextDouble();
//You should comment whats going on here
subtotal= quantity1 * unitPrice1;
tax = subtotal * taxRate;
totalCost1 = subtotal + tax;
tip = totalCost1 * tipRate;
totalCost1 = totalCost1 + tip;
//Formatting
NumberFormat money = NumberFormat.getCurrencyInstance();
NumberFormat tipMoney = NumberFormat.getCurrencyInstance();
NumberFormat taxPercent = NumberFormat.getPercentInstance();
NumberFormat tipPercent = NumberFormat.getPercentInstance();
//Output
System.out.println ("Your total before tax is: " + money.format(subtotal));
System.out.println ("The tax is " + money.format(tax) + " at " + tipPercent.format(taxRate));
System.out.println ("The tip at " + tipPercent.format(tipRate) + " is " + tipMoney.format(tip));
}//end main

Difficulty with some debugging of a code that calculates the discount you would get with various membership levels

Over all, this code is supposed to ask for the customers name, member level, and original purchase price. It should store all of those in their respective variables, if something other than an accepted member level is entered the program is supposed to exit. After all the variables are stored, the customer's name, member level, original purchase price, promotional price, and amount saved should be printed out in the format at the end of this post. Thanks in advance for any help!
import java.util.*;
public class Discount{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
double purchase = 0.0;
double platinum = (purchase * .2);
double gold = (purchase * .15);
double silver = (purchase * .1);
String Platinum = null;
String Gold = null;
String Silver = null;
String customerName = null;
String level = null;
double discount = 0.0;
System.out.print("Please enter a customer name: ");
customerName = keyboard.nextLine();
System.out.print("Please enter the customer's member level: ");
level = keyboard.nextLine();
if (!level.equals("Platinum") && !level.equals("Gold") && !level.equals("Silver"))
{
System.exit(0);
}
System.out.print("Please enter the origianl purchase price: ");
purchase = keyboard.nextDouble();
System.out.println("Congratualations, " + customerName + "!");
if (level.equals("Platinum") && purchase > 500)
{
discount = (platinum + (purchase*.05));
System.out.println("As a " + level + " level cardholder, you have received a 25% discount during Bedlam.");
}
else if (level.equals("Platinum"))
{
discount = (platinum);
System.out.println("As a " + level + " level cardholder, you have received a 20% discount during Bedlam.");
}
else if (level.equals("Gold"))
{
discount = (gold);
System.out.println("As a " + level + " level cardholder, you have received a 15% discount during Bedlam.");
}
else if (level.equals("Silver"))
{
discount = (silver);
System.out.println("As a " + level + " level cardholder, you have received a 10% discount during Bedlam.");
}
Everything works fine up until this point, if I put in M as customerName, Silver as level, and 500.20 as purchase this is what prints out in the command prompt:
Congratualations, M!
As a Silver level cardholder, you have received a 10% discount during Bedlam.
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printFloat(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at Discount.main(Discount.java:62)
System.out.printf("%.2f\n", "Original purchase price: $" + purchase);
System.out.printf("%.2f\n", "Promotional price: $" + discount);
System.out.printf("%.2f\n", "Amount saved: $" + (purchase-discount));
This is what it should look like if successfully executed:
Congratulations, Marge Simpson!
As a Silver level cardholder, you received a 10% discount during Bedlam.
Original purchase price: $500.20
Promotional price: $450.18
Amount saved: $50.02 */
}
}
Refer to this.
Try this syntax:
System.out.println( "Original purchase price: $" + String.format("%.2f",purchase));
System.out.println("Promotional price: $" + String.format("%.2f",discount));
System.out.println("Amount saved: $" + String.format("%.2f", purchase-discount));
Right now you're basically passing the entire string "Original purchase price: $" + purchase as the argument for %.2f. Use String.format instead:
System.out.println("Original purchase price: $" + String.format("%.2f", purchase));
That also eliminates the need to append "\n" to the string, since you can use System.out.println.

Categories

Resources