Question

URGENT! I NEED THIS WITHIN TWO HOURS TO PREPARE TONIGHT FOR MY FINAL EXAM TOMORROW! Create...

URGENT! I NEED THIS WITHIN TWO HOURS TO PREPARE TONIGHT FOR MY FINAL EXAM TOMORROW!

Create a class called Employee that includes three instance variables—a first name, a last name, and a monthly salary. Code the default (no-args, empty) constructor. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here is the code you need:

class Employee
{
String first_name;
String last_name;
double monthly_salary;
  
Employee()
{
first_name="";
last_name="";
monthly_salary=0;
}
  
public String get_first_name()
{
return first_name;
}
  
public String get_last_name()
{
return last_name;
}
  
public void set_first_name(String first_name)
{
this.first_name = first_name;
}
  
public void set_last_name(String last_name)
{
this.last_name = last_name;
}
  
public double get_monthly_salary()
{
return monthly_salary;
}
  
public void set_monthly_salary(double monthly_salary)
{
if(monthly_salary>=0)
this.monthly_salary = monthly_salary;
}
}
public class Main
{
   public static void main(String[] args) {
  
       Employee ob = new Employee();
       ob.set_first_name("ABC");
       ob.set_last_name("DEF");
       ob.set_monthly_salary(250);
      
       System.out.println(ob.get_first_name()+" "+ob.get_last_name());
System.out.println(ob.get_monthly_salary());
   }
}

Output:

ABC DEF 250.0

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
URGENT! I NEED THIS WITHIN TWO HOURS TO PREPARE TONIGHT FOR MY FINAL EXAM TOMORROW! Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Employee that includes three instance variables—a first name, a last name, and...

    Create a class called Employee that includes three instance variables—a first name, a last name, and a monthly salary. Code the default (no-args, empty) constructor. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.

  • Create another Java class named EmployeeMain within the same project, which includes the main method. a....

    Create another Java class named EmployeeMain within the same project, which includes the main method. a. Include another class named Employee in the same Java file. This class has the following instance variables and instance methods. Define all the instance/static variables with private access modifier and constructors, instance/static methods with public access modifier. Instance Variables empID: int employeeName: String basicSalary: double Constructor Set the value for empID. Instance Methods Get and set methods for all instance variables. displayEmployee: Display the...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • In one file create an Employee class as per the following specifications: three private instance variables:...

    In one file create an Employee class as per the following specifications: three private instance variables: name (String), startingSalary (int), yearlyIncrement (int) a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values. get and set methods for each of the instance variables. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using...

  • Create a class called Customer that includes three pieces of information as instance variables - a...

    Create a class called Customer that includes three pieces of information as instance variables - a firstname (type string), a last name (type string) and a credit limit (double) Your class should have a constructor that initializes the three values. a. Provide a customer that initializes these three instance variables. Validate credit limit; it must be greater than 0.0. b. Provide set and get methods for each instance variable. Validate credit limit; it must be greater than 0.0. Write a...

  • i was able to make sense on the others but this two i need help Name:...

    i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue                            Access modifier: public Parameters:...

  • Complete each of the following exercises from the Deitel book, using the indicated C# project names....

    Complete each of the following exercises from the Deitel book, using the indicated C# project names. You should use a .NET Framework Console application type for each project. All projects should be part of a single solution named: Cs2Apps. How to setup multiple Projects in one Visual Studio Solution When creating the first Project, make sure to uncheck the box for putting the solution and the project in the same folder. This will create a separate folder with the solution...

  • E2a: Create a class called Employee that includes three pieces of information as data members---a first...

    E2a: Create a class called Employee that includes three pieces of information as data members---a first name (char array), last name (char array) and a monthly salary (integer). Your class should have a constructor that initializes the three data members. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT