public class DemoRaise { public static void main(String[] args) { double mySalar
ID: 3706914 • Letter: P
Question
public class DemoRaise
{
public static void main(String[] args)
{
double mySalary = 200.00;
double moneyAmount = 800.00;
System.out.println("Demonstrating some raises");
predictRaise(400.00);
predictRaise(mySalary);
predictRaise(moneyAmount);
}
public static void predictRaise(double moneyAmount)
{
double newAmount;
final double RAISE = 1.10;
newAmount = moneyAmount * RAISE;
System.out.println("With raise, salary is " + newAmount);
}
}
When I run program, the output was:
Demonstrating some raises
With raise, salary is 440.00000000000006
With raise, salary is 220.00000000000003
With raise, salary is 880.0000000000001
That is imprecise !
?I want output like this:
?Demonstrating some raises
With raise, salary is 440.00
With raise, salary is 220.00
With raise, salary is 880.0
?how can I fix this code in java
Explanation / Answer
Below is the running updated code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cheggquestions;
/**
*
* @author Prashant Tomer
*/
public class Demoraise
{
public static void main(String[] args)
{
double mySalary = 200.00;
double moneyAmount = 800.00;
System.out.println("Demonstrating some raises");
predictRaise(400.00);
predictRaise(mySalary);
predictRaise(moneyAmount);
}
public static void predictRaise(double moneyAmount)
{
double newAmount;
final double RAISE = 1.10;
newAmount = moneyAmount * RAISE;
System.out.printf("With raise, salary is %.2f ", newAmount); //just use formatted version of print in java
}
}
O/P:
Demonstrating some raises
With raise, salary is 440.00
With raise, salary is 220.00
With raise, salary is 880.00
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.