Jump to content

So this should give you a pretty good start. I'll leave all the specifics for you to google for. This is a fairly simple exercise. Ask questions if you're stuck.

// I've left the imports as a hint as to what// I used to get a simple working project.import java.io.BufferedWriter;import java.io.FileWriter;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;// simple employee class with basic info for each employee// object, with getters and setters.class Employee {        private String name;    private String id;    private int wage;    private int hours;        public Employee(String name, String id, int wage, int hours) {        this.name = name;        this.id = id;        this.wage = wage;        this.hours = hours;    }        public String getID() { return id; }    public void setID(String id) { id = id; }    public String getName() { return name; }    public void setName(String name) { this.name = name; }    public int getWage() { return wage; }    public void setWage(int wage) { this.wage = wage; }    public int getHours() { return hours; }    public void setHours(int hours) { this.hours = hours; }}// simple runner class with main method to test the PayrollFile.java methodsclass PayrollRunner {        public static void main(String[] args) {                // try creating an arraylist of employees                // consider using a loop to use PayrollFile.writeToFile()        // passing each employee from the arraylist on each loop                System.out.println("Done!");    }}public class PayrollFile {    public static void writeToFile(Employee emp) {        // create some kind of writer object                try {            // try to create and write to a file            // don't forget to close the output        } catch (Exception e) {            e.printStackTrace();        }    }    public static void searchFile(Employee emp) {    }    public static void outputFile() {    }}

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
https://linustechtips.com/topic/392116-help-with-java/#findComment-5292321
Share on other sites

Link to post
Share on other sites

I Apologize for the late reply.  The Assignment is pretty much finished. Thank you all for your replies as they did actually prove helpful. Just for curiosity's sake as I have already handed it in, do you have any idea how you would solve the following problem?

 

The user input for employee ID must only be accepted if it is the letter E followed by 4 digits. Use the Java API to view the methods in the String class and/or Character class for appropriate methods that could assist you in validating the user input for employee ID.

 

 

This is part of the code i came up with but I can't find the appropriate if statement for employeeID

 

 

 

System.out.print("Please enter Employee ID: ");
employeeID = input.next();
if (employeeID //I need help here )
{
System.out.print("Employee ID must start with E and be followed by 4 digits");
}
 
System.out.print("Please enter First Name: ");
firstName = input.next();
 
System.out.print("Please enter Last Name: ");
lastname = input.next();
 
System.out.print("Please enter Pay Category: ");
paycategory = input.nextInt();
if (paycategory < 1 || paycategory > 4)
{
System.out.print("Input for pay category must be 1,2,3,4");
}
 
System.out.print("Please enter Hours Worked: ");
hoursworked = input.nextDouble();
if (hoursworked < 1 || hoursworked > 80)
{
System.out.print("Input for hours worked must be between 1 and 80 ");
}
 
PaidEmployee s1 = new PaidEmployee(employeeID, firstName, lastname, hoursworked, paycategory);
PayrollFile p1 = new PayrollFile ();
p1.writeToFile();
Link to comment
https://linustechtips.com/topic/392116-help-with-java/#findComment-5319469
Share on other sites

Link to post
Share on other sites

 

I Apologize for the late reply.  The Assignment is pretty much finished. Thank you all for your replies as they did actually prove helpful. Just for curiosity's sake as I have already handed it in, do you have any idea how you would solve the following problem?

 

Yeah. Sure. ;)

 

Anyway, you can use a combination of charAt and isDigit or you can use regular expressions (which will be a little more complicated).

Link to comment
https://linustechtips.com/topic/392116-help-with-java/#findComment-5321762
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×