Create Class Employee Which Contains A String Variable Employee Number

Jul 13, 2014

I have searched for totalPay is always 0 and the responses are not related to my problem (that I can tell).This is a class assignment and I have other questions besides why the method is not working.

Here are the instructions: Create class Employee which contains a String variable Employee Number, a String variable Employee Name, an integer Hours Worked, and a double Pay Rate. Create get and set methods for each variable. Provide method "totalPay" which calculates and returns the total pay by multiplying the hours worked by pay rate. Use figure 8.12 as an example of an object with get and set methods.

Unlike other examples of this type question online this one has Employee Number as a String variable. The book is How to Program Early Objects by Deitel 9th edition.We have instructions to do only what she has told us too. At this point it is objects and getter and setter methods. It is only the beginning of week 2.

ON THE LINES WHERE I HAVE QUESTIONS I AM COMMENTING IN ALL CAPS. NOT SHOUTING, JUST TRYING TO MAKE IT EASIER

package test11;
import java.util.Scanner;
public class Test11 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]..

Essentially I cannot figure out how to get the method getTotalPay to be called by the Scanner and do the math. I also have this random bracket problem that showed up about an hour ago.

The concept I don't get is that if I omit this.employeeNumber =id; etc. I error all over the place. If I change it to this.employeeeNumber = employee Number Netbeans tells me it is assigning itself to itself, which I know. When I try to use id instead of employeeNumber I get errors all over. If i remove "this" from it the same happens. why in public class employee I have to change to those values (id, name, etc) in the construct and set them again? I don't see where or how they can be used, so why do i have to do it?

View Replies


ADVERTISEMENT

Use Applet To Create Two Instances Of Employee Class

Jan 9, 2014

What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.

What I'm doing:

import java.applet.Applet;
import java.awt.*;
public class EmployeeApplet extends Applet {
public static int topSalary = 195000;
int hoursPerWeek;
public static void setTopSalary (int s) {
if (s > topSalary)

[Code]...

I'm not able to display hours per week for e1 and e2.

View Replies View Related

Sorting Lists In Employee Class

Feb 5, 2014

A Employee Class where i want to sort there lists one by there salary and one by there name individually as per the requirement ? How we do it?

View Replies View Related

Add New Employee And Enter A String / Data Does Not Appear In File

Mar 23, 2015

I'm just trying to append new employee information to a previously created file. When I type yes to add new employee and enter a string, the data does not appear in the file.

Java Code:

public class Records {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
FileWriter fw = new FileWriter("dbs3.java", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);

[code]....

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index. Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

I'm not sure how to use the index to do this correctly, all it's doing right now is adding hours to every hourly employee

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index.Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

View Replies View Related

Basic Console Java Program - Generate Employee ID

Feb 27, 2014

Basic console java program. I need to generate an employee id. I have an employee class that I will paste here so you can see my fields and constructors.

public class Employee {
private String firstName;
private String lastName;
private int id;
public int nextUniqueId = 0;
public Scanner sc = new Scanner(System.in);

[Code] ....

View Replies View Related

Building Calendar With Automated Employee Vacation Planner?

Apr 4, 2014

Every year, she has to plan when her employee's can go on vacation for the summer holidays - MANUALLY. It takes weeks to solve the puzzle, because she has several kinds of employee's hired, with different skills. And at all days there must be X amount of employees with skill1 at work, plus Y amount of employees with skill2 etc, and they also need special "off-days" in comparison to when they last worked and so on. It's quite the math puzzle.

I've worked a little with C#, and built a prototype of a Support System (Ticket based), so I got the basics down of programming, and I know Java and C# are quite alike, so I don't think making the switch will bother me that much.

The program should be easy to use for her, so it needs a visual calender that can be interacted with, and it should also be easy to see which employee is at work at that date and so on.

Will it be hard for me to build this kind of Calender, that allows the interaction I want?

Any open-sourced projects, or libraries that will make my task easier?

I plan on using NetBeans IDE for this project.

View Replies View Related

Report Employee Time Clock Cannot Find Corresponding Dates In And Out

Mar 8, 2014

I have this assignment to build an employee time clock. By using a menu you can enter an employee, enter punch in and out, and report.When I created the punch screen I wrote the in and out records to a file. Because there can be several employees punching in or out the file wrote each occurrence on different lines. Now I am attempting to write the report which you enter an employee Id and loop through the file to find the in and out date and then calculate the time (hours worked). I loaded the file into an Arraylist but now I cannot figure out how to loop through find the In and Out date - calculate the hours worked and then move on to the next day. here is the format of the file - employee id, place holder I or O, date, time, day. and sample

111221111i3/2/145:10 PMSunday
111221111o3/2/145:10 PMSunday
111331111i3/2/145:25 PMSunday
111331111o3/3/1412:47 PMMonday
111221111i3/3/1412:48 PMMonday
111221111o3/3/142:23 PMMonday
111441111i3/4/141:30 PMTuesday

[code]....

here is my code from the main screen.

public static void displayPunches()
throws FileNotFoundException, IOException, ParseException {
boolean isValid = false;
String choice = "y";
String emp = Validator.getLine(sc, "Enter I -Individual or A -All ");
if (emp.equalsIgnoreCase("A"))

[code]....

View Replies View Related

Adding A Phone Object Into Student / Employee Objects

Jun 1, 2014

I have to read in a file that that has Student, Employee, Faculty....such as name, last name, salary...etc

Example of a file input
Java Code: Student, John, Doe, [email]johnDoe[At]yahoo.com[/email], 123,Wonderland Ave, 21323,TX
PhoneNumber,Cell,111,222,3333
Student, Jesus,Satan,[email]jesus[At]satan.com[/email,666, HeavenHell Dr., 666666,CA
PhoneNumber,Work,111,333,5555 mh_sh_highlight_all('java'); Java Code: while(input.hasNext()){

[code]...

There is more code, but it's repetitive. Now, I keep getting an error. Array of bounds. I believe i get the error because the phone number. The phone number is on the next line..I created a different arraylist for phonenumber, but I dont know how to match it with the correct person, student, employee...etc.

View Replies View Related

Program That Displays Information For Employee Objects Of Different Types

Apr 29, 2014

I'm making a program that displays information for "employee" objects of different types. This works with a hierarchy that goes Person→ Employee→ Fulltime/Adjunct, and a driver that tests the inheritance. The Person class is given and only supplies the name, the employee class manages the year hired and the ID, and the types of employee classes manage the salaries.

One object (called staff[2]) is supposed to first be printed with default information and then later updated via set methods. I figured out how to update the name, but I don't know how to update the rest of the information because the employee's name is managed in the Person class and the reset of the information is managed in the less-general classes, and the objects are all in an array of Person.

How do I call the set methods necessary to update more of staff[2]?Output (scroll to see the updating section)

The current year is 2012

Name: Flintstone, Fred
ID Num: BR-1
Year Hired: 2005
Years Of Service: 7
Salary: 65000.12
Fulltime Type Employee

[code]....

View Replies View Related

How To Read Employee Thumb Impression From Biometric Instrument Using Java

Mar 13, 2014

How to read the thumb impressions by using bio-metric instrument using a java code and comparing the thumb impressions in java.

View Replies View Related

Write A Java Program To Store Employee Information In A Linked List

May 12, 2015

Write a java program to store employee information in a linked list, the program should implement the following functions:

The program should display the list of functions, and ask the user to enter the number of function that he/she wants to do, then perform the function as it is required in the previous table.

import java.util.*;
public class Employee {
Scanner in = new Scanner(System.in);
String Name;
String Address;
String Department;
int ID;
int Salary;

[code]....

this is my out put

Please choose a number:
1-Add a new employee
2-Update employee's info
3-Remove employee's info
4-Exit
1
Enter name:
Enter address:
2
Enter department:
3
Enter ID:
4
Enter salary:

now:

1- why are not my adding coming out in the output only the Enter name & Enter address ??

2- how can I add names and ID's and information to test that program

View Replies View Related

String Class Is Not Immutable - Can Reassign Another Value To Same Variable

Feb 26, 2015

public static void main(String[] args) {
String str1="Java";
str1="one";
System.out.println("str1="+str1);
}

String object is stored in a private final char array in String.java.
private final char value[];

The basic characteristic of a final variable is that it can initialize a value only once. By marking the variable value as final, the class String makes sure that it can’t be reassigned a value.

so the String objects can be initialized only once but the above code shows that str1 was initialized first with "Java", then it can be re-assigned value "one" bcos the output is one. If it can be re-initialized, basic characteristic of final variable is not satisified and hence how can we call String objects are immutable?

View Replies View Related

Create Dynamic String Array If Don't Know Number Of Strings In The Beginning?

Feb 21, 2014

how to create dynamic string array if we dont know number of strings in the beginning?

View Replies View Related

Phone Number Class - Int Cannot Be Converted To String

Apr 5, 2014

import java.util.*;
public class PhoneNumber {
private int areacode;
private int number;
private int ext;
PhoneNumber() {

[Code] .....

I just can't seem to get it completely correct.

PhoneNumber.java:35: error: incompatible types: int cannot be converted to String
areacode = Integer.parseInt(str[0]);
^
PhoneNumber.java:38: error: cannot find symbol
for(i = 0; i < number.length; i++){
^
symbol: variable length

[Code] ......

View Replies View Related

Reference Variable - Create Another Variable And Set It Equal To First

Jan 11, 2015

Given a reference variable : Car c1 = new Car();

when we create another variable and set it equal to the first : Car c2 = c1;

we're pointing c2 at the same car object that c1 points to (as opposed to pointing c2 at c1, which in turn points at the car). So if we have code like,

Car c1 = new Car();
Car[] cA = {c1, c1, c1, c1};

are we doing the same? Are we creating four *new* reference variables, each of which points at the same car (again as opposed to pointing them at c1 itself)? I think so, but want to make sure I'm understanding this correctly.

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

Create Class Called Factorial Algorithm Which Will Compute / Print Factorial Of Integer Number On Screen

Dec 27, 2014

1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen

2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)

View Replies View Related

How To Use Value Of String Variable Cel1 As Variable Name

May 23, 2014

I have a JFrame jf and JPanel jp on it. jp has five TextFields named cel1, cel2.. cel5. I wish to construct a String Cel + for loop index and run a for loop to reset the values of all the text fields using a single statement such as cel1.SetText("abc"). Similar things can be done in foxfro. How does one do it in java?

View Replies View Related

How To Create Simple Random Number Generator For Number Between 1 -10

May 18, 2015

I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.

View Replies View Related

Error Passing Value Of A Variable From One Class To Main Method Of Another Class

Jan 8, 2014

I've 3 classes.

1. Circle
2. GetInputFromUser
3. testCircle

package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;

[Code] .....

In the testCircle class, in the line: getRadius = ui1.GetInput();

It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

And when I do: getRadius = ui1.GetInput(rad);

It's showing the error: rad cannot be resolved

View Replies View Related

Create A Class That Will Accept Dates In Various Formats And Create A Range

Feb 1, 2014

In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.

package com.scg.athrowaway;
import java.util.Calendar;
import java.util.Date;
public class DateRange {
private Date startDate;
private Date endDate;

[code].....

View Replies View Related

How To Get User Input And Create Variable

Sep 16, 2014

Okay, so I know how to get user input and create a variable from the input, create a basic addition sum etc...

So I have this code:

package calc;
import java.util.Scanner;
class calc{
private static final double add = 0;
private static final double subtract = 0;
public static void main(String args[]){

[Code] .....

I'm basically trying to make it so that when the user enters tnum, tnum2, tnum3 and tnum4, their answer turns to the variable which has to be either true or false to make the boolean work. I don't know really how to do this. I want to make it so that if they enter yes, then that makes the boolean true and the numbers will multiply and create the answer variable. If they enter no then the boolean is false and it moves onto the next if statement. How can I do this?

View Replies View Related

I/O Arrays - Count Number Of Repetitiveness In String For The Number

May 19, 2014

//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones

import java.io.*;
import java.util.*;
public class Lottery2

[Code] ....

when I run it the array gets sorted but how do i keep the data in other words

what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved