Questions
Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model...

Assignment 2 - Employee Hierarchy

In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model the relationship between two types of employees and how to calculate the earnings for each. Another way to look at the problem is that CommissionEmployees and BasePlusCommissionEmployees are each Employees and that each has a different CompensationModel object.

A CompensationModel would provide an earnings method. Classes or subclasses of CompensationModel would contain the details of a particular Employee's compensation:

  • CommissionCompensationModel - For Employees who are paid by commission, the CommissionCompensationModel class would contain grossSales and commissionRate instance variables, and would define an earnings method to return grossSales * commissionRate.
  • BasePlusCommissionCompensationModel - For Employees who are paid a base salary and commission, this subclass of CommissionCompensationModel would contain an instance variable of baseSalary and would define the earnings method to return super.earnings() + baseSalary.

Each of these classes would contain a toString() method that displays the Compensation Model information as illustrated in the sample output.

This approach is more flexible than our original hierarchy. For example, consider an Employee who gets promoted. With the approach described here, you can simply change that Employee's CompensationModel by assigning the composed CompensationModel reference an appropriate subclass object. With the CommissionEmployee - BasePlusCommissionEmployee hierarchy, you'd need to change the Employee's type by creating a new object of the appropriate class and moving data from the old object to the new one.

Implement the Employee class and CompensationModel hierarchy discussed in this exercise. In addition to the firstName, lastName, socialSecurityNumber and CommisionCompensationModel instance variables, class Employee should provide:

  • A constructor that receives three Strings and a CommissionCompensationModel to initialize the instance variables.
  • A set method that allows the client code to change an Employee's CompensationModel.
  • An earnings method that calls the CompensationModel's earning method and returns the result.
  • A toString() method that displays all the information about the Employee as illustrated in the sample output.

Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes as in the code demonstrated in Figures 9.10 and 9.11 in the book.

Use the following code in your main function to test your classes, just copy and paste it into your main method:

        // Create the two employees with their compensation models.
       
        CommissionCompensationModel commissionModel = new CommissionCompensationModel(2000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModel = new BasePlusCommissionCompensationModel(2000.00, 0.05, 600.00);
       
        Employee employee1 = new Employee("John", "Smith", "111-11-1111", commissionModel);
        Employee employee2 = new Employee("Sue", "Jones", "222-22-2222", basePlusCommissionModel);
       
        System.out.printf("%s%n%s%n", employee1, employee2);
        System.out.printf("%s%s%s%s%s%8.2f%n%n", "Earnings for ", employee1.getFirstName(), " ", employee1.getLastName(), ": ", employee1.earnings());
       
        // Change the compensation model for the two employees.
       
        CommissionCompensationModel commissionModelNew = new CommissionCompensationModel(5000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModelNew = new BasePlusCommissionCompensationModel(4000.00, 0.05, 800.00);
       
        // Set the new compensation models for the employees.
        employee1.setCompensation(basePlusCommissionModelNew);
        employee2.setCompensation(commissionModelNew);
       
        // Print out the new information for the two employees.
        System.out.printf("%s%n%s%n", employee1, employee2);

The output from your program should look like the following:

run:
John Smith
Social Security Number: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.04
Earnings:    80.00

Sue Jones

Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.05
Base Salary of:   600.00
Earnings:   700.00

Earnings for John Smith:    80.00

John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of:   800.00
Earnings: 1000.00

Sue Jones

Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings:   200.00

In: Computer Science

Write a python program that implements a Brute Force attack on Shift Cipher. In this program...

Write a python program that implements a Brute Force attack on Shift Cipher. In this program there is only one input - ciphertext - is a sequence of UPPER CASE letters. To make it easy, the program will be interactive and will output all possible plaintexts and ask user which plaintext makes sense. As soon as user will decide YES, the program will stop searching and print the desired plaintext and the found SHIFT KEY.

In: Computer Science

How to write a method that performs matrix multiplication with three rectangle arrays along with their...

How to write a method that performs matrix multiplication with three rectangle arrays along with their dimensions as parameters using Java programming?

In: Computer Science

1. Use the enum keyword or a C++ class to create a new type Boolean with...

1. Use the enum keyword or a C++ class to create a new type Boolean with the two values F and T defined. Use the C++ class/struct keyword and an array to create a list of pairs that cover all possible combinations of the 2 Boolean constants you defined.

2. Extend the same program and implement conjunction and disjunction functionality in a separate library (mylib.h/mylib.cpp). Use your implementation to print truth tables for both.

3. Further extend the same program by adding xdisjunction and negation functionality. Use your implementation to print truth table for both.

4. Use functions developed (conjunction, disjunction, negation ...) in above assignment and implement Example 1.8 (a) Construct the truth table of the proposition (p∧q)∨(∼ p∨∼ q). Determine if this proposition is a tautology. (b) Show that p∨∼ p is a tautology.

5. Use functions developed in mylib (mylib.h/mylib.cpp) separate library (conjunction, disjunction, negation ...) in previous assignments and implement Example 1.9

(a) Show that ∼ (p∨q) ≡∼ p∧∼ q.

(b) Show that ∼ (p∧q) ≡∼ p∨∼ q.

(c) Show that ∼ (∼ p) ≡ p.

Parts (a) and (b) are known as DeMorgan’s laws.

In: Computer Science

1. Translate the following code into MIPS code. B[i + 10] = B[i -2] + 40;...

1. Translate the following code into MIPS code.

B[i + 10] = B[i -2] + 40;

i = i + 10;
B[3] = B[i - 1];

a) Assume B is an array of integers (each integer takes 4 bytes). B's address
is stored at register $10. Also assume that the compiler associates the
variable i to the register $11.
b) Assume B is an array of characters (each character takes one byte). B's address
is stored at register $10. Also assume that the compiler associates the variable i to   the register $11.


2. Translate the following code into MIPS code.
       

B [0] = 5;

for (i = 1 ; i < 50 ; i = i + 2)

{

           

            B[i] =i + B[i-1];

}

Assume the compiler associates the variable i to the register $t0. Also, assume B is an array of integers and its address is stored at register $s1.   


3. Translate the following code into MIPS code.

           

            for (i=0; i<=5; i=i+1)

                        {

                        if (i != k)

                                    k=(k *2)-1;

                                    else

                                    k=(k *4)+1;

                        }

Assume the compiler associates the variables i and k to the registers $s0 and $s1, respectively.

4. Translate the following code into MIPS code.

Test (int i, int j)

                        {

                        int k;

                        k = Double(i+1) + Double (j-10)

                        return k;

                        }

Sub (int m)

                        {

                        int g;

                        g = m + m;

                        return g;

                        }

Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.

In: Computer Science

Create a JavaScript program that asks for the input of at least five words (a total...

Create a JavaScript program that asks for the input of at least five words (a total of 25+ characters) string from a user and performs the following functions to it:

STRING METHODS

  1. Check to see if the string input meets the 25+ character limit. If it does not, send a message and ask for another string.
  2. Output the original string as it was entered onto the web page document.
  3. Output the original string in all lower case letters. Do not change the original string value.
  4. Output the original string in all upper case letters. Do not change the original string value.
  5. Output a message indicating the total characters within the string.
  6. Output the characters between index 5 and index 10.
  7. Output 5 characters starting from position 15.
  8. Combine the string with another string of your choice that also has 25+ characters. The new string should be at the end of the first string. Output the combined string.
  9. Finally, split your string into an array for the 2nd part of the assignment. Each word (not each character) should be a value for the array.

Example: Input 5 words

Note: This is an example with example input. Your input will make this much different so don't hard code my examples into your code. The program should ask for input for the 5 words.

Enters: I think therefore I am

Check to make sure it is 25 characters in length. (step 1) - it is not, it is only 22 characters so have them try again.

Enters: Failure is success in progress (this is over 25 characters)

Output: Failure is success in progress (step 2)

Output in lowercase: failure is success in progress (step 3)

Output in uppercase: FAILURE IS SUCCESS IN PROGRESS (step 4)

Output character count: Your string has 30 characters. (step 5)

Output characters between index 5 and 10. re is (step 6)

Output 5 characters starting from position 15. ess i (step 7)

Combine with a 25+ character string you have created: Failure is success in progress Success is dependent on effort (step 8)

ARRAY METHODS - Working with the same string as the String Methods program, continue your program by completing these steps.

  1. Output the list of array values.
  2. Output the total number of items in the array.
  3. Remove the first item in the array. Output the new array values.
  4. Add the word "banana" to the end of the array. Output the new array values.
  5. Reverse the elements in the array. Output the new array values.
  6. Replace the item in the 2nd position/key with the word stardust. Output the new array values showing the word in the correct position.
  7. Sort the array in alphabetical order. Output the alphabetical list of array values.

Example continued: Array Methods

Your list should be output of all words in your combined string: (step 1)

failure
is
success
in
progress
Success
is
dependent
on
effort

Output: Your string contains 10 words. (step 2)

Output after removing the first array item (step 3)

is
success
in
progress
Success
is
dependent
on
effort

Output after adding the word banana to the end of the array (step 4)

is
success
progress
Success
is
dependent
on
effort
banana

Output after reversing the array elements (step 5)

banana
effort
on
dependent
is
Success
progress
success
is

Output after updating the second array item with the word stardust (step 6)

banana
effort
stardust
dependent
is
Success
progress
success
is

Output after sorting the array (step 7)

Success
banana
dependent
effort
is
is
progress
stardust
success

In: Computer Science

Please write a C++ program to find the largest number among three numbers using nested if...else...

Please write a C++ program to find the largest number among three numbers using nested if...else statements


You need to prompt the user to enter three integer numbers from the keyboard, and then display the largest number among the three.
Please create a function to find the largest number among three numbers, and call the maxAmongThree function in the main function.

In: Computer Science

Using the code below as a template, write a program that asks the user to enter...

Using the code below as a template, write a program that asks the user to enter two integers, and finds and prints their greatest common denominator (GCD) in Java!

package cp213;

import java.util.Scanner;

public class Lab01 {

    /**
     * @param a
     * @param b
     * @return
     */
    public static int gcd(int a, int b) {

        // your code here

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        int a = 0;
        int b = 0;
        int c = 0;

        // Read an integer from the keyboard.
        System.out.print("Enter a (0 to quit): ");
        a = keyboard.nextInt();

        // your code here

        // gcd function call
        c = Lab01.gcd( a, b );

        // your code here

    }

}

In: Computer Science

The multi-merge sort algorithm (M&M sort) works like merge sort, except that instead of dividing the...

The multi-merge sort algorithm (M&M sort) works like merge sort, except that instead of dividing the array into 2 partitions, it divides the array into p partitions. It recursively sorts each of the p partitions and then merges the results doing a p-way merge (except, of course, for the base case of a singleton or empty array). (a) Write the recurrence for T(n) for M&M sort for the case where p is a constant. Then, give a closed-form solution to the recurrence using the Master Theorem, and note which case applied. (b) Now assume that p is not a constant, but rather p(n) = n/10. Rewrite T(n) for this case. Then, give a closed form solution. Use the Master Theorem if it applies, or any other means of arriving at the result.

In: Computer Science

Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based...

Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following tasks based on the Linux Fundamentals lecture. For this lab, take screenshots for all major steps completed to illustrate that each task was successfully completed (the same method as would be used for other labs).

9. Display your current directory in the terminal

10. Display your current directories contents including the inode value and permissions for each file and directory

11. Without using an editor, create a file with no contents called billy_bobs_diary.txt in the user BillyBob’s home directory

12. Edit your file using nano or vi and add the following string into the contents of the file: “This is my super-duper secret diary. No one shall read my diary for as long as I live. I will encrypt this with the moistest strongest encryption that is known to man. P.S. I really love kitten memes”

13. Rename the file to secret_file.txt using the command line

14. Move the file, secret_file.txt, to a directory named secret located in /opt

15. Create a copy of the file, secret_file.txt, and place it in BillyBob’s home directory

16. On the file, secret_file.txt, located in /opt/secret, change the file permissions so that all users have read/write access, but not execute

17. After you get weirded out that your professor just did that for fun, change the permissions so that the owning user has r/w, the owning group has r/w, and all other users have read only access

18. Display the contents of secret_file.txt via the command line without using a text editor

19. Append the following line to the document without using a text editor: “I have hidden this file so cleverly, that no one will ever find it. My secrets are safe here.”

20. Using the command line, clone the GitHub repository below into the /opt directory. Use the ReadMe to introduce yourself to the mystery scenario. After familiar with the scenario and the instructions, solve the mystery and take snapshots along the way, especially when you figure out who done it! GitHub Repository: https://github.com/veltman/clmystery

In: Computer Science

1. Obtain the following string: abcdefghijklmnopqrstuvwxyz (as input or using initialization) 2. Using recursion, write a...

1. Obtain the following string: abcdefghijklmnopqrstuvwxyz (as input or using initialization)

2. Using recursion, write a reverse function that reverses the characters in a string or character array given two indices (starting and ending). The string or the character array should reflect the reversal.

3. Read indices as input 11,18 (i.e. letters 12,19)

4. Call the reverse function to reverse letters: 12-19

5. Read indices as input 4,22 (i.e. letters 5,23)

6. Call the reverse function to reverse letters: 5,23

7. Using the reverse function, reverse the alphabet 8. Print the reversed string or character array.

Your output should contain:

abcdefghijksrqponmltuvwxyz

abcdwvutsrqponmlkjihgfexyz

zyxwvutsrqponmlkjihgfedcba

NOTE: your recursive function should modify the original string passed in as an argument, NOT make additional copies of the original string

In: Computer Science

Assume a 32-bit system, with a 2-level page table, with a page size of 4KiB (p1=10bits,...

Assume a 32-bit system, with a 2-level page table, with a page size of 4KiB (p1=10bits, p2=10bits, offset=12bits).

(i) A program on this system requires 16MiB in total: the program text segment uses 4MiB, the program data requires 2MiB, the program dynamically allocates 8MiB on the heap, and the stack utilises 2MiB. How many page-table pages are required for this process? (Don’t answer with just a number, explain your reasoning. Without your reasoning we cannot award part marks if your answer is incorrect.)

(ii) Describe the lookup steps within the page tables to find the physical address of the logical address 0x00403004.

(iii) If the reference time to access the physical memory frame is 20 nanoseconds. Assume that all required pages are in memory. How long does a paged memory reference take, if—
i. There is no TLB?
ii. There is a TLB, with an access speed of 0.05 nanoseconds, but the TLB does not contain information on the required page?
iii. There is a TLB, with an access speed of 0.05 nanoseconds, and the TLB contains information on this page?

Do not answer with just a number, explain your reasoning.

In: Computer Science

Write a C# program using repl.it that asks the user for three integers and prints the...

Write a C# program using repl.it that asks the user for three integers and prints the average value as a double. Example calculation (3 + 6 + 7) / 3 = 5.33333333333333 Given the data above, the output should be similar to: The average for the values entered is: 5.33333333333333 As always comments in your code are expected (what why how etc… ) Submit your repl.it link to the assignment dropbox text submission area.

In: Computer Science

Must be using Java Eclipse Please 4. Test program LinkedList.java, and make sure that you understand...

Must be using Java Eclipse Please

4. Test program LinkedList.java, and make sure that you understand each operation in the
program. (refer to linkedListApplication.java)

6. (Programming) Use LinkedList as a reference, add the following operations in the class
LinkedList;

a) Find the average data values of the linked list.
b) Find the node with largest key, and then delete the node. (Note, you must return
the node, not just the largest key)
c) Test ALL operations (Search, Insert, Delete, Append/Remove to/from the header)
in the Main method. (Also display the average of the data values of the linked list,
the largest key, the linked list before and after deleting the node with the largest
key;


7. (Programming) Modify LinkedList.java programs so that it handles employee objects.
Make your program menu-driven.

a) Find the average salary of the employees in the linked list.
b) Find the employee with largest ID, and then delete the node. (Note, you must return
the employee, not just the largest key, and delete it)
c) Test ALL operations (Search, Insert, Delete, Append/Remove to/from the header) in
the Main method. (Also display the average salary, the employee with largest ID, the
linked list before and after deleting the employee with the largest key;

LinkedList.java

import java.util.*;

public class LinkedList
{
   public Node header;

   public LinkedList()
   {
       header = null;
   }

   public final Node Search(int key)
   {
       Node current = header;
       while (current != null && current.item != key)
       {
           current = current.link;
       }
       return current;
   }

   public final void Append(int newItem)
   {
       Node newNode = new Node(newItem);
       newNode.link = header;
       header = newNode;
   }

   public final Node Remove()
   {
       Node x = header;
       if (header != null)
       {
           header = header.link;
       }
       return x;
   }

   public final Node searchPrevious(int key)
   {
       if (header == null)
       {
           return header;
       }
       else
       {
           Node current = header;
           while (!(current.link == null) && (current.link.item != key))
           {
               current = current.link;
           }
           return current;
       }
   }

   public final void Insert(int newItem, int preKey)
   {
       Node current;
       Node newNode = new Node(newItem);
       current = Search(preKey);
       if (current == null)
       {
           System.out.println("there is no such preKey!");
       }
       else
       {
           newNode.link = current.link;
           current.link = newNode;
       }
   }


   public final void Delete(int key)
   {
       if (header == null) // The list is empty!
       {
           System.out.println("The list is empty!");
       }
       else
       {
           if (header.item == key) // header to be deleted.
           {
               header = header.link;
           }
           else
           {
               Node p = searchPrevious(key);
               if (p.link == null)
               {
                   System.out.println("There is no such item!");
               }
               else
               {
                   p.link = p.link.link;
               }
           }
       }
   }

public final void ShowLinkedList()
{
if (header == null)
   System.out.println("The list is empty!");
else
{
Node current = header;
System.out.printf("%1$s->", current.item);
while (!(current.link == null))
{
current = current.link;
System.out.printf("%1$s->", current.item);

}
System.out.printf("null");
System.out.println();
}
}
   public final void PrintList()
   {
       if (header == null)
       {
           System.out.println("The list is empty!");
       }
       else
       {
           Node current = header;
           System.out.println(current.item);
           while (!(current.link == null))
           {
               current = current.link;
               System.out.println(current.item);
           }
       }
   }
}

In: Computer Science

In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...

In this programming assignment, you need to create 3 files.

1. DateType.h

2. DateType.cpp

3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file.

In DateType.h file, type these lines:

// To declare a class for the Date ADT // This is the header file DateType.h

class DateType

{
public:

void Initialize(int newMonth, int newDay, int newYear); int GetYear() const;
int GetMonth() const;
int GetDay() const;

private:
int year;

int month;

int day; };

// Class implementation // DateType.cpp

#include "DateType.h"

void DateType::Initialize(int newMonth, int newDay, int newYear)

{
year = newYear;

month = newMonth;

day = newDay; }

int DateType::GetMonth() const

{
return month;

}

In DateType.cpp file, type these lines:

int DateType::GetDay() const

{
return day;

}

int DateType::GetYear() const

{

return year; }

In you test driver, type in these lines:

// test driver
// I give the file name: testDriver.cpp
// To compile, type c++ DataType.cpp testDriver.cpp, this will generate an a.out executable.
// Or, type c++ Type.cpp testDriver.cpp –o testdriver, this will generate an executable named testdriver.

#include "DateType.h" #include <iostream>

using namespace std;

int main()

{
DateType today;

DateType anotherDay; today.Initialize(9, 24, 2003); anotherDay.Initialize(9, 25, 2003);

cout << "Today is " << today.GetMonth() << "/" << today.GetDay() << "/" << today.GetYear() << endl;

cout << "Anotherday is " << anotherDay.GetMonth() << "/" << anotherDay.GetDay() << "/" << anotherDay.GetYear() << endl;

return 0; }

Once you have the 3 files ready, you can compile them. The compile command is in the comments of the test driver.

After the compilation, you run the program, and see what output you get.
Now, modify the code to initialize 2 different dates, compile and run it, and see what the output is.

In: Computer Science