Questions
Have a look at the code below. Write a switch statement to check for the mode...

Have a look at the code below. Write a switch statement to check for the mode type. When the designated mode is matched, display an appropriate string for that mode. The default case should display the statement, “We do not offer this mode of course delivery.”

public class SwitchCourse
{
    enum CourseMode { ONLINE, RESIDENTIAL, HYBRID }
    CourseMode myCourse = CourseMode.HYBRID;
  
    public void myCourse()
    {
        switch (/*___*/)
        {
            case ONLINE:
                System.out.println("You will not need to attend classes on campus.");
                break;
            case RESIDENTIAL:
                System.out.println("All of your classes will be held on campus.");
                break;
            case HYBRID:
                System.out.println("You will be required to attend one class a week on campus.");
                break;
            /*____*/
                /*_____*/
        }
    }

}

In: Computer Science

What is LUN, and how can it be applied to SAN management?

What is LUN, and how can it be applied to SAN management?

In: Computer Science

Python - Create/Initialize a dictionary with 5 state/capital pairs of your choosing. The state is the...

Python

- Create/Initialize a dictionary with 5 state/capital pairs of your choosing. The state is the key and the capital is the value (e.g. “Kansas”:”Topeka”). Only one statement is needed to do this.

- Then prompt the user for a state.

e.g. The output

Enter a state, and I will display the capital.

State: Colorado

Colorado's capital is Denver.

- If that state exists in the dictionary, display the capital, else display "I'm sorry, but I still need to record " followed by the state entered.

e.g. the output

Enter a state, and I will display the capital.

State: Nebraska

I'm sorry, but I still need to record Nebraska.

- Modify the else to also include the ability to add the state and capital to the dictionary.

e.g. the output

Enter a state, and I will display the capital.

State: Nebraska

I'm sorry, but I still need to record Nebraska.

What is Nebraska's capital? Lincoln

The recorded states and capitals thus far are:

{'Kansas': 'Topeka', 'Iowa': 'Des Moines', 'Michigan': 'Lansing', 'California': 'Sacramento', 'Colorado': 'Denver', 'Nebraska': 'Lincoln'}

In: Computer Science

Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...

Code should be Written in C

  1. Using initialization lists, create 5 one-dimensional arrays, one for each of these:
  • hold the names of the people running in the election
  • hold the names of the subdivision
  • hold the vote counts in the Brampton subdivision for each candidate
  • hold the vote counts in the Pickering subdivision for each candidate
  • hold the vote counts in the Markham subdivision for each candidate

Use the data from the example below.

* Your C program should take the data in the arrays and produce the output below, neatly formatted as shown:

Candidates                            Subdivisions                 Totals

                             Brampton  Pickering Markham        

Aubrey                     600            800          800            2200

Blake 700            700          600            2000

Chubbs 800           700          800           etc

Oliver 400            450         300             

Zamier 900            900       900            

Totals                     3400            etc                              etc

  1. Create a function that will find the total votes in one subdivision and return that to main( ). Call this function 3 times to produce the 3 totals in the last line of output.

  1. Create a function that will find the total votes for one candidate and return that to main( ). Call this function 5 times to produce the 5 totals in the last column of output. Be very careful with the parameter list here. Send the function only the information it needs.
  1. Create a function that will output the first 2 lines of headings.

In: Computer Science

create a C++ program using Visual Studio that could be used by a college to track...

create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates and uses objects of each class. Save the file as Courses.cpp. Compile this application using Visual Studio and run it to make sure it is error free. Please attach your project folder in a zipfile when submitting. GRADING RUBRIC: - define a class named CollegeCourse - private fields for department, course number, credit hours, and tuition - public function(s) setting the private fields - public function that displays a CollegeCourse's data - define a class named LabCourse - inherit from CollegeCourse - include field that holds a lab fee - public function(s) setting the private field (don't forget the parent) - public function that displays a LabCourse's data (don't forget the parent) - main() function that instantiates a LabCourse, populates all private and inherited fields, calls both private and inherited methods

In: Computer Science

Suppose you have an all positive edge-weighted graph G and a start vertex a and asks...

Suppose you have an all positive edge-weighted graph G and a start vertex a and asks you to find the lowest-weight path from a to every vertex in G. Now considering the weight of a path to be the maximum weight of its edges, how can you alter Dijkstra’s algorithm to solve this?

In: Computer Science

#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...

#include <iostream>
#include <string>
#include <ctime>
using namespace std;


void displayArray(double * items, int start, int end)
{
        for (int i = start; i <= end; i++)
                cout << items[i] << " ";
        cout << endl;
}



//The legendary "Blaze Sort" algorithm.
//Sorts the specified portion of the array between index start and end (inclusive)
//Hmmm... how fast is it?
/*
void blazeSort(double * items, int start, int end)
{
        if (end - start > 0)
        {
                int p = filter(items, start, end);
                blazeSort(items, start, p - 1);
                blazeSort(items, p + 1, end);
        }
}
*/

int main()
{
        ////////////////////////////////////////////////////
        //Part 1:  Implement a method called filter.
        ////////////////////////////////////////////////////

        //Filter is a function that takes in an array and a range (start and end).
        //
        //Call the first item in the range the 'pivot'.
        //
        //Filter's job is to simply separate items within the range based on whether they are bigger or smaller than the pivot.
        //In the example array below, 13 is the pivot, so all items smaller than 13 are placed in indices 0-3.  The pivot is then placed at index 4, and all
        //remaining items, which are larger than the pivot, are placed at positions 5-10.  Note that the array is NOT sorted, just "partitioned" around
        //the pivot value.  After doing this, the function must return the new index of the pivot value.

        double testNumsA[] = { 13, 34.1, 43, 189, 4, 4.5, 18.35, 85, 3, 37.2, 5 };

        //The filter will place all items <= 13 to the left of value 13, and all items large than 13 to the right of 13 in the array.
        int p = filter(testNumsA, 0, 10);
        cout << p << endl; //should be 4, the new index of 13.
        displayArray(testNumsA, 0, 10);  //should display something like this:  5 3 4.5 4 13 18.35 85 189 37.2 43 34.1

        //One more example:
        double testNumsB[] = { 13, 34.1, 43, 189, 4, 4.5, 18.35, 85, 3, 37.2, 5 };
        p = filter(testNumsB, 2, 6);  //Here we are only interested in items from indices 2-6, ie, 43, 189, 4, 4.5, 18.35
        cout << p << endl; //should be 5
        displayArray(testNumsB, 0, 10); //Notice only indices 2-6 have been partioned:  13 34.1 18.35 4 4.5 43 189 85 3 37.2 5


        /////////////////////////////////////////////////////////////////////////////////
        //Part 2:  Uncomment "Blaze Sort".
        //Blaze Sort uses/needs your filter to work properly.
        /////////////////////////////////////////////////////////////////////////////////


        //Test if Blaze Sort correctly sorts the following array.
        double testNums[] = { 13, 34.1, 43, 189, 4, 4.5, 18.35, 85, 3, 37.2, 5 };

        blazeSort(testNums, 0, 10);

        displayArray(testNums, 0, 10);

        /////////////////////////////////////////////////////////////////////
        //Part 3:  Test how fast Blaze Sort is for large arrays.
        //What do you think the run-time (big-Oh) of blaze sort is?
        /////////////////////////////////////////////////////////////////////

        //Stress test:
        int size = 100; //test with: 1000, 10000, 100000,1000000, 10000000
        double * numbers = new double[size];

        for (int i = 0; i < size; i++)
        {
                numbers[i] = rand();
        }

        clock_t startTime, endTime;

        startTime = clock();
        blazeSort(numbers, 0, size - 1);
        endTime = clock();

        displayArray(numbers, 0, size - 1);
        cout << "Blaze sort took: " << endTime - startTime << " milliseconds to sort " << size << " doubles."  << endl;

        ////////////////////////////////////////////////////////////////////
        //Part 4: Sort Moby Dick, but this time with Blaze Sort
        ///////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////
        //1) Create a second version of Blaze Sort that sorts arrays of strings
        //(instead of arrays of doubles).
        //2) Download whale.txt from the previous lab.  Read the words from the file into
        //an array, sort the array with Blaze Sort, and then write the sorted words to an output file.
        //
        //This time, it has to be fast!  Must finish in under 10 seconds.
        

        return 0;
}

In: Computer Science

What are different methods by which you can compute the PCA? Does every method will yield...

What are different methods by which you can compute the PCA? Does every method will yield same result or answer at the end?

In: Computer Science

P4.2.7 Write a script that draws a bullseye with n concentric rings. The kth ring should...

P4.2.7 Write a script that draws a bullseye with n concentric rings. The kth ring should have inner radius k – 1 and outer radius k. (Thus, the innermost ring is just a radius-1 disk.) The kth ring should be colored white if k is odd and red if k is even.

This is a matlab problem

In: Computer Science

In this assignment, you are given partial code and asked to finish the rest according to...

In this assignment, you are given partial code and asked to finish the rest according to the specified requirement.

Problem statement: one benefit of inheritance is the code reuse. Instead of writing everything from scratch, you can write a child class that reuse all the features already existed in its parent, grandparent, great grandparent, etc. In the child class, you only need to supply small amount of code that makes it unique. In the following, you are given code for two classes: Coin and TestCoin. You study these classes first and try to understand the meaning of every line. You can cut and paste the code to Eclipse and run it.

  

The following Java codes are adapted from (John Lewis and William Loftus (2007). “Software Solutions Foundations of Program Design, 5th edition”, Pearson Education, Inc. pp. 220-222).

public class Coin {

private final int HEADS = 0;

private final int TAILS = 1;

private int face;

public Coin(){

flip();

}

public void flip(){

face = (int)(Math.random()*2);

}

public boolean isHeads(){

return (face == HEADS);

}

public String toString(){

String faceName;

if(face == HEADS){

faceName = "Heads";

}else{

faceName = "Tails";

}

return faceName;

}

}

public class TestCoin {

public static void main(String[] args) {

Coin myCoin = new Coin();

myCoin.flip();

System.out.println(myCoin);

if(myCoin.isHeads()){

System.out.println("The coin has head and you win.");

}else{

System.out.println("The coin has tail and you lose.");

}

}

}

To help your understanding, I give the following brief explanation. The Coin class stores two integer constants (HEADS and TAILS) that represent the two possible states of the coin, and an instance variable called face that represents the current state of the coin. The Coin constructor initially flips the coin by calling the flip method, which determines the new state of the coin by randomly choosing a number (either 0 or 1). Since the random() method returns a random value in the range [0-1) (the left end is closed and the right end is open), the result of the expression (int)(Math.random()*2) is a random 0 or 1. The isHeads() method returns a Boolean value based on the current face value of the coin. The toString() method uses an if-else statement to determine which character string to return to describe the coin. The toString() method is automatically called when the myCoin object is passed to println() in the main method.

The TestCoin class instantiates a Coin object, flips the coin by calling the flip method in the Coin object, then uses an if-else statement to determine which of two sentences gets printed based on the result.

After running the above two classes, the following is one of the possible outputs:

Tails

The coin has tail and you lose.

Design and implement a new class MonetaryCoin that is a child of the Coin class

The new class should satisfy the following requirement. Besides all the features existed in the Coin class, the MonetaryCoin will have an extra instance variable called value to store the value of a coin. The variable value is the type of integer and has the range of 0-10. The derived class should also have an extra method getValue() that returns the value. The new class should have two constructors: one is the no-argument constructor MonetaryCoin(), the other takes one parameter aValue of integer that is used to initialize the instance variable value. According to good practice, in the body of constructor, the first line should call its super class’ no-arg constructor. To demonstrate that your new class not only has the old feature of keeping track of heads or tails but also has the new feature of keeping track of value, you should overwrite/override the method toString(). The specification for the new toString() is:

Header: String toString()

This method gives values of all instance variables as a string.

Parameters: no.

Precondition: no.

Returns: a string that takes one of the following value:

If the face is 0, value is x (here it represents an integer in the range 0..10).

The returned string should be “The coin has head and value is x.”

If the face is 1, value is x,

The returned string should be “The coin has tail and value is x.”

As a summary, this class should have four methods:

Constructor: public MonetaryCoin()

Constructor: public MonetaryCoin(int aValue)

Getter method: public int getValue()

toString method: public String toString()()

Requirements

  • Comment your code. At the top of the program include your name, a brief description of the program and what it does and the due date.
  • The program must be written in Java and submitted via D2L.
  • The code matches the class diagram given above.
  • The code uses Inheritance.

Grading

Your grade in this assignment depends on the following:

  • Your submission meets all the requirements as described above.
  • The program is robust with no runtime errors or problems; it produces outputs that

Meet the requirement.

  • You follow the good programming practices as discussed in class (check document named “codingconventions”)
  • You follow the below submission instructions.

Required Work

You are asked to the following to get points:

  1. Write the class MonetaryCoin according to the specifications outlined in the Problem Statement section (16 pts)

In order to check the correctness of your code, I give you the following driver class. You must use this driver class to get full credit.

public class TestCoin {

public static void main(String[] args) {

int totalHeads = 0;

int totalValue = 0;

MonetaryCoin mCoin = new MonetaryCoin(1);

mCoin.flip();

System.out.println(mCoin);

if(mCoin.isHeads()) {

totalHeads += 1;

}

totalValue += mCoin.getValue();

mCoin = new MonetaryCoin(10);

mCoin.flip();

System.out.println(mCoin);

if(mCoin.isHeads()) {

totalHeads += 1;

}

totalValue += mCoin.getValue();

mCoin = new MonetaryCoin(2);

mCoin.flip();

System.out.println(mCoin);

if(mCoin.isHeads()) {

totalHeads += 1;

}

totalValue += mCoin.getValue();

mCoin = new MonetaryCoin(3);

mCoin.flip();

System.out.println(mCoin);

if(mCoin.isHeads()) {

totalHeads += 1;

}

totalValue += mCoin.getValue();

System.out.println("The total heads is " + totalHeads);

System.out.println("The total value is " + totalValue);

}

}

The driver class instantiates four MonetaryCoin objects. It has two variables (totalHeads, totalValue) to keep track of the total number of heads and the accumulative value. Finally, it prints two summary information about the total heads and the total value.

2. Using UML notation, draw the class diagram in the space below (your class diagram must match your code, your class diagram should contain TestCoin, Coin, MonetaryCoin and the relationships among them) (10 pts).

SUPPLY THE CLASS DIAGRAM IN THE SPCE BELOW TO SCORE YOUR POINTS:

3. Choose one method from the MonetaryCoin class and give one paragraph of description in the space below. You can focus on one or two of the following areas: 1) functional perspective such as what the method will do; or 2) implementation perspective such as whether the method is overloaded, etc.

In: Computer Science

MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are...

MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are the results filtered using COMPARISON and LOGICAL OPERATORS? Give one of these operators examples. Describe how parentheses can influence a query result.

In: Computer Science

Define the following terms and security objectives and give examples: Confidentiality Integrity Availability Authentication Authorization

Define the following terms and security objectives and give examples:

Confidentiality

Integrity

Availability

Authentication

Authorization

In: Computer Science

Write 3 vulnerabilities related to transport layer protocols and processes. Explain each vulnerability and it's significance...

Write 3 vulnerabilities related to transport layer protocols and processes. Explain each vulnerability and it's significance to your data security or privacy.

In: Computer Science

United States v. Barrington===Computer Crime.   Make an argument. Do you agree or disagree.   Search the internet...

United States v. Barrington===Computer Crime.  

Make an argument. Do you agree or disagree.  

Search the internet for this case, then search the book's PDF to find it.  

In: Computer Science

Use Zeller’s algorithm to figure out the days of the week for a given date in...

Use Zeller’s algorithm to figure out the days of the week for a given date in c.

W = (d + 13(m+1)/5 + y + y/4 + c/4 - 2c + 6) mod 7

Y is the year minus 1 for January or February, and the year for any other month

y is the last 2 digits of Y

c is the first 2 digits of Y

d is the day of the month (1 to 31)

m is the shifted month (March=3,...January = 13, February=14)

w is the day of week (0=Sunday,..,6=Saturday)

Output should look the following:

Please enter the day [YYYY/Month/Day]: 2020/1/1

Wednesday

In: Computer Science