Find, highlight, and fix the errors in this Java Code: package school; // This c
ID: 3907044 • Letter: F
Question
Find, highlight, and fix the errors in this Java Code:
package school;
// This contains an overloaded method to give a price discount
public class Week2{
public static void main(String [] args){
final double DISCOUNT_RATE = 0.50;
int price1 = 85;
double price2 = 85.00;
fiftyPercentOff(price1 + DISCOUNT_RATE);
fiftyPercentOff(price2 + DISCOUNT_RATE);
}
public static void fiftyPercentOff(int p){
final double DISCOUNT_RATE;
int newPrice = p * DISCOUNT_RATE;
System.out.println("Fifty percent off " + p + " is" + newPrice);
}
public static void fiftyPercentOff(double p){
double DISCOUNT_RATE;
double newPrice = p * DISCOUNT_RATE;
System.out.println("Fifty percent off " + p + " is " + newPrice);
}
}
Explanation / Answer
Week2.java
public class Week2{
static final double DISCOUNT_RATE = 0.50;
public static void main(String [] args){
int price1 = 85;
double price2 = 85.00;
fiftyPercentOff(price1 + DISCOUNT_RATE);
fiftyPercentOff(price2 + DISCOUNT_RATE);
}
public static void fiftyPercentOff(int p){
int newPrice =(int) (p * DISCOUNT_RATE);
System.out.println("Fifty percent off " + p + " is" + newPrice);
}
public static void fiftyPercentOff(double p){
double newPrice = p * DISCOUNT_RATE;
System.out.println("Fifty percent off " + p + " is " + newPrice);
}
}
Output:
Fifty percent off 85.5 is 42.75
Fifty percent off 85.5 is 42.75
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.