Need advice with nested if's - java

I have attempted using a nested if in the following code. I have initialized variables but the compiler is telling me that the variable named 'bill' is not initialized even though it has been. Why is the compiler not recognizing the value assigned to the variable? Please see the notes in the code below.
package killMe;
import java.util.Scanner;
public class Kill_Me {
static Scanner console = new Scanner(System.in);
static double PREMIUM_SERVICE = 55.00;
static double PREMIUM_DAY_OVERTIME_MIN = 0.20;
static double PREMIUM_NIGHT_OVERTIME_MIN = 0.15;
static double REGULAR_SERVICE = 30.00;
static double REGULAR_OVERTIME_MIN = 0.40;
public static void main(String[] args) {
int acctNumber;
double premiumDayMin;
double premiumNightMin;
double bill;
double minutes;
String name;
String premium = "PREMIUM";
String regular = "REGULAR";
System.out.println("What is the Account Number? ");
acctNumber = console.nextInt();
System.out.println("What is the Customer Name? ");
name = console.next();
System.out.println("Is the Service Code Premium or Regular? ");
String strService = console.next();
String strServiceCAP = strService.toUpperCase();
if(strServiceCAP.compareTo(premium) == 0)
{
System.out.println("How many Day Minutes were used? ");
premiumDayMin = console.nextDouble();
System.out.println("How many Night Minutes were used? ");
premiumNightMin = console.nextDouble();
if(premiumDayMin <0 && premiumNightMin <0)
{
System.out.println("Minutes cannot be less than 0 ");
}
else if(premiumDayMin <= 75 && premiumNightMin <= 100)
{
bill = PREMIUM_SERVICE;
}
else bill = PREMIUM_SERVICE + (premiumDayMin - 75) * PREMIUM_DAY_OVERTIME_MIN + (premiumNightMin - 100)
* PREMIUM_NIGHT_OVERTIME_MIN;
minutes = premiumDayMin + premiumNightMin;
System.out.println("Customer Name: " + name);
System.out.println("Account Number: " + acctNumber);
System.out.println("Service Type: " + strServiceCAP);
System.out.println("Minutes Premium Service Used (Day): " + premiumDayMin);
System.out.println("Minutes Premium Service Used (Night): " + premiumNightMin);
System.out.println("Amount Due: " + bill); // I get an error here stating, "The local variable 'bill' may not have been initialized".
}
else if(strServiceCAP.compareTo(regular) == 0)
{
System.out.println("How many minutes were used? ");
minutes = console.nextDouble();
bill = REGULAR_SERVICE + (minutes - 50) * REGULAR_OVERTIME_MIN;
System.out.println("Customer Name: " + name);
System.out.println("Account Number: " + acctNumber);
System.out.println("Service Type: " + strServiceCAP);
System.out.println("Minutes Regular Service Used: " + minutes);
System.out.println("Amount Due: " + bill); // I DO NOT receive an error message here.
}
else
{
System.out.println("Invalid Service Type");
}
} // End of main
} // End of class

No, bill has not been initialized in all cases.
Understand this: the Java compiler will never, ever, evaluate boolean expressions; Simplified version:
double bill;
if (c1) {
bill = v1;
} else if (c2) {
bill = v2;
}
// try and use bill here
Even if, according to your logic, boolean expressions c1 and c2 may cover all possible cases, the compiler cannot ensure that this is the case.
This is the root cause of your error, however deep your if/else, switch, etc statements may be nested.

They were some problems with else statement and variable declarations.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
double PREMIUM_SERVICE = 25.00;
double PREMIUM_DAY_OVERTIME_MIN = 0.10;
double PREMIUM_NIGHT_OVERTIME_MIN = 0.05;
double REGULAR_SERVICE = 10.00;
double REGULAR_OVERTIME_MIN = 0.20;
int acctNumber;
double premiumDayMin;
double premiumNightMin;
double bill = 0.0;
double minutes;
String name;
String premium = "PREMIUM";
String regular = "REGULAR";
System.out.println("What is the Account Number? ");
acctNumber = console.nextInt();
System.out.println("What is the Customer Name? ");
name = console.next();
System.out.println("Is the Service Code Premium or Regular? ");
String strService = console.next();
String strServiceCAP = strService.toUpperCase();
if(strServiceCAP.compareTo(premium) == 0)
{
System.out.println("How many Day Minutes were used? ");
premiumDayMin = console.nextDouble();
System.out.println("How many Night Minutes were used? ");
premiumNightMin = console.nextDouble();
if(premiumDayMin <0 && premiumNightMin <0)
{
System.out.println("Minutes cannot be less than 0 ");
}
else if(premiumDayMin <= 75 && premiumNightMin <= 100)
{
bill = PREMIUM_SERVICE;
}
else
{
bill = PREMIUM_SERVICE + (premiumDayMin - 75) * PREMIUM_DAY_OVERTIME_MIN + (premiumNightMin - 100)
* PREMIUM_NIGHT_OVERTIME_MIN;
}
minutes = premiumDayMin + premiumNightMin;
System.out.println("Customer Name: " + name);
System.out.println("Account Number: " + acctNumber);
System.out.println("Service Type: " + strServiceCAP);
System.out.println("Minutes Premium Service Used (Day): " + premiumDayMin);
System.out.println("Minutes Premium Service Used (Night): " + premiumNightMin);
System.out.println("Amount Due: " + bill); // I get an error here stating, "The local variable 'bill' may not have been initialized".
}
else if(strServiceCAP.compareTo(regular) == 0)
{
System.out.println("How many minutes were used? ");
minutes = console.nextDouble();
bill = REGULAR_SERVICE + (minutes - 50) * REGULAR_OVERTIME_MIN;
System.out.println("Customer Name: " + name);
System.out.println("Account Number: " + acctNumber);
System.out.println("Service Type: " + strServiceCAP);
System.out.println("Minutes Regular Service Used: " + minutes);
System.out.println("Amount Due: " + bill); // I DO NOT receive an error message here.
}
else
{
System.out.println("Invalid Service Type");
}
} // End of main
}

I'm not sure why it gets this error, but try initialising bill as 0.00 when you declare the variable.
Also,
if(premiumDayMin <0 && premiumNightMin <0)
should probably be changed to
if(premiumDayMin <0 || premiumNightMin <0)
Because you want to make sure that either minutes is not less then zero. You're program should then probably handle this error, because the rest of the program still executes. But maybe you're getting on to that :-P.

I don't recall what I did to stop getting an error message (sorry) but I removed the code if(premiumDayMin <0 && premiumNightMin <0) and replaced it with if(premiumDayMin <= 75 && premiumNightMin <= 100) to stop the code from being redundant. That may have fixed things. I also added another else if to clean the logic up further.

Related

Why isn't my live result updating in main?

I'm making a currency tracker to track the live value of bitcoin.
the class "bitcoinlive" runs Correctly if I run it in its own main method, but it won't work when I make an instance of the file. I need it to print the live value you of bitcoin.
I try to print out the variable "a53" but I don't know if I'm doing it right.
Here are the list of imports for the bitcoinlive class because it kept giving me an error message and wouldn't allow this to be apart of the code when posting this.
public static void main(String[] args) {
Dates d = new Dates();
String s = d.getDate();
System.out.println("Date is" + s);
W3 mywallet = new W3();
Bitcoinlive mybitcoinlive = new Bitcoinlive();
L3 myledger = new L3();
Scanner myscanner = new Scanner(System.in);
double buy = 0.0;
int choice = 0;
double bitcoin = 4000;
double USD = 20000;
while (choice != 5) {
System.out.println("Welcome! Enter a command. \n"
+ "Enter 1) Buy Bitcoin \n"
+ "Enter 2) Sell Bitcoin \n"
+ "Enter 3) Print Balance \n"
+ "Enter 4) Print History \n"
+ "ENTER 5) Exit Program\n");
choice = myscanner.nextInt();
if (choice == 1) {
System.out.println("How many? ");
buy = myscanner.nextDouble();
mywallet.add(buy);
bitcoin = bitcoin * buy;
USD = USD - bitcoin;
myledger.save(s);
System.out.println("you have bought:" + mywallet.numcoins);
System.out.println(USD);
System.out.println(mybitcoinlive.a53);
bitcoin = 4000;
} else if (choice == 2 && USD >= bitcoin) {
System.out.println("How many?");
buy = myscanner.nextDouble();
mywallet.subtract(buy);
System.out.println("you have sold:" + mywallet.numcoins);
USD = USD + bitcoin;
System.out.println(USD);
bitcoin = 4000;
myledger.save(s);
} else if (choice == 3) {
System.out.println("Balance:" + mywallet.numcoins);
} else if (choice == 4) {
System.out.println("Transaction history: ");
System.out.println("you have made" + myledger.getsize() + "transactions"
+ d.getDate());
} else if (choice == 5) {
// exit
break;
} else if (choice == 7) {
System.out.println(mybitcoinlive.price);
}
}
System.out.println("Bye");
}
this is my separate class
public class Bitcoinlive {
Double a53=0.0;
double price;
Double get() {
try {
String urlcoincapeth13 = "https://api.coinmarketcap.com/v1/ticker/bitcoin/";
Document docblocktradescoincapeth13 = Jsoup.parse(new URL(urlcoincapeth13).openStream(), "UTF-8", "", Parser.xmlParser());
String a13 = docblocktradescoincapeth13.toString();
int a23 = a13.indexOf("price_usd") + 13;
int a33 = a13.indexOf("price_btc") - 4;
String a43 = a13.substring(a23, a33);
a53 = Double.parseDouble(a43);
} catch (Exception e) {
System.out.println("Error accessing bitcoin values");
}
return a53;
}
}
Your class Bitcoinlive stores the price in a field called a53. You can update this field by calling get(). However, it looks like you're never calling get() - you're just calling the field:
System.out.println(mybitcoinlive.a53);
Try replacing that line with:
System.out.println(mybitcoinlive.get());
Or refresh it first:
mybitcoinlive.get();
System.out.println(mybitcoinlive.a53);

How do I state the }while(???) portion of the loop?

I need this code to loop for however many iterations someone decides to use, I do not understand what condition I would need to put into the {while**(??here??)**;
Also I understand that the loop should go around my input statements and tax computation, have I placed the do and the while in the right position?
EDIT* I've removed 2 of the cases from the code which are pretty much the same so I could post within the rules here.
import java.util.Scanner;
public class Assignment333 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
do {
System.out.println("Enter your first name:");
String name = input.next();
System.out.println("Enter your age in years:");
byte age = input.nextByte();
System.out.println("Enter your gender (F/M):");
char gender = input.next().charAt(0);
System.out.println("Enter your marital status (S/M/D/W):");
char marital_status = input.next().charAt(0);
System.out.println("Enter your taxable income for 2016:");
long income = input.nextLong();
String name_prefix;
double tax_amount;
if (gender == 'M') {
name_prefix = (age < 18) ? "Master." : "Mr.";
} else {
name_prefix = (marital_status == 'M') ? "Mrs." : "Ms.";
}
switch (marital_status) {
case 'M':
if (income < 8500) {
tax_amount = 0;
System.out.println(name_prefix + " " + name + ", based on the income provided, you owe no tax for the fiscal year 2016");
} else {
if (income < 24000) {
tax_amount = income * 0.01;
} else {
tax_amount = income * 0.025;
}
System.out.println(name_prefix + " " + name + ", based on the income provided, you owe a tax of $" + tax_amount + " for the fiscal year 2016");
}
break;
case 'W':
if (income < 8500) {
tax_amount = 0;
System.out.println(name_prefix + " " + name + ", based on the income provided, you owe no tax for the fiscal year 2016");
} else {
if (income < 24000) {
tax_amount = income * .015;
} else {
tax_amount = income * 0.034;
}
System.out.println(name_prefix + " " + name + ", based on the income provided, you owe a tax of $" + tax_amount + " for the fiscal year 2016");
}
while ()
}
break;
default: System.out.println("Sorry! Our system is unable to calculate your tax at this time.");
}
System.out.println("Thank you!");
//closing all objects
input.close();
}
}
You can finish it like this:
...
System.out.println("Would you like to try again? (y/n)");
} while (Objects.equals("y", input.next()))
...

Calling methods

I have a project in mind however there are a few basics I need to master before I can proceed. Here's the issue I'm trying to call a function from main in java but I can't get it to compile. I have read the feedback and I went with using a switch to call each function. I always get "error can't find symbol". I've made a few changes here and there trying to get it to run. Once again I feel like I'm lacking something very fundamental and it's preventing me from getting this to work. Any ideas
import java.util.*;
import java.lang.*;
import java.io.*;
class Practice {
static void wagecalc() {
Scanner input = new Scanner(System.in);
System.out.println("Input pay per hour:");
int a = input.nextInt();
int b;
System.out.println("Input hours worked:");
b = input.nextInt();
int c;
System.out.println("Input days worked:");
c = input.nextInt();
int gross = a * b * c;
System.out.println("Your gross pay is:" + gross);
// Determining tax rate//
if (gross < 10000) {
int taxrate = gross * 10 / 100;
System.out.println("Your tax rate is 10%:/n");
int total = gross - taxrate;
System.out.println("Your net pay is:" + total + "/n");
}
else if (gross > 10000 || gross <= 30000) {
int taxrate = gross * 15 / 100;
System.out.println("Your tax rate is 15%:/n");
int total = gross - taxrate;
System.out.println("Your net pay is:" + total + "/n");
}
else if (gross >= 30000 || gross <= 70000) {
int taxrate = gross * 20 / 100;
System.out.println("Your tax rate is 20%:/n");
int total = gross - taxrate;
System.out.println("Your net pay is:" + total + "/n");
}
else if (gross > 70000) {
int taxrate = gross * 25 / 100;
System.out.println("Your tax rate is 25%:/n");
int total = gross - taxrate;
System.out.println("Your net pay is:" + total + "/n");
}
}
static void autocalc() {
Scanner input = new Scanner(System.in);
// Declaring the variables as an integer//
int auto;
int loan;
int interest;
int mnydwn;
int pymnt;
int year;
int month = 12;
int tap;
int term = year * month;
int spec;
System.out.println("Please enter the following information for your car loan:/n");
System.out.println("Please enter the amount of the vehicle you wish to purchase:/n");
auto = input.nextInt();
System.out.println("Please enter the amount of money you wish to put down:/n");
mnydwn = input.nextInt();
System.out.println("Please enter the interest rate:/n");
interest = input.nextInt();
System.out.println("Please enter the term of the loan (years):/n");
year = input.nextInt();
System.out.println("Processing......../n");
System.out.println("Processing............");
// Calculations//
loan = auto - mnydwn;
int intamt = loan * interest;
tap = loan + intamt;
pymnt = tap / term;
// Display//
System.out.println("Process...Complete./n");
System.out.println("Car amount:" + auto);
System.out.println("Loan recieved:" + loan);
System.out.println("Interest rate:" + interest);
// if statement for proper output of year//
if (year == 1) {
System.out.println("Your monthly payments will be" + pymnt + "for a" + year + "year" + term + "months.");
} else if (year > 1) {
System.out.println("Your monthly payments will be" + pymnt + "for" + year + "years" + term + "months.");
}
System.out.println("Total amount paid at the end of the term" + tap);
}
public static void main(String[] args) throws java.lang.Exception {
// User input//
Scanner input = new Scanner(System.in);
int count = 0; // Count for the while loop//
// Instructions on how to begin interface//
System.out.println("Hi!/n");
System.out.println("...Thanks for using D Anomaly's Finance calculator!!/n");
System.out.println("Please choose one of the following:/n");
System.out.println(" 1. Wages:/n");
System.out.println(" 2. Auto Loan:/n");
// System.out.println(" 3. Home Loan:/n");//
System.out.println("Choose 1-3");
int calc = input.nextInt();
switch (calc) {
case 1:
wagecalc();
break;
case 2:
autolcalc();
break;
case 3: // homecalc();//
break;
if (calc >= 4) {
System.out.println(" Invalid entry!!!/n");
System.out.println("Please try again:");
break;
}
}
}
}
There are a few problems here, including the following:
1.
public void wageinformation(int gross) needs to be declared static if you want to call it from main()
2.
You are calculating int gross = a * b * c right after you have received it as a parameter.
3.
You have (or had in the initial version of this post) several extra braces.
4.
The deduction and total variables are never declared within the wageinformation() method.
I would strongly suggest working through some online Java tutorials if you are looking to improve your skills.

unable to get the correct output for input .11

I have an assignment at school and I have to display the correct change for an amount that is being input by the user that is less than 1.00 but greater than 0. Every amount works except anything in a double digit that has a 1 or a 6 on the tenth spot. for example .11, .16, .21, .26 etc.
this is my code
import java.util.Scanner;
public class AmountChange
{
public static void main(String[] args)
{
//
double amt;
int cents, quarter, dime, nickle, penny;
Scanner keyboard = new Scanner(System.in);
//To get the users input
System.out.println("Change in Coins");
System.out.println("---------------");
System.out.println("Enter the amount less than $1.00, " +
"\nbut more than zero.");
System.out.print("\nEnter amount: ");
amt = keyboard.nextDouble();
//Loop for incorrect input
while ( amt < 0 || amt > 1.00 )
{
System.out.println("Please enter the amount less than $1.00,"
+ "\nbut more than zero.");
System.out.print("\nRe-enter amount: ");
amt = keyboard.nextDouble();
}
//
cents = (int)( amt * 100 + .1 );
quarter = cents/25;
cents %= 25;
dime = cents/10;
cents %= 10;
nickle = cents/5;
cents %= 5;
penny = cents;
// ----------------------------------------------------------
if (quarter > 1)
{
System.out.print("\nYou will need " + quarter + " quarters, ");
}
else if (quarter == 1)
{
System.out.print("\nYou will need " + quarter + " quarter ,");
}
else
{
System.out.print("\nYou will need no quarters, ");
}
// ----------------------------------------------------------
if (dime > 1)
{
System.out.print(dime + " dimes, ");
}
else if (dime == 1)
{
System.out.print(dime + " dime, ");
}
else
{
System.out.print("no dimes, ");
}
// ----------------------------------------------------------
if (nickle > 1)
{
System.out.print(nickle + " nickles, ");
}
else if (nickle == 1)
{
System.out.print(nickle + " nickle, ");
}
else
{
System.out.print("no nickles, ");
}
// ----------------------------------------------------------
if (penny > 1)
{
System.out.print("and " + penny + " pennies.");
}
else if (quarter == 1)
{
System.out.print("and " + penny + " penny.");
}
else
{
System.out.print("and no pennies.");
}
}
}
Ah, the joys of cut and paste :-)
if (penny > 1)
{
System.out.print("and " + penny + " pennies.");
}
else if (quarter == 1) // <<<<< LOOK HERE !!!
{
System.out.print("and " + penny + " penny.");
}
else
{
System.out.print("and no pennies.");
}
That should be penny, not quarter.
And, in fact, it actually does work for .26 (despite your assertion) since quarter is set to 1, the same as penny. In fact it'll work for any value where the number of quarters equals the number of pennies (.26, .52, .78), but only by accident.
As an aside, one other thing you may want to think about is refactoring all that repeated code with something like:
import java.util.Scanner;
public class Test
{
static double getAmount(Scanner keyboard) {
System.out.println("Enter the amount between zero and $1.00.");
System.out.print("\nEnter amount: ");
return keyboard.nextDouble();
}
static String mkeTxt (int val, String prefix, String singular, String plural) {
if (val == 0)
return prefix + "no " + plural;
if (val == 1)
return prefix + "1 " + singular;
return prefix + val + " " + plural;
}
public static void main(String[] args)
{
double amt;
int cents, quarter, dime, nickle, penny;
Scanner keyboard = new Scanner(System.in);
System.out.println("Change in Coins");
System.out.println("---------------");
amt = getAmount(keyboard);
while ( amt < 0 || amt > 1.00 )
amt = getAmount(keyboard);
cents = (int)( amt * 100 + .1 );
quarter = cents/25;
cents %= 25;
dime = cents/10;
cents %= 10;
nickle = cents/5;
cents %= 5;
penny = cents;
System.out.print("\nYou will need ");
System.out.print(mkeTxt(quarter,"", "quarter", "quarters"));
System.out.print(mkeTxt(dime,", ", "dime", "dimes"));
System.out.print(mkeTxt(nickle,", ", "nickle", "nickles"));
System.out.print(mkeTxt(penny," and ", "penny", "pennies"));
System.out.println(".");
}
}
The use of a function to output the prompt and accept input makes the user input code a little easier to maintain as you only need to change interaction in one place.
The real saver is the mkTxt() function to give you a string that auto-magically adjusts to the quantity of coins. It gets rid of that voluminous group of if/then/else blocks in main(), aiding readability somewhat.
If you ever find yourself doing a similar thing many times but with different values, that positively cries out to be changed into a function or loop of some description.
You just have a simple typo!
Change:
else if (quarter == 1){
System.out.print("and " + penny + " penny.");
} else {
System.out.print("and no pennies.");
}
To,
else if (penny == 1){
System.out.print("and " + penny + " penny.");
} else {
System.out.print("and no pennies.");
}

InputMismatch exception not working

I have created a program to check for input range for integer variable "paycategory" but when I want to check for inputmismatch errors as well. I tried it but its not working... I don't want to change the data type to string because the paycategory is supposed to be integer. Please help how to fix this problem ?
import java.util.Scanner;
import java.util.*;
import java.text.*;
import java.lang.Object.*;
public class TestEmployeePayRoll {
public static void main(String Args[])
{
String EmployeeID = null, FirstName = null, LastName = null, result;
double HoursWorked;
int PayCategory = 0, counter = 0;
do
{
Scanner input = new Scanner(System.in);
try
{
int flag = 1;
String input1 ;
System.out.println("Enter your Employee ID number: ");
while(flag==1){
EmployeeID = input.nextLine();
if(EmployeeID.trim().length()>=5){
flag = 0;
System.out.println("Enter the First Name: ");
FirstName = input.nextLine();
System.out.println("Enter Last Name: "+ " ");
LastName = input.nextLine();
}else
System.out.print("EmployeeID must be exactly 5 digits long: \n Enter the Employee ID again: ");
}
}
catch(Exception e)
{
System.out.println("Exception ");
}
try{
do{
System.out.println("Enter the Pay Category: "+ " ");
PayCategory = input.nextInt();
if(!(PayCategory >0 || PayCategory <5))throw new InputMismatchException();
{
System.out.println("Pay Category must be between 1 and 4");
}
}
while(PayCategory < 1 || PayCategory > 4);
}
catch(InputMismatchException e)
{
System.out.println("PayCategory must be integers");
}
do
{
System.out.println("Enter the number of hours worked: ");
HoursWorked = input.nextDouble();
Double hours = new Double(HoursWorked);
if(hours.isNaN())
{
System.out.println("---Enter a valid hours value---");
}
else if(!(HoursWorked >1 || HoursWorked <80))
{
System.out.println("---Enter value between 1 and 80---");
}
}
while(HoursWorked < 1 || HoursWorked > 80);
EmployeePayRoll obj1 = new EmployeePayRoll(FirstName, LastName, EmployeeID, HoursWorked, PayCategory);
DecimalFormat fmt = new DecimalFormat("###,##0.00");
System.out.println("\n-----------------------------------------------------");
System.out.println("\n The pay details for:" + obj1.getName() + "\t\t\t" + "ID:" + EmployeeID);
System.out.println("\n-----------------------------------------------------");
System.out.println("Pay Category: \t\t\t" + obj1.getPayCategory());
System.out.println("Hours Worked: \t\t\t" + obj1.getHoursWorked());
System.out.println("Pay Rate: \t\t\t" + obj1.getPayRate());
System.out.println("Gross Pay: \t\t\t" + "$"+fmt.format(obj1.getGrossPay()));
System.out.println("Tax Payable: \t\t\t" + "$"+fmt.format(obj1.getTaxPayable()));
System.out.println("\t\t\t\t---------");
System.out.println("Net Pay: \t\t\t" + "$" + fmt.format(obj1.getNetPay()));
System.out.println("\n------------------------------------------------------");
System.out.println();
System.out.println("\n Process another employee? (Y/N)");
result = input.next();
}
while (result.equals("Y")||result.equals("y"));
}
}
Thanks
Your condition below can never be true, so the InputMismatchException will never be thrown.
if(!(PayCategory >0 || PayCategory <5))
throw new InputMismatchException();
Correct your condition.
Read up on De Morgan's laws.
!(PayCategory >0 || PayCategory <5) is equivalent to !(PayCategory>0) && !(PayCategory<5).
Dogbane is quite correct in his answer but this problem is common in your code: you are over complicating your logical conditions which is making errors harder to spot.
Take the line:
else if (!(HoursWorked > 1 || HoursWorked < 80))
HoursWorked will ALWAYS be either > 1 or < 80 so the bracketed condition will ALWAYS be true and the reverse never. Try to make your logical conditions simpler so that you can easily see what they are rather than using the ! operator when it really isn't necessary.
This condition should be:
else if (HoursWorked < 1 || HoursWorked > 80)

Categories

Resources