- Joined
- Nov 13, 2006
- Messages
- 15,643 (2.35/day)
- Location
- Mid-Atlantic
System Name | Desktop |
---|---|
Processor | i5 13600KF |
Motherboard | AsRock B760M Steel Legend Wifi |
Cooling | Noctua NH-U9S |
Memory | 4x 16 Gb Gskill S5 DDR5 @6000 |
Video Card(s) | Gigabyte Gaming OC 6750 XT 12GB |
Storage | WD_BLACK 4TB SN850x |
Display(s) | Gigabye M32U |
Case | Corsair Carbide 400C |
Audio Device(s) | On Board |
Power Supply | EVGA Supernova 650 P2 |
Mouse | MX Master 3s |
Keyboard | Logitech G915 Wireless Clicky |
Software | Fedora KDE Spin |
got a new small program that i finished but im having decimal issues. essentially it keeps cutting off the last "0" in the digits even tho i have DecimalFormat set to "0.0" and it is keeping the last counting to the thousandths place...
Code:
import java.io.*;
import java.text.DecimalFormat;
public class exam1
{
private BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat oneDecimal = new DecimalFormat("0.0");
private String input_string;
private double purchase_order, total_charge, initial_charge, bags_purchased, discount;
public void user_interface() throws IOException
{
System.out.println("How many bags of delicious coffee would you like to purchase?");
input_string = keyboard.readLine();
bags_purchased = Double.parseDouble(input_string);
if(bags_purchased < 25)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.00;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 25)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.05;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 50)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.10;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 100)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.15;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 150)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.20;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 200)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.25;
total_charge = initial_charge - discount;
}
if(bags_purchased >= 300)
{
initial_charge = bags_purchased * 5.50;
discount = initial_charge * 0.30;
total_charge = initial_charge - discount;
}
System.out.println("Number of Bags Ordered: " + bags_purchased + " - $" + initial_charge);
System.out.println("Discount: $" + discount ++);
System.out.println("Your total charge is: $" + total_charge + "");
}
public static void main(String[] args) throws IOException
{
exam1 x = new exam1();
x.user_interface();
}
}