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
ADVERTISEMENT
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
View Related
Feb 24, 2015
I have table data I'm trying to read . However one column is populated with the word "null". I guess java does not like dealing with the word null and throws errors.
When I try a block like : if ( rsrow.getString(insCol) = "null") {
I get and error .
If I try :
cmp = rsrow.getString(insCol);If I try:If I try:
if (cmp = "null") {
I get an error
If I try to use a replace function like:
System.out.println(cmp.replace("null", "0"));
Just to see if replace works I get and error.
What is the BEST way to replace this string value with something like "0" when I come across it with out jave throwing an error? I want it such that every time I come across the word "null" I can repalce it with "0".
Something like:
if (rsrow.getString(insCol) = "null") {rowofdata = rowofdata + "'0',"; } else {rowofdata = rowofdata + "'" + rsrow.getString(insCol) + "',";}
View Replies
View Related
Aug 15, 2014
I need to get the html in string when i hit the hit the jsp in servlets basically i need to put the output of jsp in pdf file when i hit one link i need to download that data in pdf file. I am using itextpdf.
Sample code
pResponse.setContentType("application/pdf");
((HttpServletResponse) pResponse).setHeader("Content-Disposition", "attachment; filename=report.pdf");
//Get the output stream for writing PDF object
OutputStream outStream=pResponse.getOutputStream();
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
[Code] ....
I need to convert the sample download.jsp to html so that i can parse
// XMLWorkerHelper.getInstance().parseXHtml(docWriter, document,new FileInputStream(jspPath),new FileInputStream(csspath) ,null ,new XMLWorkerFontProvider());
View Replies
View Related
Oct 7, 2014
I'm currently taking a Java Programming module in college, the program we are using is jGrasp and I'm currently stuck on one aspect of the language.
I did VB last year and I enjoyed it and got good grades so I'm comfortable with Java in terms of compiling the code correctly and getting it to run with no errors.
But for a project we got yesterday, the user must be able to enter data (e.g. an answer) into jGrasp without using a GUI. This is the case because we won't be dealing with GUIs until next semester.
I'm able to handle the rest of the project, but the part which I can't figure out is how the user can interact with jGrasp without the aid of a GUI.
View Replies
View Related
Feb 15, 2015
I am suppose to design a problem the prompts the user to enter a String. Based on the input from the user, have the program prompt with a full description of the playing card entered. Below is a table of the notation and meaning:
Notation Meaning
A Ace
2...10 Card Values
J Jack
Q Queen
K King
D Diamonds
H Hearts
S Spades
C Clubs
Use the .charAt(...) to extract each character from the user's input and build a switch statement to determine the full description.
import java.util.Scanner;
public class PlayingCardIdentifier {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a card notation: ");
String s = input.nextLine();
[code]...
View Replies
View Related
Feb 7, 2014
I need to allow users only enter integer into a String variable, "input" and I am not sure what statement to use.
import java.util.Scanner;
public class assq2b {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input,b;
[Code] ......
View Replies
View Related
Sep 18, 2014
double a = scan.nextInt();
double b = scan.nextInt();
double c = scan.nextInt();
//**********************************Equations**********************************
System.out.println ();
double sum = a + b + c;
System.out.printf("Sum = %d", sum);
Heres the error I'm getting
Enter three positive integers separated by spaces, then press enter:
15 20 9
Sum = Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at project2.main(project2.java:52)
View Replies
View Related
Sep 13, 2014
How to improve my code. I finally was able to create a program that gives you the corresponding letter grade, when you enter in a numeric grade without using an array. The only issue left is that I have to be able to enter 5 grades at a time, and it give me the letter grade for all 5. I have the programming working, but only am able to enter 1 at a time. I am not sure what kind of loop or if I am supposed to use a loop.
public static void main(String[] args){
{
int grade = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter : ");
grade = input.nextInt();
if (grade >= 90)
[Code] .....
View Replies
View Related
Mar 7, 2014
I'am trying to converting string data into xml data using xml beans and StringEscapeUtils.This is work fine but in one case it if the data contains special characters.
Code snippet
--------------------
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
public class ParseXMLData {
public static XmlObject parseXML(String stringXML) {
XmlObject xmlObject = null;
[Code] ....
success case
---------------------------
i/p------<aaa><bbb>This converts string to xml</bbb></aaa>
o/p---<aaa><bbb>This converts string to xml</bbb></aaa>
Failer case
-----------------
i/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa>
expected o/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa>
Observed that it converts < to '<' but as per xml rules, if data contains '< ' it fails. I want to convert staring and end tags to xml format and if data in b/w middle of starting and ending tags do'n need to convert it. How to do it.
View Replies
View Related
Apr 14, 2014
I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.
View Replies
View Related
Apr 9, 2015
I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?
View Replies
View Related
Mar 21, 2015
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
FileWriter fw = new FileWriter("dbs3.java");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
System.out.println("NEW EMPLOYEE DATA SHEET");
System.out.print("Number of new employees: ");
int number = input.nextInt();
[Code] ....
View Replies
View Related
Apr 23, 2015
I am trying to remove a line based on user input. myFile.txt looks like:
Matt
Brian
John
However when I enter "Brian" (to remove this line), It is deleted on the temp file (myTempFile.txt), but not renamed back to the original file (myFile).
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
[code]....
View Replies
View Related
Feb 8, 2015
I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .
Java Code:
public static void main(String[] args) {
// TODO Auto-generated method stub
// Variables Declaration Section
//******************************
BufferedReader br;
String sCurrentLine;
String str;
[Code] ....
My issue is that the 'str' value is not initialized, but if I initialize it, it ruins the code. I'm not sure what to do in the situation.
View Replies
View Related
Apr 17, 2015
I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.
Here's my code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {
[Code] .....
It's not doing anything, I don't understand why.
View Replies
View Related
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
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
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
Jul 14, 2014
New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows
(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.
[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
[Code]....
View Replies
View Related
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
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
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
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
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
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