Questions
Question 5 0/1 point (graded) The following is the full path to a homework assignment file...

Question 5

0/1 point (graded)

The following is the full path to a homework assignment file called "assignment.txt": /Users/student/Documents/projects/homeworks/assignment.txt.

Which line of code will allow you to move the assignment.txt file from the “homeworks” directory into the parent directory “projects”?

mv assignment.txt

mv assignment.txt .

mv assignment.txt ..

mv assignment.txt /projects incorrect

Answer

Incorrect:

Try again. This code does not provide enough information about where to move the file. You need to specify a relative or full path to the location where you want to move the file to.

Question 9

0/1 point (graded)

The source function reads a script from a url or file and evaluates it. Check ?source in the R console for more information.

Suppose you have an R script at ~/myproject/R/plotfig.R and getwd() shows ~/myproject/result, and you are running your R script with source('~/myproject/R/plotfig.R').

Which R function should you write in plotfig.R in order to correctly produce a plot in ~/myproject/result/fig/barplot.png?

ggsave('fig/barplot.png'), because this is the relative path to the current working directory.

ggsave('../result/fig/barplot.png'), because this is the relative path to the source file ("plotfig.R"). incorrect

ggsave('result/fig/barplot.png'), because this is the relative path to the project directory.

ggsave('barplot.png'), because this is the file name.

Question 12

1 point possible (graded)

Which of the following meanings for options following less are not correct?

(Hint: use man less to check.)

-g: Highlights current match of any searched string

-i: case-insensitive searches

-S: automatically save the search object

-X: leave file contents on screen when less exits.

Question 13

1 point possible (graded)

Which of the following statements is incorrect about preparation for a data science project?

Select ALL that apply.

Always use absolute paths when working on a data science project.

Saving .RData every time you exit R will keep your collaborator informed of what you did.

Use ggsave to save generated files for use in a presentation or a report.

Saving your code in a Word file and inserting output images is a good idea for making a reproducible report.

In: Computer Science

Question 11 1 point possible (graded) The commands in the pipeline $ cat result.txt | grep...

Question 11

1 point possible (graded)

The commands in the pipeline $ cat result.txt | grep "Harvard edX" | tee file2.txt | wc -l perform which of the following actions?

From result.txt, select lines containing “Harvard edX”, store them into file2.txt, and print all unique lines from result.txt.

From result.txt, select lines containing “Harvard edX”, and store them into file2.txt.

From result.txt, select lines containing “Harvard edX”, store them into file2.txt, and print the total number of lines which were written to file2.txt.

From result.txt, select lines containing “Harvard edX”, store them into file2.txt, and print the number of times “Harvard edX” appears.

unanswered

You have used 0 of 2 attempts Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.

Question 12

0/1 point (graded)

How is git rebase used?

To switch branches or restore working tree files incorrect

Uses a binary search to find the commit that introduced a bug

To reapply commits on top of another base tip

To reset the current HEAD to the specified state

To download objects and refs from another repository

You have used 1 of 2 attempts Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.

Question 13

1 point possible (graded)

Which of the following statements is wrong about Advanced Unix Executables, Permissions, and File Types?

In Unix, all programs are files/executables except for commands like ls, mv, and git.

which git allows a user to find the path to git.

When users create executable files themselves, they cannot be run just by typing the command - the full path must be typed instead.

ls -l can be used to inspect the permissions of each file.

In: Computer Science

Write an SQL query that will output the employee id, first name and hire date from...

  1. Write an SQL query that will output the employee id, first name and hire date from the employee table. Pick only those employees whose employee ID is specified in the employee table (no nulls). If the employee id is 777, name is ABC and hire date is 01-JAN-2016, the output should be like - ' ABC (Employee ID - 777) was hired on 1, January of 2016'. Note - The date should not have preceding zeros.

In: Computer Science

1) Why should virtualization sprawl be restrained and what would you do to achieve that goal?...

1) Why should virtualization sprawl be restrained and what would you do to achieve that goal?

2) If virtualization sprawl is already an issue, what should an administrator do before it becomes even worse?

In: Computer Science

for C++ pointers: a. Given int arr [10], *ap = &arr[2]; what is the result of...

for C++ pointers:

a. Given int arr [10], *ap = &arr[2]; what is the result of (ap - arr)?

b. Given int val = 10, *x = &val, *y; y = x; *y=100; what is the output of cout << *x << *y;?

c. Given int arr [10], *ap = arr; what element does ap point to after ap +=2; ?

In: Computer Science

Please implement a HashSet using Separate Chaining to deal with collisions. public interface SetInterface<T> {   ...

Please implement a HashSet using Separate Chaining to deal with collisions.

public interface SetInterface<T> {

   public boolean add(T item);
   public boolean remove(T item);
   public boolean contains(T item);
   public int size();
   public boolean isEmpty();
   public void clear();
   public Object[] toArray();
  
}

public class HashSet<T> implements SetInterface<T> {
   //============================================================================= Inner node class
   private class Node<E> {
       private E data;
       private Node<E> next;

       public Node(E data) {
           this.data = data;
           this.next = null;
       }
   }

   //============================================================================= Properties
   private Node<T>[] buckets;   // An array of nodes
   private int size;
   private static final double LOAD_FACTOR = .6;
   private static final int DEFAULT_SIZE = 11; // should be prime

   //============================================================================= Constructors
   public HashSet() {
       buckets = (Node<T>[]) new Node[DEFAULT_SIZE];
       size = 0;
   }

   public HashSet(T[] items) {
       //************************************************************* TO-DO
       // Make a call to your empty constructor and then somehow fill
       // this set with the items sent in

   }
  
   //============================================================================= Methods
   @Override
   public boolean add(T item) {
       //************************************************************* TO-DO
       // Check to see if item is in the set. If so return false. If not,
       // check if the LOAD_FACTOR has already been exceeded by the previous
       // add and if so, call the resize() before adding.
      

       return true; // returns true because we know it's been added
   }

   @Override
   public boolean remove(T item) {
       //************************************************************* TO-DO
       // To remove an item, you are removing from a linked chain of nodes.
       // Our algorithm is to copy the data from that head node to the node to be
       // removed, and then remove the head node.
       boolean success = false;

       return success;
   }

   @Override
   public boolean contains(T item) {
       //************************************************************* TO-DO
       // A one-line method that calls
       // the find() method
       return false;
   }

   @Override
   public void clear() {
       //************************************************************* TO-DO
       // sets all items in the array to null
   }

   @Override
   public int size() {
       return size;
   }

   @Override
   public boolean isEmpty() {
       return size == 0;
   }

   @Override
   public Object[] toArray() {
       Object[] result = new Object[size];

       // The structure of this is similar to the structure of toString
       //************************************************************* TO-DO

      
       return result;
   }

   // Return a string that shows the array indexes, and the items in each bucket
   public String toString() {
       String result = "";
       String format = "[%" + ("" + buckets.length).length() + "d] ";
      
       // Loop through the array of buckets. A bucket is just a chain of linked nodes.
       // For each bucket, loop through the chain, displaying the contents of the bucket
       for (int i = 0; i < buckets.length; i++) {
           result += String.format(format, i);
          
           // add the data in bucket i
           Node curr = buckets[i];
           while (curr != null) {
               result += curr.data + " ";
               curr = curr.next;
           }
           result += "\n";
       }
       return result;
   }

   // helper methods

   // Adds all items in an array to this set.
   // resize() could make use of this.
   // One of the constructors can make use of this too.
   private void addAll(T[] items) {
       //************************************************************* TO-DO
       // loop to add each item to the set (calls add())
   }

   private void resize() {
      
       T[] allData = (T[]) toArray();   // toArray() is method above
       buckets = (Node<T>[]) new Node[ firstPrime(2 * buckets.length) ];
       size = 0;
      
       //************************************************************* TO-DO
       // now, allData contains all the data from the set
       // and buckets points to a new empty array
       // call addAll to do the adding
       // double-check size when you are done

   }

   // Very important
   // Returns the node containing a particular item, or null if not found.
   // Useful for add, remove, and contains. This is a PRIVATE helper method
   private Node<T> find(T item) {
       // Step 1:    find the index of where this T would be...
       int index = getHashIndex(item);
      
       // Step 2:    using the index, check the linked nodes at that array index
       // by looping through all nodes of the bucket      
       Node<T> curr = buckets[index];  
       while(curr != null && !curr.data.equals(item))
           curr = curr.next;
      
       return curr;   // we will either be returning null (not found) or the node
                       // that contains the node we are looking for
   }

   // Gets the index of the bucket where a given string should go,
   // by computing the hashCode, and then compressing it to a valid index.
   private int getHashIndex(T item) {
       // item will always have the hashCode() method.
       // From the
       int hashCode = item.hashCode();
       int index = -1;   // calculate the actual index here using the
                       // hashCode and length of of the buckets array.
      
       //************************************************************* TO-DO
      
       return index;
   }

   // Returns true if a number is prime, and false otherwise
   private static boolean isPrime(int n) {
       if (n <= 1)   return false;
       if (n == 2)   return true;

       for (int i = 2; i * i <= n; i++)
           if (n % i == 0)   return false;
      
       return true;
   }

   // Returns the first prime >= n
   private static int firstPrime(int n) {
       while (!isPrime(n)) n++;
       return n;
   }

}


public class Tester {
  
   public static void main(String[] args) {

       HashSet<String> set = new HashSet<>();
       System.out.println("true? " + set.isEmpty());
       System.out.println("true? " + set.add("cat"));
       System.out.println("true? " + set.add("dog"));
       System.out.println("false? " + set.add("dog"));
       System.out.println("2? " + set.size());
       System.out.println("false? " + set.isEmpty());
       System.out.println(set.toString());

       for(char c : "ABCDEFGHIJKLMNOPQUSTUVWXYZ".toCharArray())
           set.add("" + c);
      
       System.out.println(set.toString());
   }
  
}


In: Computer Science

Make sure you are using the appropriate indentation and styling conventions Open the online API documentation...

Make sure you are using the appropriate indentation and styling conventions

Open the online API documentation for the ArrayList class, or the Rephactor Lists topic (or both). You may want to refer to these as you move forward.

Exercise 1 (15 Points)

  • In BlueJ, create a new project called Lab7
  • Create a class in that project called ListORama
  • Write a static method in that class called makeLists that takes no parameters and returns no value
  • In makeLists, create an ArrayList object called avengers that can hold String objects.

Exercise 2 (15 Points)

  • Add the following names to the avengers list, one at a time:

Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark

  • Print the avengers object. You will notice that the contents are displayed in between two brackets [] and separated by a comma. This is how the toString() method of the ArrayList class is implemented!
  • Then use a for-each loop to print each person in the list, one per line.

Exercise 3 (15 Points)

  • Print a blank line.
  • Print the current size of the ArrayList:

Current size of avengers: xxx

  • Now use a regular for loop to print the elements of the list, one per line.

Exercise 4 (15 Points)

  • Now remove the "Clark" and "Gwyneth" elements from the ArrayList. Remember, the list "closes the gaps" when something is removed.
  • Print the current size again.

Now the size is: xxx

  • Print the entire list object again.
  • Make sure you removed the right people!

Exercise 5 (20 Points)

  • Add "Chris H." to the end of the ArrayList.
  • Change the first element "Chris" to "Chris E."
  • Insert "Loki" between "Robert" and "Scarlett"
  • Print the size of the ArrayList again.
  • Print the entire list again.

Exercise 6 (20 Points)

  • Print the elements of the ArrayList again, this time on one line separated by commas.
  • Don't print a comma after the last name!
  • To do this, use a regular for loop and the ArrayList get method to get each name to print.
  • Use an if statement to decide whether to print a comma after each name

In: Computer Science

Find a company or organization which provide cloud computing and services, analyze the information by listing...

Find a company or organization which provide cloud computing and services, analyze the information by listing and commenting their:

a. Services to provide

b. Major clients

c. Benefits

d. Issues and problems

In: Computer Science

I have a set of 100,000 random integers. How long does it take to determine the...

I have a set of 100,000 random integers. How long does it take to determine the maximum value within the first 25,000, 50,000 and 100,000 integers? Will processing 100,000 integers take 4 times longer than processing 25,000? You may use any programming language/technique. It is possible the time will be very small, so you might need to repeat the experiment N times and determine an average value for time. Complete this table. Source code is not needed.

Number

Time

25,000

50,000

100,000

Language/Tool used:

Technique used:

In: Computer Science

Python: The goal is to reverse the order of month and date. # For example, #...

Python:

The goal is to reverse the order of month and date.

# For example,
# output: I was born on 24 June
print(reverse("I was born on June 24"))

# output: I was born on June two
print(reverse("I was born on June two"))

#output: I was born on 1 January, and today is 9 Feb.
print(reverse("I was born on January 1, and today is Feb 9."))

My code (so far, works for first two not the last):

def reverseOrder(string):
newString = []
count = 0
for word in string.split():
count = count+1
if word.isdigit():
count = count+1
newString.append(word)
newString[count-3], newString[count-2] = newString[count-2], newString[count-3]
else:
newString.append(word)
  
return ' '.join(newString)

In: Computer Science

Create a Python program that will calculate the user’s net pay based on the tax bracket...

Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents.

The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as followed:

  • 0 – 1 Dependents : Tax = 20%
  • 2 – 3 Dependents : Tax = 15%
  • 4+ Dependents :    Tax = 10%

After calculating the net pay, print the name of the user, the monthly gross pay, the number of dependents, the gross pay, the tax rate, and the net pay.

The formula to compute the net pay is: monthly gross pay – (monthly pay * tax rate)

In: Computer Science

My class PayCalculator isn't implementing the interface Constants, it did this before but when I saved...

My class PayCalculator isn't implementing the interface Constants, it did this before but when I saved it went nuts. I was wondering how to fix it?

import java.text.DecimalFormat;

public class PayCalculator implements Constants {
  
   private String employeeName;
   private int reportID;
   private double hourlyWage;
   private static int ID = 0;
   private static int reportIDGenerator = 1000;
   public int[] overtimes = HOURS_WORKED;

public PayCalculator(String name) {
   public PayCalculator() {
   this.reportID = reportIDGenerator;
   reportIDGenerator+=10;
   this.overtimes = HOURS_WORKED;
   }
}
public PayCalculator(String name, double hourlyWage) {
   this.reportID = reportIDGenerator;
reportIDGenerator+=10;
this.employeeName = name;
this.hourlyWage = hourlyWage;
this.overtimes = HOURS_WORKED;
}

public String getEmployeeName() {
return employeeName;
}

public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}

public int getReportID() {
return reportID;
}

public double getHourlyWage() {
return hourlyWage;
}

public void setHourlyWage(double hourlyWage) {
this.hourlyWage = hourlyWage;
}
  
@Override
public String toString() {
return "PayCalculator [employeeName=" + employeeName + ", reportId=" + reportID +
       ", hourlyWage=" + hourlyWage+ "]";
}
public double calculateYearlyGrossPay(){
double totalGross = 0.0;
for(int period = 1; period <= PAY_PERIODS_IN_YEAR; period++){
totalGross += calculateGrossForPeriod(period);
}
return totalGross;
}
public double calculateYearlyNetPay(){
double totalNet = 0.0;
for(int period = 1; period <= PAY_PERIODS_IN_YEAR; period++){
totalNet += calculateNetPayForPeriod(period);
}
return totalNet;
}
public double calculateNetPayForPeriod(int periodNumber){
double gross = calculateGrossForPeriod(periodNumber);
double tax = calculateTax(gross);
double netPay = gross-tax;
return netPay;
}
public double PAY_PERIODS_IN_YEAR(int periodNumber){
double gross = calculateGrossForPeriod(periodNumber);
double tax = calculateTax(gross);
double netPay = gross-tax;
return netPay;
}
public void printNetPayForAllPeriods(){
DecimalFormat df = new DecimalFormat("#.00");
System.out.println("NET PAY for all periods:\n");
for(int period =1; period <= PAY_PERIODS_IN_YEAR; period++){
System.out.println("PERIOD:"+period+" NET PAY:"+df.format(calculateNetPayForPeriod(period)));
}
}
public void increaseWageRate(double percentage){
hourlyWage =hourlyWage+ hourlyWage*(percentage/100);
}

private double calculateGrossForPeriod(int periodNumber){
double regulayPay = FULL_TIME*hourlyWage;
double overtimePay = overtimes[periodNumber-1]*(hourlyWage*OVERTIME_RATE);
double gross= regulayPay+overtimePay;
return gross;
}
private double calculateTax(double gross){
double federalTax = gross*FEDERAL_TAX_RATE;
double stateTax = gross*STATE_TAX_RATE;
return federalTax+stateTax;
}
  
}


public interface Constants {
  
   public final int[] HOURS_WORKED = {89, 80, 19, 73, 44, 99, 77, 0, 80, 70, 80, 87, 84, 82,
           80, 30, 89, 90, 100, 120, 0, 69, 99, 91, 83, 80};
  
   public final int PAY_PERIODS_IN_YEAR = 26;
   public final double FEDERAL_TAX_RATE = 0.2;
   public final double STATE_TAX_RATE = 0.09;
   public final double OVERTIME_RATE = 1.5;
   public final double FULL_TIME = 80;
  
   public final int PAY_PERIOD_1 = 0;
   public final int PAY_PERIOD_2 = 1;
   public final int PAY_PERIOD_3 = 2;
   public final int PAY_PERIOD_4 = 3;
   public final int PAY_PERIOD_5 = 4;
   public final int PAY_PERIOD_6 = 5;
   public final int PAY_PERIOD_7 = 6;
   public final int PAY_PERIOD_8 = 7;
   public final int PAY_PERIOD_9 = 8;
   public final int PAY_PERIOD_10 = 9;
   public final int PAY_PERIOD_11 = 10;
   public final int PAY_PERIOD_12 = 11;
   public final int PAY_PERIOD_13 = 12;
   public final int PAY_PERIOD_14 = 13;
   public final int PAY_PERIOD_15 = 14;
   public final int PAY_PERIOD_16 = 15;
   public final int PAY_PERIOD_17 = 16;
   public final int PAY_PERIOD_18 = 17;
   public final int PAY_PERIOD_19 = 18;
   public final int PAY_PERIOD_20 = 19;
   public final int PAY_PERIOD_21 = 20;
   public final int PAY_PERIOD_22 = 21;
   public final int PAY_PERIOD_23 = 22;
   public final int PAY_PERIOD_24 = 23;
   public final int PAY_PERIOD_25 = 24;
   public final int PAY_PERIOD_26 = 25;
}

In: Computer Science

Submit a processed dataset and Python or SAS script that has been used along with a...

Submit a processed dataset and Python or SAS script that has been used along with a short description of the steps you have been following.

In: Computer Science

First time working with stack implementation. Newbie to java Two stacks of positive integers are needed,...

First time working with stack implementation. Newbie to java

Two stacks of positive integers are needed, both containing integers with values less than or 
equal to 1000. One stack contains even integers, the other contains odd integers. The total number of elements in the combined stacks is never more than 200 at anytime. but we cannot predict how many are in each stack. (All of the elements could be in one stack, they could be evenly divided, both stacks could be empty, and so on).

1. Design ADT (named NumberStack.java).
2. write an application, generate random 2000 numbers between 0 and 5000, then push them (valid numbers) 
  to their corresponding stack.
2. print the numbers stored in each stack.

Class file include (you must use the names as specified):
NumberStack.java
NumberStackTester.java

In: Computer Science

JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one...

JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE

Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be given in class). All add, subtract, multiply and divide methods return a Bottle. This means the demo code b2 = b3.add(b1) brings into the add method a Bottle b1 which is added to b3. Bottle b3 is the this Bottle. The returned bottle is a new bottle containing the sum of b1 and b3. The value of b3 (the this bottle) is not changed. Your Bottle class must guarantee bottles always have a positive value and never exceed a maximum number chosen by you. These numbers are declared as constants of the class. Use the names MIN and MAX. The read() method should guarantee a value that does not violate the MIN or MAX value. Use a while loop in the read method to prompt for a new value if necessary. Each method with a parameter must be examined to determine if the upper or lower bound could be violated. In the case of the add method with a Bottle parameter your code must test for violating the maximum value. It is impossible for this add method to violate the minimum value of zero. The method subtract with a Bottle parameter must test for a violation of the minimum zero value but should not test for exceeding the maximum value. In the case of a parameter that is an integer, all methods must be examined to guarantee a value that does not violate the MIN or MAX values. Consider each method carefully and test only the conditions that could be violated.

(2 point) Further in the semester we will use a runtime exception class to guarantee these invariants.

public String toString()

{     

       return “” + this.pennies;

}

In: Computer Science