Questions
Write a function in Python which removes a set of common words from a long piece...

  1. Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are:

a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the

These are typical words that are considered to have low semantic value.

Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing the processed paragraph with the common words and punctuation removed. It is not required to put the text samples into a file (you can simply copy and paste into a string variable inside your Python script).

For the text samples to process, use the following (taken from the official Python tutorial):

If you do much work on computers, eventually you find that there’s some task you’d like to automate. For example, you may wish to perform a search-and-replace over a large number of text files, or rename and rearrange a bunch of photo files in a complicated way. Perhaps you’d like to write a small custom database, or a specialized GUI application, or a simple game.

If you’re a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow. Perhaps you’re writing a test suite for such a library and find writing the testing code a tedious task. Or maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application.

In: Computer Science

Could I please get explainations and working out as to how to get to the answers....

Could I please get explainations and working out as to how to get to the answers.

Note that  is where part of the answer goes.

1.

Consider the following ArrayList list:

ArrayList list = new ArrayList(Arrays.asList(10,70,20,90));

//list = [10, 70, 20, 90]

Complete the following statements so that list contains the items [50, 70, 20]

Do NOT include spaces in your answers.

list.remove(  ); list.  (  , 50);

2.

Assume there exists an ArrayList list that contains the items

[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ....]

(So, we know the first item is 10, second item is 20, but we don't know how many items it contains. You may assume it contains at least 10 items)

Complete the following code that displays every other item starting at the fifth item (so, the pattern 50 70 90 ...)

Do NOT include spaces in your answer.

for(int i=  ; i <  ;  ) {

System.out.println(  +" ");

}

3.

Complete the following function that returns the number of negative (less than 0) items in ArrayList list.

public static int countNegatives(ArrayList list) {

int result =  ;

for(int i=0; i < list.size(); i++) {

if(    ) {  ; }

} return result; }

In: Computer Science

You will be creating a JUnit Test Class for Gradebook.java, (listing 1.1) and you can download...

You will be creating a JUnit Test Class for Gradebook.java, (listing 1.1) and you can download it from blackboard.

Gradebook has two attributes: an array of int called scores to hold scores and scoreSize that indicates how many scores are currently held in the array. This field is initially set to 0.

Task #1:
Add a getScoreSize() method to the Gradebook class which returns scoresSize;
Add a toString() method to the Gradebook class that returns a string with each score in scores field of the Gradebook separated by a space.

.
Task #2: Create the Test Class GradebookTester by right clicking on the GradeBook.java, select New, Junit Test Case.
Using the wizard:
Select the setUp and tearDown method check boxes and click Next.
Select all of the methods of Gradebook, except for the constructor to create tests for. Then click finish.

.
Task #3:
In the setUp method of GradebookTester, create at least two objects of Gradebook to hold 5 scores. Then call the addScore method for each of the Gradebook objects at least twice (but no more than 5 times) to add some random scores of your choice to the GradeBook objects
In the teardown method of GradebookTester, set the two objects of Gradebook to null.

Task #4: Create test for the methods of Gradebook:
addScore
Use the toString method to compare the contents of what is in the scores array vs. what is expected to be in the scores array assertTrue( . . .)
Compare the scoreSize to the expected number of scores entered, using assertEquals(. . .)
sum
Compare what is returned by sum() to the expected sum of the scores entered.
minimum
Compare what is returned by minimum() to the expected minimum of the scores entered.
finalScore
Compare what is returned by finalScore() to the expected finalScore of the scores entered. The finalScore is the sum of the scores, with the lowest score dropped if there are at least two scores, or 0 if there are no scores.

Task #5: Upload both files to GitHub in a directory named CMSC203_Lab6.


Example:

As a private attribute (member) of GradeBookTest:
   GradeBook g1;

In setup:
g1 = new GradeBook(5);
g1.addScore(50);
g1.addScore(75);

In teardown:
   g1 = null;

in testSum():
assertEquals(125, g1.sum(), .0001);

in testMinimum():
   assertEquals(50, g1.minimum(), .001);

in addScoreTest();
   assertTrue(g1.toString().equals(“50.0 75.0 ”);

Listing 1.1 – GradeBook.java

import java.util.ArrayList;

public class GradeBook
{
private double[] scores;
private int scoresSize;

/**
Constructs a gradebook with no scores and a given capacity.
@capacity the maximum number of scores in this gradebook
*/
public GradeBook(int capacity)
{
scores = new double[capacity];
scoresSize = 0;
}

/**
Adds a score to this gradebook.
@param score the score to add
@return true if the score was added, false if the gradebook is full
*/
public boolean addScore(double score)
{
if (scoresSize < scores.length)
{
scores[scoresSize] = score;
scoresSize++;
return true;
}
else
return false;
}

/**
Computes the sum of the scores in this gradebook.
@return the sum of the scores
*/
public double sum()
{
double total = 0;
for (int i = 0; i < scoresSize; i++)
{
total = total + scores[i];
}
return total;
}
  
/**
Gets the minimum score in this gradebook.
@return the minimum score, or 0 if there are no scores.
*/
public double minimum()
{
if (scoresSize == 0) return 0;
double smallest = scores[0];
for (int i = 1; i < scoresSize; i++)
{
if (scores[i] < smallest)
{
smallest = scores[i];
}
}
return smallest;
}

/**
Gets the final score for this gradebook.
@return the sum of the scores, with the lowest score dropped if
there are at least two scores, or 0 if there are no scores.
*/
public double finalScore()
{
if (scoresSize == 0)
return 0;
else if (scoresSize == 1)
return scores[0];
else
return sum() - minimum();
}
}

In: Computer Science

----------------------------------------------------------------------------------------------------------------IN PYTHON-----------------------------------------------------------------------------------------------------------------------------write a Q

----------------------------------------------------------------------------------------------------------------IN PYTHON-----------------------------------------------------------------------------------------------------------------------------write a Quiz Generator. This program is expected to generate questions for a student, record student answers, displays the answers correctly entered and reports the total time taken by the student to finish the quiz.
a) The program should initialize three variables, one called correct that starts with an int of 0, second called count that also starts with an int of 0 and third called totalquestions that starts with an int of 5 (Hint: Typecast all the initialized variables to int values). The variable correct stores the correct answers entered by the student, count variable counts the number of questions and totalquestions is a constant value for total number of questions that equals 5.


b) Using the python time library, start the timer for the student. Store the value in a variable startTime. (Hint: Use time() method). Display the message “The quiz has started” using a print statement.


c) Using randint() method, generate two single digit integers for each question and store them in num1 and num2 variables. (Hint: use while to loop through totalquestions, generating two random integers (between 0-9) for each question)


d) Ask the student to input the answer to "What is num1 ** num2?" using input() function and save this value in a variable answer. Grade the answer by comparing its value to the actual operation between the two numbers and display the correct answers if the answer entered is wrong. (Hint: The student must enter the answer for num1 raise to the power num2. Then, after grading, using print statements, display the message “You are correct!” for correct answers entered by the student or “You are wrong! Correct answer is…” for wrong answers entered by the student).

e) End the timer for the student. Store the value in a variable endTime. Use totalTime variable to store the total time taken by the student. (Hint: totalTime is the difference value of endTime and startTime).


f) Print the number of points received based on the number of answers correctly entered by the student (Hint: You can display something like this “The number of points received are 3 out of 5”). Also, print the total test time taken by the student in seconds.


g) Ask input from the user if he wants to retake the test or exit. Depending upon the option selected by the user, restart the program again or end it. You can ask the user for input "Do you want to retake the quiz? Type Y/N: ". If the user enters N or stop or exit, end the program using ‘break’. If the user types Y, restart the quiz again. (Hint: use infinite while loop to restart the quiz again).


h) Use the same variable names and print statement examples as given in the question.

In: Computer Science

1/ Suppose you are responsible for the IT infrastructure of an organization, which has about 15desktop...

1/ Suppose you are responsible for the IT infrastructure of an organization, which has about 15desktop computers. You are advised that automation for uniformity is a good solution. What does it mean by “automation for uniformity”? Why is it a good solution in principle? Will you implement a fully automatic system in this case of yours? Why or why not.

In: Computer Science

In Java please. I put down my code and what I was able to achieve so...

In Java please. I put down my code and what I was able to achieve so far:

public class Animal {

  private String gender; //stores the gender of the animal
   private String type; //stores the type of the animal(bear of fish)
   private int strength; //stores the strength of the animal

   public Animal() {
       gender = "none";
       type = "none";
       strength = 0;
   }
  
    public Animal (String g, String t, int s) {
       g = gender;
       t = type;
       s = strength;      
   }

   public boolean setGender() {
       Random ranGen = new Random();
      
       boolean g = ranGen.nextBoolean();

  
       if (g == true)
           gender = "Male";
       else
           gender = "Female";
       return g;
   }
  
   public String getGender() {
       return gender;
   }

   public boolean setType() {
       Random ranGen = new Random();
      
       boolean t = ranGen.nextBoolean();
      
       if (t == true)
           type = "Bear";
       else
           type = "Fish";
       return t;      
   }
  

   public String getType() {
       return type;
   }


   public void setStrength(int strength) {
       this.strength = strength;
   }


   public int getStrength() {
       return strength;
   }

  
   public boolean compareGender(Animal animal) {

       if(this.getGender().equals(animal.getGender()))
       {
           return true;
       }
       else {
           return false;

       }
   }

  
   public boolean compareType(Animal animal) {
  
       if(this.getClass().equals(animal.getClass())){
           return true;   
       }
       else{
           return false;

       }

   }


   public boolean compareStrength(Animal animal) {
  
       if(this.getStrength() == (animal.getStrength())){
           return true;   
       }
       else{
           return false;

       }
   }
  
   public void increaseStrength() {
  
       this.setStrength(this.getStrength() + 4);
   }
  

   public String toString() {
       String str = new String ("The animal:  " + type + " + gender + strength);
       return str;

   }

}

public class River {
   private Animal[] river;
   private int numAnimals;
      

   public River() throws NumberFormatException{
   numAnimals = 0;
   Random randNum = new Random();
   int num = randNum.nextInt(20);
   river = new Animal[num];
   while(numAnimals < river.length/2)
   {
       int place = randNum.nextInt(river.length);
       if(river[place] == null)
       {
           river[place] = new Animal();

numAnimals++;


       }
   }
  
   }
  
   public River(Animal[] size) throws NumberFormatException{
       setRiver(size);
      
   }
  

   public void setRiver(Animal[] s) throws NumberFormatException
   {
       river= s;
           if (s.length >= 10 && s.length <= 20)
               river = s;
           else
       throw new NumberFormatException("Invalid Number: number out of range");
   }
  

   public Animal[] getRiver() {
       return river;      
   }
  
   public void play() {
       Random randNum = new Random();
       int moviment;
       for(int i=0; i<river.length; i++) {
           if(river[i] != null) {
               moviment = randNum.nextInt();
               if(moviment == 1) {
                  
               }
              
           }
       }
  

So my problem is on the play method. I need to iterate through the array.

If I find an animal I need to randomly decide if the animal id going to move back, forward or stay in place.

If the animal is moving back I need to make sure that he is not at the beginning of the array.

If the animal is moving forward I need to make sure that he is not at the last position of the array.

If the animal stays in place nothing needs to be done.

If the animal moves back/forward the index position needs to be checked if to see if its empty.

If is empty the animal can just move there. If is not the animal type needs to be checked.

If they are of the same type its gender needs to be checked. Same gender produces a baby, different gender they fight and the weaker animal dies (meaning it will be erased from the array).

If the animals are from different types one of the animals is going to be eaten.

**I really do not know how to do this method, I tried to start but I do not know how to move forward, so I would really appreciate if you put comments through the code. Also, can you please check if the parameterized constructor is right?

Thank you so much
  

In: Computer Science

Java programmers!!!! Complete the definition of the Tavunu class according to the specifications below and the...

Java programmers!!!!

Complete the definition of the Tavunu class according to the specifications below and the JUnit4 test file given

Background

A tavunu is an imaginary Earth-dwelling being that looks a bit like a Patagonian Mara and lives in a non-gendered but hierarchical society. Most interactions among tavunu are negotiated with pava --- items of status used for bargaining. Pava is always traded whole; you can't trade half a pava.

public class Tavunu {

// See what to do

}

what to do

Develop some code

Complete the definition of the Tavunu class so it represents tavuni (that's plural for tavunu) according to the specifications below and the JUnit4 test file here( see below).

A Tavunu instance should have a name of the tuvunu, the amount of pava the tavunu holds, and their year of birth.

A Tavunu instance should also have the following methods:

  • setName(name): gives the tavunu a new name. All tavunu names begin with the letters 'T' or 'D'. If the desired new name does not meet this criterion, the method does not change the name and returns false. Otherwise it changes the tavunu's name and returns true.
  • getName(): returns the tavunu's name.
  • spendPava(amount): decreases the amount of pava held by the tavunu. If the amount is zero or less the method does not change the pava and returns false. Otherwise it subtracts the amount from the tavunu's pava and returns true.
  • receivePava(amount): increases the amount of pava held by the tavunu. If the amount is zero or less it does not change the pava and it returns false. Otherwise it adds the amount to the tavunu's pava and returns true.
  • getPava(): returns the amount of pava held by this tavunu.
  • Accessor and mutator for the year of their birth. Negative values are OK --- they correspond to BCE dates.
  • An appropriate toString() method.
  • No-argument (default) and parameterized constructors.
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * Tests the Tavunu class w/ JUnit 4.
 *
 */
public class TavunuTest {

    /**
     * Also tests accessors.
     */
    @Test
    public void testCtorNoArg() {
        var tv = new Tavunu();
        assertEquals(tv.getName(), "");
        assertEquals(tv.getPava(), 0);
        assertEquals(tv.getBirthYear(), Integer.MIN_VALUE);
    }

    /**
     * Also tests accessors.
     */
    @Test
    public void testCtorParams() {
        var tv = new Tavunu("Dease", 1944, 42);
        assertEquals(tv.getName(), "Dease");
        assertEquals(tv.getPava(), 42);
        assertEquals(tv.getBirthYear(), 1944);
    }

    @Test
    public void testToString() {
        var tv = new Tavunu("Dease", 1944, 42);
        
        assertEquals("" + tv, "Dease born in 1944 has 42 pava.");
    }
    
    @Test
    public void testSetName() {
        var tv = new Tavunu();

        tv.setName("");
        assertEquals(tv.getName(), "");

        tv.setName("T");
        assertEquals(tv.getName(), "T");

        tv.setName("D");
        assertEquals(tv.getName(), "D");

        tv.setName("Trelling");
        assertEquals(tv.getName(), "Trelling");

        tv.setName("Dint");
        assertEquals(tv.getName(), "Dint");

        tv.setName("tranque");
        assertEquals(tv.getName(), "Dint");

        tv.setName("demary");
        assertEquals(tv.getName(), "Dint");

        tv.setName("Hint");
        assertEquals(tv.getName(), "Dint");
    }

    @Test
    public void testSetYear() {
        var tv = new Tavunu("Dease", 1944, 42);

        tv.setBirthYear(-2001);
        assertEquals(tv.getBirthYear(), -2001);

        tv.setBirthYear(0);
        assertEquals(tv.getBirthYear(), 0);

        tv.setBirthYear(2001);
        assertEquals(tv.getBirthYear(), 2001);
    }

    @Test
    public void testReceivePava() {
        var tv = new Tavunu("Dease", 1944, 42);

        boolean rv = tv.receivePava(-2001);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, false);

        rv = tv.receivePava(-1);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, false);

        rv = tv.receivePava(0);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, true);

        rv = tv.receivePava(1);
        assertEquals(tv.getPava(), 43);
        assertEquals(rv, true);

        rv = tv.receivePava(10);
        assertEquals(tv.getPava(), 53);
        assertEquals(rv, true);
    }

    @Test
    public void testSpendPava() {
        var tv = new Tavunu("Dease", 1944, 42);

        boolean rv = tv.spendPava(-2001);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, false);

        rv = tv.spendPava(-1);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, false);

        rv = tv.spendPava(0);
        assertEquals(tv.getPava(), 42);
        assertEquals(rv, true);

        rv = tv.spendPava(1);
        assertEquals(tv.getPava(), 41);
        assertEquals(rv, true);

        rv = tv.spendPava(10);
        assertEquals(tv.getPava(), 31);
        assertEquals(rv, true);
    }

}

In: Computer Science

Write a program in C++ that will output the truth table for a simple wff. There...

Write a program in C++ that will output the truth table for a simple wff. There will only be Ps and Qs, so you can hard code the P truth table and the Q truth table into arrays. The user will use A for ^ , O for V, N for ' , & I for -> .

Hint: Read the first character, load the appropriate truth table into the first working array. Read the next character. If it is an N, output the negation of the first working array. If it is a P or Q, oad the appropriate truth table into the second working, array, then read the last character and output the appropriate truth table.

Expression                Would be input as

P^Q                            PQA

P'                                PN

Q->P                           QPI

Example runs (note the user input is bold)

Run 1

Please input the wff: PQA

The truth table is

T

F

F

F

Run 2

Please input the wff: P'

The truth table is

F

F

T

T

In: Computer Science

Subtract in binary

Subtract in binary

In: Computer Science

Add in Octal

Add in Octal

In: Computer Science

I need the following problem to be coded in python without using Numpy: Given input features...

I need the following problem to be coded in python without using Numpy:

Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function:

g(X,W)={1 if wTx>0;0 otherwise}

The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer value:

def perceptron(X, W):

In: Computer Science

Subtract in Hexadecimal

Subtract in Hexadecimal

In: Computer Science

Which one of these code fragments could possibly be a comment that could be used to...

Which one of these code fragments could possibly be a comment that could be used to perform a XSS injection?

Select one:

a. <script>Evil()</script>

b. DROP TABLE users;

c. admin’ OR 1=1 --

In: Computer Science

Java Script. Develop a program that will determine the slugging percentages and batting average of several...

Java Script.

Develop a program that will determine the slugging percentages and batting average of several New York Yankees from the 2006 season. Slugging percentage is calculated by dividing the total number of bases by the number of at bats. The number of bases would be one for every single, two for every double, three for every triple, and four for every home run. The batting average is calculated by dividing the total number of hits by the number of at bats. You do not know the number of players in advance, but for each player you know their number of singles, doubles, triples, home runs, total number of at bats, and the player's name (use the proper type and method for each variable).

You will use a while sentinel loop on the 1st item to input. If it is not the sentinel, go into the while sentinel loop and separately input the rest of the input items (be careful of the enter in the input memory buffer for the player name). You will then calculate the total bases and the slugging percentage. You will then calculate the batting average. You will then print out the player's name, the labeled slugging percentage for that player to three decimal places, and the labeled batting average for that player to three decimal places. Use separate output statements. Print a blank line between players. This loop will repeat for as many players as you need.

Run your program with the following players and sentinel value (to show the sentinel value worked):

Create a java script. Modify your program that determined the slugging percentages and batting average of several New York Yankees from the 2006 season. The user now knows in advance the number of players to process. You will ask the user to input the number of players and input that value into a variable. You will use a while loop to check their input. While their input is less than zero or more than twenty, you will ask them to re-input the number of players, since the number of players has to be from zero to twenty. Use proper form for the while loop. Since we now know the number of players, use a for loop to count up to their number. Inside the loop, input all the data, calculate the batting average and slugging percentages, and print the name, batting average, and slugging percentage as in the while sentinel loop. Use proper form for the for loop. Make sure everything from part one is working properly. Slugging percentage is calculated by dividing the total number of bases by the number of at bats. The number of bases would be one for every single, two for every double, three for every triple, and four for every home run. The batting average is calculated by dividing the total number of hits by the number of at bats. You do not know the number of players in advance, but for each player you know their number of singles, doubles, triples, home runs, total number of at bats, and the player's name (use the proper type and method for each variable). Then use a for loop with a counter. While the counter is less than or equal to the number of players, go into the for loop and separately input the items (be careful of the enter in the input memory buffer for the player name). You will then calculate the total bases and the slugging percentage. You will then calculate the batting average. You will then print out the player's name, the labeled slugging percentage for that player to three decimal places, and the labeled batting average for that player to three decimal places. Use separate output statements. Print a blank line between players. This loop will repeat for as many players as the user asked for. Run your program with the following input and players: Enter number of players (0 – 20): 25 Invalid number of players. Enter number of players (0 – 20): -1 Invalid number of players. Enter number of players (0 – 20): 3 Singles: 158 Doubles: 39 Triples: 3 Home Runs: 14 At Bats: 623 Player: Derek Jeter Singles: 51 Doubles: 25 Triples: 0 Home Runs: 37 At Bats: 446 Player: Jason Giambi Singles: 104 Doubles: 26 Triples: 1 Home Runs: 35 At Bats: 572 Player: Alex Rodriguez

In: Computer Science

Assignment Questions: 1. Write a short note on external fragmentation. 2. Why we need operating system....

Assignment Questions:
1. Write a short note on external fragmentation.
2. Why we need operating system. If we don’t have operating system what would be the consequences?
3. What is BIOS?
4. Explain resources.
5. What is program counter?

In: Computer Science