Question

In: Computer Science

Create a java program that has a code file with main() in it and another code...

Create a java program that has a code file with main() in it and another code file with a separate class. You will be creating objects of the class in the running program, just as the chapter example creates objects of the Account class.

Your system handles employee records and processes payroll for them. Create a class called Employee that holds the following information: first name, last name, monthly salary, and sales bonus. The class should have all the gets and sets and have a method to report the yearly salary (which is the monthly salary * 12 + the sales bonus.)

[Note: Before anyone asks. You cannot have spaces in variable names. So you might call the first one firstName, first_name, fname or any other appropriate and legal variable name. The write up above is telling you the information to be stored in English, not java.]

Create 2 objects of Employee in your main code class and display their names, monthly, and yearly salaries. Then give them each a 100 pay raise to their monthly salary. (Hint: use the get() to read it out to a variable, add 100, then use the set() to store it back in) Then display their names, monthly, and yearly salaries again.

[Note2: You can hard code the names, and salaries you are storing in the 2 employee objects or ask the user for them with a Scanner. Either way is fine. It is perfectly all right from a grading standpoint to just give it test values like the chapter example does.]

Please use beginner level Java and NetBeans 8.0

Solutions

Expert Solution

class Employee {
   private String fname;
   private String lname;
   private double mSalary;
   private double salesBonus;

   public Employee() {
       super();
   }

   // construtor to initialize the values
   public Employee(String aFname, String aLname, double aSalary, double aSalesBonus) {
       super();
       fname = aFname;
       lname = aLname;
       mSalary = aSalary;
       salesBonus = aSalesBonus;
   }

   // getters and setters
   public String getFname() {
       return fname;
   }

   public void setFname(String aFname) {
       fname = aFname;
   }

   public String getLname() {
       return lname;
   }

   public void setLname(String aLname) {
       lname = aLname;
   }

   public double getSalary() {
       return mSalary;
   }

   public void setSalary(double aSalary) {
       mSalary = aSalary;
   }

   public double getSalesBonus() {
       return salesBonus;
   }

   public void setSalesBonus(double aSalesBonus) {
       salesBonus = aSalesBonus;
   }

   // returns the yearlySalary
   public double yearlySalary() {
       return mSalary * 12 + salesBonus;
   }

   // toString will return all the object details
   public String toString() {
       return "Employee [Fist Name=" + fname + ", Last Name=" + lname + ", Monthly Salary=" + mSalary + ", salesBonus=" + salesBonus
               + "]";
   }

}

public class TestEmployee {
   public static void main(String[] args) {
       // creating 2 objects
       Employee e1 = new Employee("Uday", "Kumar", 5000, 500);
       Employee e2 = new Employee("Keerthi", "Reddy", 6000, 100);
       // printing 2 objects
       System.out.println(e1);
       System.out.println(e2);
       // giving 100 hike for both employees
       e1.setSalary(e1.getSalary() + 100);
       e2.setSalary(e2.getSalary() + 100);
       // printing 2 objects
       System.out.println("After giving 100 hike");
       System.out.println(e1);
       System.out.println(e2);

   }
}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

Create a new Java file, containing this code public class DataStatsUser { public static void main...
Create a new Java file, containing this code public class DataStatsUser { public static void main (String[] args) { DataStats d = new DataStats(6); d.append(1.1); d.append(2.1); d.append(3.1); System.out.println("final so far is: " + d.mean()); d.append(4.1); d.append(5.1); d.append(6.1); System.out.println("final mean is: " + d.mean()); } } This code depends on a class called DataStats, with the following API: public class DataStats { public DataStats(int N) { } // set up an array (to accept up to N doubles) and other member...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Using the code below from “LStack.h” file, write the code for a main program that takes...
Using the code below from “LStack.h” file, write the code for a main program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions { 25 + ( 3 – 6 ) * 8 } and 7 + 8 * 2 contains matching grouping symbols. However, the expression 5 + { ( 13 + 7 ) / 8 - 2 * 9 does not contain matching grouping symbols....
Java Code Question: The program is supposed to read a file and then do a little...
Java Code Question: The program is supposed to read a file and then do a little formatting and produce a new txt file. I have that functionality down. My problem is that I also need to get my program to correctly identify if a file is empty, but so far I've been unable to. Here is my program in full: import java.io.*; import java.util.Scanner; public class H1_43 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an...
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an error message if the input cannot be converted I can give an thumbs up! :)
Using Java (Swing) language(please hard code)... Create a program that has a textfield for the user...
Using Java (Swing) language(please hard code)... Create a program that has a textfield for the user to type in a set of input. Below that textfield have the following controls to show string manipulations: (1) A button that will change the entire textfield’s current text to uppercase. (2) A button with its own textfield for a search value, that will tell the position the search value appears in the textfield above. (3) A button that reports the current number of...
Using a minimum of 2 classes create a java program that writes data to a file...
Using a minimum of 2 classes create a java program that writes data to a file when stopped and reads data from a file when started. The data should be in a readable format and the program should work in a way that stopping and starting is irrelevant (e.g. all data doesn't have to save just the important elements.) Program should be unique and semi-complex in some way.
2. Create a java program that reads a file line by line and extract the first...
2. Create a java program that reads a file line by line and extract the first word.        The program will ask for the name of input and output file. Input file: words.txt today tomorrow sam peterson peter small roy pratt Output file: outwords.txt tomorrow peterson small pratt
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT