Question
Can someone please debug these codes for me to identify problems with them? I am very new to debugging and programming in general so I
Can someone please debug these codes for me to identify problems with them? I am very new to debugging and programming in general so I would appreciate it so much.
Here is the first code:
import java.util.*;
public class HA8LargestErr {
private int num1;
private int num2;
private int num3;
public HA8LargestErr() {
num1 = 0;
num2 = 0;
num3 = 0;
}
public void getNumsFromUser() {
Scanner input = new Scanner (System.in);
System.out.println("Enter three numbers: ");
num1 = input.nextInt();
num2 = input.nextInt();
num3 = input.nextInt();
}
public int returnLargest() {
if (num1 > num2 && num1 > num3)
return num1;
if (num2 > num3 && num2 > num1)
return num2;
return num3;
}
public static void main(String[] args) {
HA8LargestErr data = new HA8LargestErr();
data.getNumsFromUser();
System.out.println ("The largest is : " + data.returnLargest());
}
}
---------
And here is the second one:
import java.util.*;
public class HA8PayrollErr {
public static void main(String[] args)
{
float hoursWorked;
float ratePay;
float basePay = 0.0f;
float overtimePay = 0.0f;
float totalPay = 0.0f;
float taxDeducted = 0.0f;
float netPay = 0.0f;
int doAgain = 0;
Scanner input = new Scanner(System.in);
do {
System.out.println("Enter hours worked this week");
hoursWorked = input.nextFloat();
System.out.println("Enter rate of pay");
ratePay = input.nextFloat();
if (hoursWorked > 37.5f) {
basePay = 37.5f*ratePay;
overtimePay = (hoursWorked - 37.5f) * ratePay * 1.5f;
} else {
basePay = hoursWorked * ratePay;
}
totalPay = basePay + overtimePay;
if (totalPay
taxDeducted = 0;
else if (totalPay > 2000)
taxDeducted = totalPay *0.30f;
else taxDeducted = totalPay * 0.20f;
netPay = totalPay - taxDeducted;
System.out.println ("Base pay is : $" + basePay);
System.out.println ("Overtime pay is : $"+ overtimePay);
System.out.println ("Tax deducted is : $" + taxDeducted);
System.out.println ("Net pay is : $" + netPay);
System.out.println ("Enter 0 to repeat, or 1 to quit: ");
doAgain = input.nextInt();
} while (doAgain == 0);
}
}
1 import java.util.*; 2 4 public class HA8LargestErr { private int num1; private int num2; private int num3; 6 7 9 public HA8LargestErr() num1 = 0; num2 = 0; num3 = 0 10 12 13 15 public void getNumsFromUser() 16 17 18 19 20 21 Scanner input = new Scanner (System.in); System.out.println("Enter three numbers: "); num1 = input.nextInt(); num2 = input.nextInt(); num3 = input.nextInt(); 23 public int returnLargest() { 24 25 26 27 28 29 30 31 if (numl num2 && num1 num3) if (num2 num3 && num2 num1) return num3; return num1; return num2; 32 public static void main(String] args) ( data HA8 Large stErr(); 34 35 36 37 38 39 40 41 HA8 Large stErr new = data.getNumsFromUser(); System.out.println ("The largest is" data.returnLargest())
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started