Question

12. Predict the output generated at the marked println lines in the following program. The program...

12. Predict the output generated at the marked println lines in the following program. The program makes use of the class Employee that is also given. Please enter your answers in the space provided below the code.

public class Employee {

private String name;

private double salary;

public Employee(String name, double salary) {

this.name = name;

this.salary = salary;

}

public String getName() {

return name;

}

public double getSalary() {

return salary;

}

public void raiseSalary(double percent) {

double raise = salary * percent/100;

salary += raise;

}

}

public class Pr3 {

public static void main(String[] args) {

double percent = 10;

System.out.println("percent = " + percent); //---------------------(a)

doubleValue(percent);

System.out.println("percent = " + percent); //---------------------(b)

Employee john = new Employee("John", 75000);

System.out.println("Salary: $" + john.getSalary()); //-----------------(c)

doubleSalary(john);

System.out.println("Salary: $" + john.getSalary()); //-----------------(d)

Employee a = new Employee("Emily", 90000);

Employee b = new Employee("Henry", 100000);

System.out.println("a’s Name: " + a.getName()); //-------------------(e)

System.out.println("b’s name: " + b.getName()); //-------------------(f)

swap(a, b);

System.out.println("a’s Name: " + a.getName()); //-------------------(g)

System.out.println("b’s name: " + b.getName()); //-------------------(h)

}

public static void doubleValue(double x) {

x = 2 * x;

System.out.println("End of method: x = " + x); //-------------------(i)

}

public static void doubleSalary(Employee y) {

y.raiseSalary(200);

System.out.println("End of method: Salary : " + y.getSalary()); //-----(j)

}

public static void swap(Employee x, Employee y) {

Employee temp = x;

x = y;

y = temp;

System.out.println("End of method: x is " + x.getName()); //-----------(k)

System.out.println("End of method: y is " + y.getName()); //-----------(l)

}

} (a) Answer(a):

(b) Answer(b):

(c) Answer(c):

(d) Answer(d):

(e) Answer(b):

(f) Answer(e):

g) Answer(f):

(h) Answer(g):

(i) Answer(h):

(j) Answer(i): (

k) Answer(j):

(l) Answer(k):

(m) Answer(l):

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

(a) Answer(a): 10.0

(b) Answer(b): 20.0

(c) Answer(c): $75000.0

(d) Answer(d):  $225000.0

(e) Answer(e): Emily

(f) Answer(f): Henry

g) Answer(g): Emily

(h) Answer(h): Henry

(i) Answer(i): 20.0

(j) Answer(j):  225000.0

k) Answer(l): Henry

(l) Answer(l): Emily

// Screenshot of the code & output

// Code to copy

Employee.java

public class Employee
{
   private String name;
   private double salary;

   public Employee(String name, double salary)
   {
       this.name = name;  
       this.salary = salary;

   }

   public String getName()
   {
       return name;

   }

   public double getSalary()
   {
       return salary;

   }

   public void raiseSalary(double percent)
   {
       double raise = salary * percent/100;  
       salary += raise;

   }

}

Pr3.java

public class Pr3
{

   public static void main(String[] args)
       {
           double percent = 10;
  
           System.out.println("percent = " + percent); //---------------------(a)
  
           doubleValue(percent);
  
           System.out.println("percent = " + percent); //---------------------(b)
  
           Employee john = new Employee("John", 75000);
  
           System.out.println("Salary: $" + john.getSalary()); //-----------------(c)
  
           doubleSalary(john);
  
           System.out.println("Salary: $" + john.getSalary()); //-----------------(d)
  
           Employee a = new Employee("Emily", 90000);
  
           Employee b = new Employee("Henry", 100000);
  
           System.out.println("a’s Name: " + a.getName()); //-------------------(e)
  
           System.out.println("b’s name: " + b.getName()); //-------------------(f)
  
           swap(a, b);
  
           System.out.println("a’s Name: " + a.getName()); //-------------------(g)
  
           System.out.println("b’s name: " + b.getName()); //-------------------(h)

       }

       public static void doubleValue(double x)
       {
           x = 2 * x;  
           System.out.println("End of method: x = " + x); //-------------------(i)

       }

       public static void doubleSalary(Employee y)
       {  
           y.raiseSalary(200);  
           System.out.println("End of method: Salary : " + y.getSalary()); //-----(j)

       }

       public static void swap(Employee x, Employee y)
       {
           Employee temp = x;  
           x = y;  
           y = temp;  
           System.out.println("End of method: x is " + x.getName()); //-----------(k)  
           System.out.println("End of method: y is " + y.getName()); //-----------(l)  
           }
}

Add a comment
Know the answer?
Add Answer to:
12. Predict the output generated at the marked println lines in the following program. The program...
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
  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • I do not understand why the swap methods are not doing anything for the variable x...

    I do not understand why the swap methods are not doing anything for the variable x and y in the main method. When are variables affected by the other methods and when they do not get modified by the other methods? (The answer is A). Thank you so much in advance, 24. What does the following code print? public class Swapper [ public static void main (String[] args) I int [ ] x = int [ ] y = {4,5,6,7,8};...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • Create a program called GeneralizedBubbleSort that will make use of the Comparable Interface in the same...

    Create a program called GeneralizedBubbleSort that will make use of the Comparable Interface in the same way it is used in the GeneralizedSelectionSort. You should use the attached ComparableDemo to test your program. public class ComparableDemo { public static void main(String[] args) { Double[] d = new Double[10]; for (int i = 0; i < d.length; i++) d[i] = new Double(d.length - i); System.out.println("Before sorting:"); int i; for (i = 0; i < d.length; i++) System.out.print(d[i].doubleValue( ) + ", ");...

  • In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate...

    In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees. ************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************ import java.io.*; public class ManagerTest { public static void main(String[] args) { InputStreamReader...

  • What is the output for the following program codes? a) [ 0.5 Mark ] class A...

    What is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); }} class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); }} OUTPUT: b) [ 0.5 Mark ] class Parent { public void getBike(){ System.out.println("Suzuki Bike"); }} class Child extends Parent {...

  • java help!im a littleconfused with this swap. Could someone please explain the steps. possibly with a...

    java help!im a littleconfused with this swap. Could someone please explain the steps. possibly with a memory diagram? thanks!! public class tricky {       public static void tricky1(Point arg1, Point arg2) {     arg1.x = 100;     arg1.y = 100;     Point temp = arg1;     arg1 = arg2;     arg2 = temp; } public static void main(String [] args) {     Point pnt1 = new Point(0,0);     Point pnt2 = new Point(0,0);     System.out.println("X: " + pnt1.x +...

  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • I need help in getting the second output to show both the commission rate and the...

    I need help in getting the second output to show both the commission rate and the earnings for the String method output package CompemsationTypes; public class BasePlusCommissionEmployee extends CommissionEmployee { public void setGrossSales(double grossSales) { super.setGrossSales(grossSales); } public double getGrossSales() { return super.getGrossSales(); } public void setCommissionRate(double commissionRate) { super.setCommissionRate(commissionRate); } public double getCommissionRate() { return super.getCommissionRate(); } public String getFirstName() { return super.getFirstName(); } public String getLastName() { return super.getLastName(); } public String getSocialSecurityNumber() { return super.getSocialSecurityNumber(); } private...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

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
ADVERTISEMENT