Sorry for the bland question, but anyway here is my code
import java.io.*;
import java.text.*;
public class Prob5 {
public static void main(String[] args) throws Throwable {
BufferedReader in = new BufferedReader( new InputStreamRead er(System.in));
NumberFormat nf = NumberFormat.ge tNumberInstance ();
nf.setMaximumFr actionDigits(2) ;
double D,P,S,Y;
System.out.prin tln("Enter the purchase price of the item:");
P = Double.parseDou ble(in.readLine ());
System.out.prin tln("Enter the length of time,in years, you plan on using this item:");
S = Double.parseDou ble(in.readLine ());
System.out.prin tln("Enter the expected salvage value(price you plan to sell it for):");
Y = Double.parseDou ble(in.readLine ());
D = (P-S)/Y;
String n = nf.format(D);
System.out.prin tln("The yearly depression for this item is $" + n);
}
}
When I run the program the answer comes out wrong even though my math is right. An example for instance is I tried just doing D = P-S and I made the values of P and S equal 4000 and 1000 respectively. However D came out to be 3997.
import java.io.*;
import java.text.*;
public class Prob5 {
public static void main(String[] args) throws Throwable {
BufferedReader in = new BufferedReader( new InputStreamRead er(System.in));
NumberFormat nf = NumberFormat.ge tNumberInstance ();
nf.setMaximumFr actionDigits(2) ;
double D,P,S,Y;
System.out.prin tln("Enter the purchase price of the item:");
P = Double.parseDou ble(in.readLine ());
System.out.prin tln("Enter the length of time,in years, you plan on using this item:");
S = Double.parseDou ble(in.readLine ());
System.out.prin tln("Enter the expected salvage value(price you plan to sell it for):");
Y = Double.parseDou ble(in.readLine ());
D = (P-S)/Y;
String n = nf.format(D);
System.out.prin tln("The yearly depression for this item is $" + n);
}
}
When I run the program the answer comes out wrong even though my math is right. An example for instance is I tried just doing D = P-S and I made the values of P and S equal 4000 and 1000 respectively. However D came out to be 3997.
Comment