That takes in as argument pay check double and expense doubl
Solution
Note:
I took the valid number for paycheck and expense as greater than zero values.If you want me to modify for any other value just tell me I will change.Thank You
______________________
PaycheckExpense.java
import java.util.Scanner;
public class PaycheckExpense {
public static void main(String[] args) {
//Declaring variables
double paycheck,expense;
//Scanner class object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//This loop continues to execute until the user enters a valid input
while(true)
{
//getting the paycheck value entered by the user
System.out.print(\"Enter the Pay check value :$\");
paycheck=sc.nextInt();
if(paycheck<=0)
{
//Displaying the error message
System.out.println(\"** Invalid Number.Must be greater than zero **\ \");
continue;
}
else
break;
}
//This loop continues to execute until the user enters a valid input
while(true)
{
//getting the expense value entered by the user
System.out.print(\"Enter the Expenses :$\");
expense=sc.nextInt();
if(expense<=0)
{
//Displaying the error message
System.out.println(\"** Invalid Number.Must be greater than zero **\ \");
continue;
}
else
break;
}
//calling the method by passing the paycheck and expense value as arguments
checkAmt(paycheck,expense);
}
/* this method will display the appropriate messages
* based on the paycheck and expense values
*/
private static void checkAmt(double paycheck,double expense) {
if(paycheck<100)
{
System.out.println(\"Better than Nothing!\");
}
else if(paycheck<expense)
{
System.out.println(\"You are in debt by $\"+(expense-paycheck));
}
else if(paycheck>expense)
{
System.out.println(\"Good job! You can save $\"+(paycheck-expense));
}
else if(paycheck==expense)
{
System.out.println(\"Living paycheck to pay check..\");
}
else if(paycheck>5000)
{
System.out.println(\"Not bad!\");
}
}
}
_________________
output:
Enter the Pay check value :$-250
** Invalid Number.Must be greater than zero **
Enter the Pay check value :$250
Enter the Expenses :$-250
** Invalid Number.Must be greater than zero **
Enter the Expenses :$250
Living paycheck to pay check..
________________Thank You

