Questions
* Javascript * Describe an advantage or why someone would choose this loop type over another....

* Javascript *

  1. Describe an advantage or why someone would choose this loop type over another. Some things to consider and ask yourself:
    When would you use a for loop over a while loop? When would you use a while loop over a for loop? When would you use a do...while loop over a while loop?
  2. Give an example that fits the loop type's optimal use case (short answer, not code). Example scenario for a for loop (do not copy, be creative):
    Given an array of 100 numbers, iterate over each element/index and calculate the sum.

In: Computer Science

Using HTML: Create a Book of the Month Club Web site. The home page should describe...

Using HTML: Create a Book of the Month Club Web site. The home page should describe the current month's selection, including book title, author, publisher, ISBN, and the number of pages. Create separate Web pages for book selections in each of the last three months. Add links to the home page that opens each of the three Web pages. Save the home page as BookClub.html, and save the Web Pages for previous months using the name of the month.

BOOK: Principles of HTML, XHTML, and DHTML: The Web Technologies Series
CHAPTER 2 Building, Linking, Publishing Basic Web Pages
PROBLEM 2-1

In: Computer Science

PYTHON A Class for a Deck of Cards We will create a class called Card whose...

PYTHON

A Class for a Deck of Cards

We will create a class called Card whose objects we will imagine to be representations of playing cards. Each object of the class will be a particular card such as the '3' of clubs or 'A' of spades. For the private data of the class we will need a card value ('A', '2', '3', ... 'Q', 'K') and a suit (spades, hearts, diamond, clubs).

Before we design this class, let's see a very simple main() (also called the client, since it uses, or employs, our class) that instantiates a few Card objects and displays their values on the screen. We want to do a lot of fun things with our Card, but not yet. We start very carefully and slowly.

from enum import Enum


def main():
    card1 = Card()
    card2 = Card('5')
    card3 = Card('9', Suit.HEARTS)
    card4 = Card('j', Suit.CLUBS)
    card5 = Card('1', Suit.DIAMONDS)

    if not card2.set(2, Suit.CLUBS):
        print("GOOD: incorrect value (2 (int), CLUBS) passed to Card's set()\n")
    if not card2.set('2', Suit.CLUBS):
        print("BAD: incorrect value ('2', CLUBS) passed to Card's set()\n")

    print(str(card1) + "\n" + str(card2) + "\n" +
          str(card3) + "\n" + str(card4) + "\n"
          + str(card5) + "\n")

    card1 = card4

    # test assignment operator for objects
    print("after assigning card4 to card1:")
    print(str(card1) + "\n" + str(card4)
          + "\n")

We can't run this main() without embedding it into a full program that has the Card class definition, but let's look at a copy of the run anyhow, so we can see what the correct output for this program should be:

GOOD: incorrect value (2 (int), CLUBS) passed to Card's set()

(A of Spades)
(2 of Clubs)
(9 of Hearts)
(J of Clubs)
(A of Spades)

after assigning card4 to card1:
(J of Clubs)
(J of Clubs)

We can learn a lot about what class Card must be and do by looking at main() and the run. Let's make a list of things that we can surmise just by looking at the client.

  • We are instantiating several Card objects and sending a varying number of arguments to the constructor. For example, look at this code fragment:
   card1 = Card()
   card2 = Card('5')
   card3 = Card('9', Suit.HEARTS)
   card4 = Card('j', Suit.CLUBS)
   card5 = Card('1', Suit.DIAMONDS)

We see that card1 is instantiated with no arguments. This tells us that the class has a constructor (always __init__()) that does not require any arguments. Do you remember how that's done? Right! Either a default constructor (no formal parameters) or a constructor with all default parameters. So it must be one of those types.

However, we also see that card2 is providing the constructor with one argument and card3, card4 and card5 with two arguments. So, we must also have at least a 2-parameter constructor, and whatever number of parameters it has, they must all be default parameters (not counting the self parameter).  

  • Looking again at that same fragment, we see that those Card objects which are being instantiated with two arguments are supplying both a value and a suit:
       card3 = Card('9', Suit.HEARTS)
    The first argument, the value, is passed to the constructor as what data type? It is surrounded by quotes '5', '9', 'j', so it must be a string. (See Note On String Delimiters, below.) But the suit is a little odd. It is a construct like Suit.CLUBS or Suit.DIAMONDS with no quotes around it. Words without quotes in Python usually refer to variable names, but in this case, that's not what they are. Here we are using enumerated or enum types. You may not have had enums in your first course, so you will learn about them this week.
  • A set() method is used to assign values to a Card object, e.g., card1.set(2, clubs). Such instance methods are called mutators. This works the same way as a 2-parameter constructor but is used after, not during, the birth (construction) of the object. Furthermore, the set() method seems to be returning a bool value because we are treating the return value as if it were either True or False, e.g., if not card2.set(2, Suit.CLUBS)... . Apparently, this mutator method is returning a True if the assignment was successful and a False, otherwise.
  • By looking at the error message printed in the run, we can see that most ints (like 2) are not allowed to be passed to the constructor as the Card value. We have to pass a string, like '2', to represent the "deuce" (card with value '2'), for instance. The mutator method must be checking to make sure that the character passed in is between an ASCII '2' and an ASCII '9', or is one of the picture or ten Card characters 'A', 'K', 'Q', 'J', 'T'.  
  • It looks like a picture or 10 Card value passed in as a lower case char ('a','k', 'q', 'j', 't') is being up-cased (converted to upper case) by the mutator or constructor.
  • The assignment operator works as it should:  card1 = card4 assigns the object to which the reference card4 points to the reference card1, so that both references then point to the same object — a technique called aliasing. We'll prove this in a later version of the client today.
  • Finally, there is a __str__() instance method. In CS 3A, we learned that this is a special instance method that we write for most of our classes to help our clients use objects sometimes like strings(print( my_object)), and sometimes like primitive (immutable) types (print( "My object is" + str(my_object)) .

In: Computer Science

(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note:...

(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note: you must be 18 or older to vote && is the symbol for And | | is the symbol for Or ! is the symbol for Not USE AND, OR, OR NOT TO SEE IF THEY'RE OLD ENOUGH TO VOTE and display appropriate message USE AND, OR, OR NOT TO SEE IF THEY ENTERED A NUMBER LESS THAN 0 and display appropriate message USE AND, OR, OR NOT TO SEE IF THEY ENTERED 18 or higher and display appropriate message DISPLAY A MENU OF CHOICES: 1. Democrat 2. Republican 3. Independent ASK USER TO ENTER THE NUMBER OF THEIR CHOICE USE IF STATEMENT WITH == TO CHECK THEIR CHOICE use a different message for each choice if they enter something other than 1,2, or 3 use AND, OR, or NOT to find out display a message

In: Computer Science

Hierarchical clustering is sometimes used to generate K clusters, K > 1 by taking the clusters...

Hierarchical clustering is sometimes used to generate K clusters, K > 1 by taking the clusters at the K th level of the dendrogram. (Root is at level 1.) By looking at the clusters produced in this way, we can evaluate the behavior of hierarchical clustering on different types of data and clusters, and also compare hierarchical approaches to K-means.
The following is a set of one-dimensional points: {6, 12, 18, 24, 30, 42, 48}.

(a)
For each of the following sets of initial centroids, create two clusters by assigning each point to the nearest centroid, and then calculate the total squared error for each set of two clusters. Show both the clusters and the total squared error for each set of centroids.
i.{18, 45}
ii. {15, 40}
(b)
Do both sets of centroids represent stable solutions; i.e., if the K-means algorithm was run on this set of points using the given centroids as the starting centroids, would there be any change in the clusters generated?
(c)
What are the two clusters produced by single link?
( d) Which technique, K-means or single link, seems to produce the "most natural" clustering in this situation? (For K-means, take the clustering with the lowest squared error.)
(e)
What definition(s) of clustering does this natural clustering correspond to? (Well-separated, center-based, contiguous, or density.)
(f)
What well-known characteristic of the K-means algorithm explains the previous behavior?

In: Computer Science

CODE IN JAVA A computer company sells software and computer packages for $75. Quantity discounts are...

CODE IN JAVA

A computer company sells software and computer packages for $75. Quantity discounts are given based on the following criteria:

Quantity          Discount

10 - 19             20%
20 - 49             30%
50 - 99             40%
100 or more    50%

Be sure the user is presented with all necessary information, then prompt the user for the quantity of packages. Display the total cost of the purchase making sure to apply appropriate discounts.

Example Output:

Demon software and computers is offering discounts on the Vic Package. This package includes a computer and needed software to perform basic daily functions. The Vic package sells for $75.00. Discounts are given based on quantity. The discounts are listed below:

10 - 19 gives a 20% discount
20 - 49 gives a 30% discount
50 - 99 gives a 40% discount
100 or more gives a 50% discount

How many would you like to purchase?

25

You purchased 25 packages. Your total is $1312.50

In: Computer Science

Write a query that returns all of the main information that are associated with the purchase...

Write a query that returns all of the main information that are associated with the purchase orders that have an amount greater than 70% of the average amount of all purchase orders, the output should be sorted by the largest purchase order amount

In: Computer Science

public class Classroom { // fields private String roomNumber; private String buildingName; private int capacity; /**...

public class Classroom
{
// fields
private String roomNumber;
private String buildingName;
private int capacity;

/**
* Constructor for objects of class Classroom
*/
public Classroom()
{
this.capacity = 0;
}
  
/**
* Constructor for objects of class Classroom
*
* @param rN the room number
* @param bN the building name
* @param c the room capacity
*/
public Classroom(String rN, String bN, int c)
{
setRoomNumber(rN);
setBuildingName(bN);
setCapacity(c);
}
  
/**
* Mutator method (setter) for room number.
*
* @param rN a new room number
*/
public void setRoomNumber(String rN)
{
this.roomNumber = rN;
}
  
/**
* Mutator method (setter) for building name.
*
* @param bN a new building name
*/
public void setBuildingName(String bN)
{
this.buildingName = bN;
}
  
/**
* Mutator method (setter) for capacity.
*
* @param c a new capacity
*/
public void setCapacity(int c)
{
this.capacity = c;
}
  
/**
* Accessor method (getter) for room number.
*
* @return the room number
*/
public String getRoomNumber()
{
return this.roomNumber;
}
  
/**
* Accessor method (getter) for building name.
*
* @return the building name
*/
public String getBuildingName()
{
return this.buildingName;
}
  
/**
* Accessor method (getter) for capacity.
*
* @return the capacity
*/
public int getCapacity()
{
return this.capacity;
}
}

  1. Modify this class so that it implements the Comparable interface. This will involve adding a method called compareTo() to your Room class and making some other changes to the class definition.
  2. Now write a main program (in a new class called TestComparable) that creates an ArrayList of Rooms. Add about 5 Rooms to the list so that they're randomly ordered. Print the list in its current order. Then call the sort() method to sort the Rooms based on capacity. Print the list in the new sorted order.

In: Computer Science

1.  Give the top five most popular operating systems of the world. Justify your answer and explain...

1.  Give the top five most popular operating systems of the world. Justify your answer and explain why they are the most popular.

2.(a) What is the biggest advantage of implementing thread in user space? What is the biggest disadvantage?

(b) What is the biggest advantage of implementing thread in kernel space? What is the biggest disadvantage?

In: Computer Science

Playing with encryption: Write a program that will read a four-digit integer entered by the user...

Playing with encryption:

Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original number. Print out both the encrypted and decrypted integer.

In: Computer Science

please write the code in C format avoid using (<<count>>) Assume that you work for a...

please write the code in C format avoid using (<<count>>)

Assume that you work for a travel agency. Write a C program that performs 7 different tasks described below
for this company. The flights have the following
daily departure and arrival times:

hotel name cost ride cost
Rose 248$ 0$
Poprock 90$ 25$
flower 128$ 20$
departure time arrival time cost
7:15 am 8:25am 231$
8:15 am 9:25am 226$
9:15am 10:25am 226$
10:15am 11:25am 283$
11:15am 12:25pm 283$
3:15pm 4:25pm 226$
4:15pm 5:25pm 226$
5:15pm 6:25pm 401$

a) Based on the time entered by the customer, the closest departure time is displayed using 12- hour format.

b)the customer is asked if they would like a hotel and for how many days. hotel cost is mentioned above. Calculate the total cost (before taxes) and display it (flight + hotel for n number of days +ride).

c) now there is 2 types of discount:
Discount1: If the total fee is a multiple of 11, then the
customer gets a 6% discount.
Discount2: An additional discount of 7% is given to those customers whose subtotal
after discount1 is a multiple of the sum of digits of the customer’s day of birth.
Three examples are given below for your convenience. See Sample Input / output
for more clarification.
• Ex1: If the day of birth entered is 3, the customer will get an additional 7%
discount if the sub-total of their purchase after discount1 is a multiple of 3.
• Ex 2: If the day of birth entered is 12, the customer will get an additional 7%
discount if their purchase after discount1 is a multiple of 3 (since sum of digits of
day of birth (12) is 3).

c)13% tax is applied to the total cost and the final bill is?

In: Computer Science

I am having a hard time with these questions regarding JDBC and XML. 1) Which type...

I am having a hard time with these questions regarding JDBC and XML.

1)

Which type of driver provides JDBC access via one or more ODBC drivers?

Group of answer choices

a) Type 1 driver

b) Type 2 driver

c) Type 3 driver

d) Type 4 driver

2)

Which of the following provides the application-to-JDBC Manager connection.

a) JDBC Driver

b) JDBC API

c) JDBC Driver API

d) SQL Server

3)

With the code below, indicate JDBC coding best practices that have been violated (this code does compile and run!):

import java.sql.*;

public class StudentData{
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(args[2], args[0], args[1]);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM Student WHERE rollno='" + args[3] + "'");

while (rs.next()) {
System.out.print(rs.getInt(1) + "\t");
System.out.print(rs.getString(2) + "\t ");
System.out.print(rs.getInt(3) + "\t ");
System.out.println(rs.getDate(4));
}
stmt.close();
stmt = null;
rs.close();
rs = null;
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}

  

a) The program imports all of the java.sql packages

b) This program does not properly close database resources

c) The program should catch SQLException

d) The program should not string-concatenate a query, but rather use a PreparedStatement.

e) The program retrieves data from a ResultSet by column number instead of by name

f) The program hardcodes the name of the JDBC driver and the SQL query. These should be externalized from the compilable code.

g) Answer 1, 3 and 5 only

h) Answers 1-6 all apply

4)

In JDBC, it is a good practice to use standard SQL statement and avoid using db specific query until necessary.

a) True

b) False

In: Computer Science

Windows 10: Cortana and Windows Search Why might you or a business might want to remove...

Windows 10: Cortana and Windows Search

  1. Why might you or a business might want to remove metadata from a document, or a photo shared on the web?
  2. Where must the text you type in a search appear in a word?
  3. How would you search for files between 0-16KB?
  4. Pick a date about one week ago. In File Explorer’s search box, find all files that were modified before that date. What search command did you use?

In: Computer Science

Trying to create a Class of Employees that holds every Employee created from a class called...

Trying to create a Class of Employees that holds every Employee created from a class called Employee in c++

In: Computer Science

C++ The minimum function. (a) Write a function that takes two integers and returns the value...

C++ The minimum function.

(a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of the smaller one according to the less-than operation. Test the function in main() using the integer and character types.

In: Computer Science