Questions
Java (a) Create a class Router which stores the information of a router. It includes the...

Java

(a) Create a class Router which stores the information of a router. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Router object is created. Also write the getter methods for those variables. Finally add a method toString() to return the router information in the following string form.

 "brand: Linksys, model number: RVS4000, price: 1080.0"

Copy the content of the class as the answers to this part.

  1. (b) Create a class ComputerShop which stores the router information in a map routerMap, whose key is the concatenation of the brand and model number, separated by ": " (a colon and a space). Write a method addRouter(Router oneRouter) which adds oneRouter to routerMap. Copy the content of the class, which any include import statement(s) required, as the answers to this part.

  2. (c) Create a class TestComputerShop with a main() method which creates a ComputerShop object aShop and add the first router with brand "Linksys", model number "RVS4000" and price 1080. Add the second router with brand "Planet", model number "VRT-311S" and price 510. Copy the content of the class as the answers to this part.

  3. (d) Write a method showRouter() of ComputerShop which loops through the keys of routerMap using the enhanced for-loop and directly prints each router object stored using System.out.println(). (Loop through the values is simpler but using the keys is required in this part.) This should show suitable information since the method toString() has been written in (a). Add a statement in TestComputerShop to display all the router information of aShop. Copy the content of the method, line(s) added and execution output as the answers to this part.

  4. (e) Write a method modelNumberSet() of ComputerShop which returns model numbers of the routers in a set. You should loop through the values of routerMap using the enhanced for-loop and collect the model numbers. Add a statement in TestComputerShop to display the set using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.

  5. (f) Write a method priceList() of ComputerShop which returns the prices of the routers in a list. You should loop through the values of routerMap using the enhanced for-loop and collect the prices of the routers. Add a statement in TestComputerShop to display the list using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.

In: Computer Science

Please make a C program named: rotate.c This code will contain a single function (and the...

Please make a C program named:

rotate.c

This code will contain a single function (and the include directive to your header file) to perform the rotation operation using the two integer operands passed to this function. The first integer operand is the number to be rotated. The second integer operand is the number of bit positions that the first operand must be rotated by.

EXAMPLE:

Enter a 32-bit number (>= 1 and <= 4294967295, inclusively): 1

Enter the number of positions to rotate-right the input (between 0 and 31, inclusively): 1

1 rotated by 1 position gives: 2147483648

In: Computer Science

Write a class named TestScores. The class constructor should accept an array of test scores as...

Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program.

Use TestScoresDemo.java to test your code

public class TestScoresDemo

{

public static void main(String[] args)

{

// An array with test scores.

// Notice that element 3 contains an invalid score.

double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 };

// Another array with test scores.

// All of these scores are good.

double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0 };

// Create a TestScores object initialized with badScores.

try

{

TestScores tBad = new TestScores(badScores);

// The following statement should not execute.

System.out.println("The average of the bad scores is " +

tBad.getAverage());

}

catch (IllegalArgumentException e)

{

System.out.println("Invalid score found.\n" + e.getMessage());

}

// Create a TestScores object initialized with goodScores.

try

{

TestScores tGood = new TestScores(goodScores);

System.out.println("The average of the good scores is " +

tGood.getAverage());

}

catch (IllegalArgumentException e)

{

System.out.println("Invalid score found.\n" + e.getMessage());

}

}

}

In: Computer Science

Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement)...

Using Matlab

Write a program that print the following matrix. (hint: use nested for-loop and if-statement)

mat =

[2 -1 0 0 0

-1 2 -1 0 0

0 0 -1 2 -1

0 0 0 -1 2];

In: Computer Science

Implement the following method take takes the name of an ASCII text file and displays the...

Implement the following method take takes the name of an ASCII text file and displays the frequency of each character in the file. (6 pts)

public static void CountCharacters(String filename)

{

...

}

// Main provided for testing

public static void main(String args[])

{

CountCharacters("testfile.dat");

}

Output should be in the following format:

ASCII CODE - COUNTS

10 - 1

66 - 2

104 - 1

In: Computer Science

class Counter{   private int count = 0;   public void inc(){    count++;     }   public int get(){     return...

class Counter{

  private int count = 0;

  public void inc(){

   count++;  

  }

  public int get(){

    return count;

  }

}

class Worker extends Thread{

Counter count;

  Worker(Counter count){

    this.count = count;

  }

  public void run(){

    for (int i = 0; i < 1000;i++){

      synchronized(this){

        count.inc();

      }}

  }

}

public class Test

{  

  public static void main(String args[]) throws InterruptedException

  {

    Counter c = new Counter();

    Worker w1 = new Worker(c);

    Worker w2 = new Worker(c);

    w1.start();

    w2.start();

    w1.join();

    w2.join();

    System.out.println(c.get());

     

  }

}

The above code should print 2000 because inc() method is synchronized. However, it is printing a different number ranging from 1000 to 2000 everytime it runs. Can you explain why? How would you fix it?

In: Computer Science

2. Resourcing profiling is the first step of the risk management life cycle. Describe what is...

2. Resourcing profiling is the first step of the risk management life cycle. Describe what is involved with this step, what challenges are involved with resource profiling. Use examples from the real world for your analysis. Your answer must be two pages in length.

In: Computer Science

Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are...

Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are all binary variables):

a. If A happens then B or C happens.

b. If A and B happen then C and D must happen.

c. If A happens or B does not happen then C or D must happen.

d. If A happens or B happens then C and D happen.

This has previously been posted before on Chegg but there are conflicting answers and comments to the questions/responses.

In: Computer Science

PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if...

PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if n is odd.

row ← n - 1

column ← n/2

for k = 1 . . . n2 do

Place k at [row][column]

Increment row and column

if the row or column is n then

replace it with 0

end if

if the element at [row][column] has already been filled then

Set row and column to their previous values

Decrement row end if end for

Here is the 5 × 5 square that you get if you follow this algorithm:

11 18 25 2 9

10 12 19 21 3

4 6 13 20 22

23 5 7 14 16

17 24 1 8 15

Write a program whose input is the number n and whose output is the magic square of order n if n is odd.

Please solve in Python

In: Computer Science

In Python, write a function called user_name that takes two arguments, first_name and last_name and creates...

In Python, write a function called user_name that takes two arguments, first_name and last_name and creates a “user name” consisting of the first three letters of the first name concatenated with the first three letters of the last name.   You can assume ach name is at least three letters long.

Return the new user name.   

your results should yield something like these test cases.

>>> print(user_name("bob", "taft"))

bobtaf

>>>

>>> print(user_name("Ralph", "Waldo"))

RalWal

>>>

In: Computer Science

Write a c++ program that randomly generates 100 dates, store them into four vectors of date...

Write a c++ program that randomly generates 100 dates, store them into four vectors of date objects according to their seasons.. The dates generated must be within 1000 days after 1/1/2000.

In: Computer Science

What would the code look like if you weren't using hash maps and array lists (only...

What would the code look like if you weren't using hash maps and array lists (only using scanner import) and solving using a partition algorithm?

In: Computer Science

a file named maintence08-01.txt is included with your downloadable student files. Assume that this program is...

a file named maintence08-01.txt is included with your downloadable student files. Assume that this program is a working program in your organization and that it needs modifications that are described in the comments(lines that begin with two slashes) at the beginning of the file. Your job is to alter the program to meet the new specifications.


Here is the file Maintence08-01.txt

// This application reads sales data for a real estate broker.
// The user enters a record for each of 10 salespeople
// containing the salesperson's name,
// the number of properties sold by that person during the month,
// and the total value of those properties.
// The data records are sorted by value so the data for
// the top three salespeople can be displayed.
// Modify the program to
// (1) enter data for any number of salespeople up to 60
// (2) allow the user to choose whether to see
// (a) the data for the top three salespeople
// (or fewer if 3 are not entered) by value
// (b) the data for the top three salespeople
// (or fewer if 3 are not entered) by
// number of properties sold

start
Declarations
num SIZE = 10
string names[SIZE]
num properties[SIZE]
num values[SIZE]
num count
num NUM_TO_DISPLAY = 3
num comps
num x
num y
num tempProp
num tempVal
string tempName
getReady()
display()
finish()
stop

getReady()
count = 0
while count < SIZE
output "Enter salesperson name "
input names[count]
output "Enter number of properties sold "
input properties[count]
output "Enter total value of those properties "
input values[count]
count = count + 1
endwhile
return

display()
sort()
count = 0
while count < NUM_TO_DISPLAY
output names[count], properties[count], values[count]
count = count + 1
endwhile
return


finish()
output "End of display"
return

sort()
comps = SIZE - 1
while y < comps
x = 0
while x < comps
if values[x] < values[x + 1] then
swap()
endif
x = x + 1
endwhile
y = y + 1
endwhile
return

void swap()
tempName = names[x + 1]
names[x + 1] = names[x]
names[x] = tempName
tempProp = properties[x + 1]
properties[x + 1] = properties[x]
properties[x] = tempProp
tempVal = values[x + 1]
values[x + 1] = values[x]
values[x] = tempVal
return

In: Computer Science

Java- Create a new class named Forest that has a 2D array of integers to store...

Java-

Create a new class named Forest that has a 2D array of integers to store a forest.

Create a private inner class Position to store the row and column of the current cell.

Create a Depth First Search Method that uses a stack to remove the current tree and search its neighbors based on the following pseudocode:

// given a forest "f"
// store positions on fire
Stack<Position> cellsToExplore

// the forest is aflame!
for each tree in the top row:
  add position to cellsToExplore
  mark tree as "on fire"

// continue lighting neighbors on fire
while cellsToExplore is not empty
  pop the stack into currentPosition
  return true if currentPosition is on the bottom row
  for each neighboring tree
    push location onto the stack
    mark tree as "on fire"

// must not have reached the bottom row...
return false

In: Computer Science

In this problem, we provide you with a Java file called Question2.java. Suppose that there is...

In this problem, we provide you with a Java file called Question2.java. Suppose that there is an array and let us call this array, items. The array items contains n integers. These n integers are in a completely random order in the array. What you are asked to do is to reorder the items in the array such that all the negative integers come before all the zeros and all the positive integers appear at the end. Note, this question is not asking you to sort the numbers in the array. It is asking you to reorder them

In this first example, you can see that the array initially contains the integers 7, −3, 0, 0, 8 and −2. Now, this is in some random order. What you must do to this array, is to reorder the numbers such that the array has three distinct pieces (also called constraints) represented by < 0, == 0 and > 0. You can see that in the first region, we place all the numbers that are less than 0, followed by all zeros and then followed by any numbers that are greater than 0. The numbers within each region can be in any order, as long as they happen to fulfill the constraint.

2. You can only visit all the numbers in the array once. i.e., you are not allowed to have nested loops. Neither can you create a new array or use an array list. You should be able to work on this problem simply by visiting every number once. You must mutate the array that is already provided to you and make changes to this array itself.

3. Do not sort any numbers. If you were to sort the numbers, you would receive zero for this question.

4. The numbers within each region can be in any order, as long as they happen to fulfill the constraint.

5. You cannot assume that there will be at least a single zero in the array. You may very well have an array with all zeros or an array that contains no zero. Assuming that the array contains only negative numbers and positive numbers (≥ 1) If this is the case, you will proceed with reordering the items in the array such that you have negative numbers followed by positive numbers. 6. We provide to you the following methods that must be completed

starter code:

package 3;
//Make sure to copy/paste the honor code and fill in all the required details. 
//If you do not complete the honor code, your assignment will not get marked.
import java.util.Arrays;

public class Question2 {
        /*
         * TODO: You are asked to complete the method
         * rearranging. This method takes in as input an 
         * array of ints and returns back nothing (void).
         * You cannot change the function 
         * signature of this method. Your method question2 must call
         * the swap method. Scroll down to find the swap method.   
         * You cannot use any kind of sorting to answer this question. 
         */
        public static void question2(int[] items)
        {
                
        }
        
        /*
         * TODO: You are asked to complete the method
         * swap. This method takes in as input two ints
         * and an array of ints. The int i and int j 
         * are the index i and index j in the array items.
         * You are asked to swap the value at the index i in items
         * with the value at the index j. You cannot change the function 
         * signature of this method. This method must be called inside question2. 
         */
        private static void swap(int i,int j,int[] items)
        {
                
                
        }

        
        /*
         * Do not write any code inside the main method and expect it to get marked. 
         * Any code that you write inside the main method will be ignored. However, 
         * you are free to edit the main function in any way you like for 
         * your own testing purposes. 
         */
        public static void main(String[] args) {
                
                
                int [] items={-7,-3,20,10,8,2};
                Question2.question2(items);
                System.out.println(Arrays.toString(items)); //must print [-7, -3, 10, 8, 2, 20]
                
                int [] items1={1,1,1,1,1,1,1,1};
                Question2.question2(items1);
                System.out.println(Arrays.toString(items1)); //must print [1, 1, 1, 1, 1, 1, 1, 1]
                
                
                int [] items2={1,2,3,4,5,6,7,8,9};
                Question2.question2(items2);
                System.out.println(Arrays.toString(items2)); //must print [2, 3, 4, 5, 6, 7, 8, 9, 1]
                
                int [] items3={6,7,8,0,1,2,3,-1,-2};
                Question2.question2(items3);
                System.out.println(Arrays.toString(items3)); //must print [-2, -1, 0, 1, 2, 3, 8, 7, 6]
                
                
                
                int [] items4={0,0,0,0,1,2,3,-1,-2,-3};
                Question2.question2(items4);
                System.out.println(Arrays.toString(items4)); //must print [-3, -2, -1, 0, 0, 0, 0, 3, 2, 1]
                
                int [] items5={-1,4,5,6,0,0,0,-2};
                Question2.question2(items5);
                System.out.println(Arrays.toString(items5)); //must print [-1, -2, 0, 0, 0, 6, 5, 4]
                
                
        }
}

In: Computer Science