Purchase Solution

Clarifying java string comparison and control structures

Not what you're looking for?

Ask Custom Question

Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the print out, display the dollar symbol ($) to the left fo the weekly pay amount and formate the weekly pay amount to display currency. Also have the application to continue to request employee information until the user enters "stop" as the employee name. Have the program to check the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, teh application should prompt the user to enter a positive amount. The program should use a class to store or retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method withing that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate.

Please keep this as simple as possible, no fancy stuff. No boolean, keep as one program by renaming the class within the class, no private static void. Very very very basic program with printf. Please! No buffered reader either. I cannot express simply simply simply and basic to much here! I'm a beginner programmer and need to see the basic before jumping into deep. A scanner is fine! I have included an attachment so you get the idea of how basic.

No, the new class will not be contained within the main method and you do not have to put it in a file of its own.

Yes, you are to create a main method that will create an instance of the class. The class should contain a constructor and a method that performs all of the functionality of the previous program.

Here is a brief example:

public class WeeklyPayroll
{
public static void main (String args[ ])
{
PayrollClass myPayroll = new PayrollClass ( );
} // end of main method

class PayrollClass ( )
{
declare variables

create constructor

}// end of Payroll class

}// end of WeeklyPayroll

Step 1: create a class declaration. If you create a class in the same program as the main the declaration might look something like this:

class NewClass
{
You will need to move all of the variables declared in the main to here.

Step 2: after the class and variable declaration you will create a constructor. Remember that a constructor is executed when you create a new object from a class. Constructors are declared just like other methods except that they have exactly the same name as the class. The constructor will come right after the declaration of the variables.

class NewClass
{
You will need to move all of the variables declared in the main to here.

public NewClass( )
{
You do not have to put anything in this constructor unless you are passing values to your variables. In this case, we are not.

}// end of constructor
} // end of NewClass

Step 3: now that you have your class created, we have to create a method that will calculate the weekly pay. We will declare this method void because this method will before a task but will not return any information when it completes the task. We will want to move everything contained in the outer while loop to this method that will immediately follow the constructor.

Step 4: the main method now has no statements. We will add only two statements. The first will be the statement that creates a new object and the second statement will call the method to calculate the weekly pay.

I'm not asking anyone to do the work I have attached what I have in payroll4.java I cannot get to compile. Please help!

Scanner should be fine.

Purchase this Solution

Solution Summary

In this solution I demonstrate the use of the java case insensitive string comparison method. I also show the difference between using an if statement and a while statement.

Solution Preview

The provided program was a very good start at solving this problem. I found two issues that needed to be fixed. The first deals with out the equalsIgnoreCase. The second deals with the confusion between if statements and while statements.

The "equalsIgnoreCase" method needs to be called on a String value. The original program showed this:

emp.equalsIgnoreCase("stop");

The emp object is an Employee type not a String. Since the Employee type doesn't have an ...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C# variables and classes

This quiz contains questions about C# classes and variables.