Questions
Write a JAVA program that reads a text file. Text file contains three lines. Place each...

Write a JAVA program that reads a text file.

Text file contains three lines.

Place each line in an array bucket location.

Add to the end of the array list.

Print the array.

In: Computer Science

Part 1: Write a program that has 2 classes. The first class is a test class...

Part 1:

Write a program that has 2 classes. The first class is a test class with 2 methods; a main method, and a static method called drinkMilk(). The drinkMilk method returns void, and will throw an exception of type OutOfMilkException. The purpose of this exercise is to demonstrate that a method can get information back to the caller through an exceptions object that is thrown inside the called method and caught in the calling method.   (OutOfMilkException is the second class that you will create.)

The drinkMilk method will: save what time you start drinking your milk, here’s how:

            In the System class there is a method:

public static long currentTimeMillis()

Returns the current time in milliseconds.

Then, in an infinite loop, while (true) generate random integers between 0 – 1000 and perform an int division using the random integer as the denominator. Use anything except 0 as the numerator. You must use the Random class to generate random integers, not the Math class. Eventually you will execute a divide by zero.

Each time you generate a random number print out “Gulp.” Use print instead of println. When a division by zero exception is thrown, the drinkMilk method will catch the ArithmeticException exception. Within the catch block throw an exception of type OutOfMilkException.

(You are catching one kind of exception, creating a more descriptive exception that describes the situation, and throwing that exception.)

The outOfMilkException object will contain a value that indicates how long it took to drink the milk – in milliseconds, i.e., how long it took to generate a 0 value. The main method that catches the OutOfMilkException will printout the number of milliseconds that it took to drink the milk.

This demonstrates that information is "thrown" from the drinkMilk method to the main method. Keep in mind that the purpose of this exercise is to “throw” a piece of information from one method to another without using the usual mechanisms for passing information from one method to another, i.e., parameters and return values.

Note: It is not good practice to put any calculation inside an Exception object. These objects are holders of data only! No arithmetic operators, no method calling. Maybe a String concat + once in a while. The methods in the exceptions should never contribute to the solution; their role is exclusively to know about what went wrong, and to be thrown and caught.

Part 2: Assertions

Background:

The ‘assert’ keyword was added to Java in version 1.2. That caused a problem. “assert” was used for many years in C++, and when Java did not provide that mechanism, many Java programmers added a public method called ‘assert’ into their code.   When Java 1.2 came out, all of the code that used ‘assert’ wouldn’t compile, because they had a method name that matched a keyword.

assert somethingTrue;    // does nothing

assert somethingThatIsFalse;    // this will throw an AssertionError

        It became necessary to add some qualifiers to the compile and run commands in Java, so that assertions might be used at compile time and/or at run time. Since we are doing all of our work within Eclipse, you will need to figure out how to turn these on within the Eclipse environment.   Eclipse is generating the commands to compile and run the java programs – that’s good, we don’t have to type the commands, but it makes it harder when we need to change what command is generated.

The compile and run switches for Assertions are quite elaborate. Assertions are only used during development. Everyone will want to turn off this feature at run-time when the product is released.

When you have figured out how to turn Assertions on / off within Eclipse, post your solution on the discussion board. If the answer is already there, but you can add something, do it. You don’t need to re-post something that is already there.

Coding exercise:

Demonstrate using the assert keyword. Create a private method that takes an int parameter.

If the value passed in is negative, the method will assert something that is false, causing the method to throw an AssertionError.

Pass the value that was passed into the method to the constructor of the AssertionError class.

All of this is done with a single assert statement.

Why did I ask you to make this method private? It works the same with public methods. Put a comment in the code if you can find an answer that question. (It isn’t something you can figure out, you will need to read about the convention and the reason for having that convention.)

In: Computer Science

PYTHON ?Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and...

PYTHON ?Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length; it has two methods that calculate and return its area and volume. You also need to include a client class (with the main method) to test these two classes.??

In: Computer Science

1) Consider any recent acquisition by Facebook. Why do you think Facebook purchased the company? Suggest...

1) Consider any recent acquisition by Facebook. Why do you think Facebook purchased the company? Suggest ways in which the app has been monetized.

In: Computer Science

Compare and contrast (1) the procedural/functional approach (defining a function for each operation with the function...

Compare and contrast (1) the procedural/functional approach (defining a function for each operation with the function body providing a case for each data variant) and (2) the object-oriented approach (defining a class for each data variant with the class definition providing a method for each operation). (250 own words)

In: Computer Science

Create a program in C that performs the following tasks: Define a macro arraySize of size...

Create a program in C that performs the following tasks:

  • Define a macro arraySize of size n
  • Create two arrays of size n.
  • Pass these arrays to a function fillArrays that randomizes enough integers between 1-100 (inclusive) to fill both arrays.
  • Print both of these arrays.
  • Pass the filled arrays to a second function mergeArrays that creates a third array of size 2n.
  • Still in mergeArrays, store the values from the original two arrays into your new array in reverse.
  • Print out your sorted array.

In: Computer Science

Conduct some research and define all aspects of Descriptive Statistics such as Mean, Median, Mode, Range...

Conduct some research and define all aspects of Descriptive Statistics such as Mean, Median, Mode, Range and Percentiles.

In: Computer Science

Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

Create an abstract class Employee. Your Employee class should include the following attributes:

First name (string)

Last name (string)

Employee id (string)

Employee home street address (string)

Employee home city (string)

Employee home state (string)

Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the Employee class to initialize the common instance variables but also initializes the HourlyRate and HoursWorked. Implement the Employee abstract earnings method in HourlyEmployee to calculate the earnings for a week. Note that earnings is hourly rate * hours worked.

Create a test class that prompts the user for the information for two hourly employees, creates the 2 two hourly employees objects, calls the earnings method then displays the attributes and earnings for each of the two hourly.

SUBMIT YOUR JAVA CODE AND PSUEDOCODE

In: Computer Science

8.14 LAB: Warm up: Contacts (C Programming Only) You will be building a linked list. Make...

8.14 LAB: Warm up: Contacts (C Programming Only)

You will be building a linked list. Make sure to keep track of both the head and tail nodes.

(1) Create three files to submit.

  • ContactNode.h - Struct definition, including the data members and related function declarations
  • ContactNode.c - Related function definitions
  • main.c - main() function

(2) Build the ContactNode struct per the following specifications:

  • Data members
  • char contactName[50]
  • char contactPhoneNum[50]
  • struct ContactNode* nextNodePtr
  • Related functions
  • CreateContactNode() (2 pt)
  • InsertContactAfter() (2 pts)
    • Insert a new node after node
  • GetNextContact() (1 pt)
    • Return location pointed by nextNodePtr
  • PrintContactNode()


Ex. of PrintContactNode() output:

Name: Roxanne Hughes
Phone number: 443-555-2864


(3) In main(), prompt the user for three contacts and output the user's input. Create three ContactNodes and use the nodes to build a linked list. (2 pts)

Ex:

Person 1
Enter name:
Roxanne Hughes
Enter phone number:
443-555-2864
You entered: Roxanne Hughes, 443-555-2864

Person 2
Enter name:
Juan Alberto Jr.
Enter phone number:
410-555-9385
You entered: Juan Alberto Jr., 410-555-9385

Person 3
Enter name:
Rachel Phillips
Enter phone number:
310-555-6610
You entered: Rachel Phillips, 310-555-6610


(4) Output the linked list. (2 pts)

Ex:

CONTACT LIST
Name: Roxanne Hughes
Phone number: 443-555-2864

Name: Juan Alberto Jr.
Phone number: 410-555-9385

Name: Rachel Phillips
Phone number: 310-555-6610

In: Computer Science

Chapter 20, programming challenge 2: Linked List Sorting and Reversing Modify the LinkedList1 class presented in...

Chapter 20, programming challenge 2: Linked List Sorting and Reversing

Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedListDemo class to support sort and reverse commands, and use it to test the new methods.

This must be done in java (netbeans)

In: Computer Science

What is the main difference between arrays and ArrayLists? Arrays can be resized, ArrayLists cannot. ArrayLists...

  1. What is the main difference between arrays and ArrayLists?
    1. Arrays can be resized, ArrayLists cannot.
    2. ArrayLists can be resized, Arrays cannot.
    3. Arrays can hold more information than ArrayLists
    4. ArrayLists can hold more information than Arrays

  1. What method is used to add a new element to the end an ArrayList?
    1. .add
    2. .new
    3. .insert
    4. .put

  1. What is the proper syntax for accessing the third element of an ArrayList called Books?
    1. Books.elementAt(3);
    2. Books.elementAt(2);
    3. Books[3];
    4. Books[2];

  1. What is overloading?
    1. Having a method in a child class which replaces a method of the same name in the parent class
    2. Having two or more method with the same name but different parameters
    3. Writing more methods than a class can support
    4. Writing more child classes than a parent class can support

  1. What is overriding?
    1. Having a method in a child class which replaces a method of the same name in the parent class
    2. Having two or more method with the same name but different parameters
    3. Writing more methods than a class can support
    4. Writing more child classes than a parent class can support

  1. When does a constructor run?
    1. When the program ends
    2. When the program starts
    3. When an object is released from memory
    4. When an object is created.

  1. Which of the following is the proper syntax for having a class named Child inherit from a class named Parent?
    1. public class Child extends Parent
    2. public class Child implements Parent
    3. public class Child : Parent
    4. public class Child -> Parent

  1. What is a virtual method?
    1. A method that can be overridden but does not have to be overridden
    2. A method with no definition that must be overridden
    3. A method that cannot be overridden
    4. Virtual methods are not supported by C#

  1. What is an abstract method?
    1. A method that can be overridden but does not have to be overridden
    2. A method with no definition that must be overridden
    3. A method that cannot be overridden
    4. Abstract methods are not supported by C#

  1. True/False. An abstract class cannot be instantiated.
    1. True
    2. False

  1. Which of the following is valid:
    1. ParentClass myObject = new ChildClass();
    2. ChildClass myObject = new ParentClass();
    3. new ParentClass myObject = ChildClass();
    4. new ChildClass myObject = ParentClass();

  1. MessageBox._______ causes a popup to display on the screen
    1. popup
    2. display
    3. show
    4. dialog

  1. The _________ property of the textbox, label, and many other controls determines what is currently written in the control.
    1. label
    2. writing
    3. text
    4. name
  1. Complete the following code:

foreach(int i ______ intArr)

    1. in
    2. on
    3. under
    4. over
  1. A private variable is
  1. Only in a method
  2. Only accessible from a method methods
  3. Part of a class, not an instance.
  4. Part of an instance, Not a class.
  1. The static Keyword
  1. Allows access to a method without an instantiated object
  2. Allows instance variables to be accessed from within a static method
  3. Only has one copy of itself during runtime
  4. Both 1 & 3
  5. All of the above.
  1. Properties are different than fields because:
  1. Fields are static
  2. Properties are static
  3. Properties can perform actions such as method calls
  4. Fields can perform actions such as method calls.
  1. An object is a(n) ____________ of a class.
    1. figment
    2. institution
    3. instantiation
    4. child
  1. Class fields are created with the ____________ modifier by default.
    1. Public
    2. Private
    3. Internal
    4. Caustic
  2. The thisreference is (Circle all that apply)
    1. Confusing
    2. Straight-Forward
    3. Implied in certain circumstances
    4. Better than a sharp stick in the eye.

In: Computer Science

Question 12 PYTHON: Write a function named first_last that takes a single parameter, string_list (a list...

Question 12 PYTHON:

Write a function named first_last that takes a single parameter, string_list (a list of strings). The
function first_last should return a list of the strings in string_list that are not empty and that begin
and end with the same letter.

For example, the following would be correct input and output for the function first_last.

response = ['to', 'that', 'I', 'say', '', 'hurrah']
print(first_last(response))
['that', 'I', 'hurrah']

Question 13 (20 points)

Write a function named number_luck. The function number_luck takes two parameters:

1. lucky, a list of lucky numbers between 2 and 12, inclusive
2. unlucky, a list of unlucky numbers between 2 and 12, inclusive

Every number is either lucky, unlucky or boring (neither lucky nor unlucky).

The function number_luck should

1. ask the user for a number in the range 2 to 12 (you may assume that the user provides valid
input)
2. print a message echoing the user’s number and stating whether it is lucky, unlucky or boring
3. return an integer that is the user’s number

For example, the following would be correct input and output.

>>> a_num = number_luck([7, 11], [2, 3, 12])
Give me a number from 2 to 12: 7
7 is lucky. You win!
>>> print(a_num)
7

In: Computer Science

Which areas of the network would a college IT staff most likely NOT have to redesign...

Which areas of the network would a college IT staff most likely NOT have to redesign as a direct result of many students bringing their own tablets to school to access school resources? And explain the function of each design (choose 4) (1pt each correct ans. + 3 pts. for each explanation)?

Extranet:

Intranet:

Wired LAN:

Wireless LAN:

Wireless WAN:

In: Computer Science

(C++)Problem #1: Coin Tossing Simulation: Write a program that simulates coin tossing. Let the program prompt...

(C++)Problem #1: Coin Tossing Simulation: Write a program that simulates coin tossing. Let the program prompt the user to enter the number of tosses N and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip() that takes no arguments and returns 0 for tails and 1 for heads. The program should produce different results for each run.

Sample Input / Output

Enter the number of tosses N: 1000

The total number of Heads is: 495

The total number of Tails is: 505

In: Computer Science

PLEASE MAKE UP ANY 3 NONLINEAR PROGRAMMING PROBLEMs BY YOUR OWN AND SOLVE IT in either...

PLEASE MAKE UP ANY 3 NONLINEAR PROGRAMMING PROBLEMs BY YOUR OWN AND SOLVE IT in either EXCEL, matlab or lingo.

In: Computer Science