Question

In: Computer Science

This class contains the main method. In this class you should: Ask the user for the...

This class contains the main method. In this class you should:

  1. Ask the user for the name, job tilte, and salary.
  2. Instantiate a Employee object with those parameters.
  3. Use the accessor methods to check the value of all three instance variables and print them.
  4. Ask the user to enter a percentage to raise the salary by.
  5. Use the raise method to increase the salary.
  6. Use the salary accessor check the new value of salary and print it.

Solutions

Expert Solution

Code:

====


public class EmployeeDemo {
   public static void main(String[] args) {
       Employee emp = new Employee("ABC", "BCD", 10000.00);
       System.out.println("Employee name: "+emp.getName());
       System.out.println("Employee job title: "+emp.getJobTitle());
       System.out.println("Employee salary: "+emp.getSalary());
       System.out.println("Calling salary raise method with 25%");
       emp.raiseSalary(25.0);
       System.out.println("Employee salary after 25% hike: "+emp.getSalary());
   }
}

class Employee{
   private String name;
   private String jobTitle;
   private double salary;
   public Employee(String name, String jobTitle, double salary) {
       super();
       this.name = name;
       this.jobTitle = jobTitle;
       this.salary = salary;
   }
   public String getName() {
       return name;
   }
   public String getJobTitle() {
       return jobTitle;
   }
   public double getSalary() {
       return salary;
   }
  
   public void raiseSalary(double perc) {
       this.salary = (perc*salary/100)+salary;
   }  
  
}

output:

=====


Related Solutions

Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
You are to write a class StringPlay that has only a main method. This class contains...
You are to write a class StringPlay that has only a main method. This class contains all interaction with the user. The main method Uses a Scanner to accept user input Maintains a “current” String Uses a sentinel-controlled loop to accept multiple user commands, or exit The program displays a message asking the user to enter one of the following commands a – enter a new value for current b – padLeft asks the user for the number of characters...
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input...
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input two integers (one by one), add the two integers, and return the sum. By using java.util.Scanner to get user input; The method may not compile due to Scanner Class which need to add a "throws" statement onto the end of the method header because some lines may throw exceptions Refer to the Java API documentation on Scanner to figure out which specific Exception should...
Create a new class called Account with a main method that contains the following: • A...
Create a new class called Account with a main method that contains the following: • A static variable called numAccounts, initialized to 0. • A constructor method that will add 1 to the numAccounts variable each time a new Account object is created. • A static method called getNumAccounts(). It should return numAccounts. Test the functionality in the main method of Account by creating a few Account objects, then print out the number of accounts
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a month, then determine what season it is based on that input. Write a method that takes in a month and day and returns which season it is (“Spring”, “Summer”, “Fall”, “Winter”). Your main method should be the only one that includes a print statement. Note the first days of each season: • March 19th – Spring • June 20st – Summer • September 22nd...
.......Subject Java..... main() main() will ask the user for input and then call functions to do...
.......Subject Java..... main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main(). Second function Create another function named computeBill that receives 2 parameters. It will receive the...
Part I: Have a program class named TestArrays This class should have a main() method that...
Part I: Have a program class named TestArrays This class should have a main() method that behaves as follows: Have an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following: Prompt the user to enter a number of inches Read the number of inches entered from the console Convert the inches into an equivalent number of miles, yards, feet, and inches. Output the results to the console. For example, if a user entered 100000 inches, the program would output: 100000 inches is equivalent to: Miles: 1 Yards: 1017 Feet: 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT