Questions
1. Henry is having a problem with the electrical system on his current laptop. The battery...

1. Henry is having a problem with the electrical system on his current laptop. The battery for the laptop will not charge. Henry took the AC adapter and battery from another laptop that is known to work, and put them in his current laptop, but still the battery will not charge.

What possible actions can Henry take to make his laptop usable? (Select all that apply.)

a) Henry can replace the battery again, as the second battery could also be bad.

  b) Henry can replace the laptop system board.

c) Henry can purchase a new laptop.

d) Henry can use the laptop only when it’s connected to the power using the AC adapter.

2. When you turn on your computer for the day, you notice lights and fans but no beeps and no video. The Num Lock light does not come on.

What might be the problem with your computer? (Select all that apply.)

a) Motherboard has failed.

b) Video is not working properly.

c) Processor has failed or is not seated properly.

d) Power supply is not working properly.

e) RAM is not working properly.

In: Computer Science

Determine Theta for the following code fragments in the average case. Explain your answer. a =...

Determine Theta for the following code fragments in the average case. Explain your answer.

  1. a = b + c;

d = a + e;

  1. sum = 0;

for (i=0; i<3; i++)

for (j=0; j

sum++;

3. sum = 0;

for (i=1; i<=n; i*=2)

for (j=1; j<=n; j++)

sum++;

4. Assume that array A contains n values, Random takes constant time,

and sort takes n log n steps.

for (i=0; i

for (j=0; j

A[j] = Random(n);

sort(A, n);

5. Assume array A contains a random permutation of the values from 0 to n - 1.

sum = 0;

for (i=0; i

for (j=0; A[j]!=i; j++)

sum++;

In: Computer Science

CHALLENGE ACTIVITY 3.12.1: String comparison: Detect word. Write an if-else statement that prints "Goodbye" if userString...

CHALLENGE

ACTIVITY

3.12.1: String comparison: Detect word.

Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.

import java.util.Scanner;

public class DetectWord {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userString;

userString = scnr.next();

/* Your solution goes here */

}
}

In: Computer Science

Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The...

Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam

Use of any built in string function or any built in array function is not alllowed,

any help would be much appreciated.

In: Computer Science

Provide a screenshot of your script code and a screenshot of running the scripts with test...

Provide a screenshot of your script code and a screenshot of running the scripts with test inputs.

Write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake.  

In: Computer Science

convert +38 and +17 to binary using the signed 2s complement representation and enough digits to...

convert +38 and +17 to binary using the signed 2s complement representation and enough digits to accomaodate the numbers. Then perform the binary equivalent of (-38) and +17

In: Computer Science

Write a program that uses loops (both the for-loop and the while loop). This assignment also...

Write a program that uses loops (both the for-loop and the while loop). This assignment also uses a simple array as a collection data structure (give you some exposure to the concept of data structure and the knowledge of array in Java). In this assignment, you are asked to construct an application that will store and retrieve data. The sequence of data retrieval relative to the input is Last In First Out (LIFO). Obviously, the best data structure that can achieve this is a Stack. For simplicity, we require that the Stack to handle only characters. In this assignment, we will use two Java classes: the worker class and the application class. We will name the application class (the one that contains the main() method) SimpleStackApp; and name the worker class SimpleStack.

  • 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 the worker class SimpleStack, the for-loop, the while-loop

Design

Since this is a simple application, we are using the two classes: the worker class and the application class. The worker class is problem specific and the application class is generic (means the code in this class is almost the same for different programs). The application class “SimpleStackApp” contains a special method main(), which is the entry point of the program. The worker class “SimpleStack” is created by SimpleStackApp and is used by it. Thus the relationship between the worker class and the application class is an association relationship. The following UML diagram shows this design.

Supplied Partial Code

To help you get started, I give you partial code that implements several methods indicated in the above class diagram (you can cut and paste them to Eclipse). You are required to supply the missing code that will produce the expected outputs.

List 1: partial code for SimpleStack (the worker class)

-----------------------------------------------------------------------------------

class SimpleStack {

                char[] data; // this array holds that stack

                int tos;        // index of top of stack

                // Construct an empty stack given its size.

                SimpleStack(int size) {

                        data = new char[size]; // create the array to hold the stack

                        tos = 0;

}

                // Push a character onto the stack.

void push(char ch) {

                        if(isFull()) {

                                System.out.println(" – -- Stack is full.”);

                                return;

                        }

                        data[tos] = ch;

                        tos++;

                }

                // Pop a character from the stack.

char pop() {

                        if(isEmpty()) {

                                System.out.println(" – -- Stack is empty.”);

                                return (char) 0; // a placeholder value

                        }

                        tos--;

                     return data[tos] ;

                }

                // You are asked to finish this method.

boolean isEmpty() {

                       // finish the method according the spec specified later.

                }

                // You are asked to finish this method.

boolean isFull() {

                       // finish the method according the spec specified later.

                }

}

-------------------------------------------------------------------------------------

List 2: partial code for SimpleStackApp (the application class)

-----------------------------------------------------------------------------------

class SimpleStackApp {

public static void main(String[] args) {

int i;

char ch;

System.out.println(“Dmonstrate SimpleStack\n”);

// Construct 10-element empty stack.

SimpleStack stack = new SimpleStack(10);

                       

                                System.out.println("Push 10 items onto a 10-element stack.”);

// push the letters A through J onto the stack.

System.out.print("Pushing: ”);

for(ch = ‘A’; ch < ‘K’; ch++) {

                                System.out.print(ch);

                                stack.push(ch);

}

               

                                System.out.println("\nPop those 10 items from stack.”);

// Now, pop the characters off the stack.

// Notice that order will be the reverse of those pushed.

System.out.print("Popping: ”);

for(i = 0; i < 10; i++) {

ch = stack.pop();

                                System.out.print(ch);

}

                               System.out.println("\n\nNext, use isEmpty() and isFull() “ +

“to fill and empty the stack.”);

// Push the letters until the stack is full.

System.out.print("Pushing: ”);

for(ch = ‘A’; !stack.isFull(); ch++) {

                                System.out.print(ch);

                                stack.push(ch);

}

               System.out.println();

// Now, pop the characters off the stack until it is empty.

System.out.print("Popping: ”);

while(!stack.isEmpty()) {

ch = stack.pop();

                                System.out.print(ch);

}

                               System.out.println("\n\nNow, use a 4-element stack to generate “ +

“ some errors.”);

// In the space below, you are asked to supply the missing

//code that will produce the output given in the required work

//section.

}

}

Now, use a 4-element stack to generate some errors

The given partial code will produce the output from “Outputs:” to the line “Now, use a 4-element stack to generate some errors.” Your task here is to supply the missing code in this class that will produce the last 2 lines shown below.

Pushing: 12345 --- Stack is full.

Popping: 4321 --- Stack is empty.

In: Computer Science

MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of...

MATLAB Coding. Please answer with respected Matlab code format

HW 2_5

Determine the two roots of f(x) = 2x cos(2x) − (x − 2)^2 , using falsepos.p, accurate to 3 sig figs. Plot these points on the graph with a star marker.

In: Computer Science

The program reads a text file with student records (first name, last name and grade on...

  • The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). <--- Completed
  • Need help on this
  • Then it prompts the user to enter a command, executes the command and loops. The commands are the following:
    • "all" - prints all student records (first name, last name, grade, type).
    • "excellent" - prints students with grade > 89.
    • "ok" - prints students with grade <= 89.
    • "end" - exits the loop the terminates the program.

import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;

public class Students
{
public static void main (String[] args) throws IOException
{ String first_name, last_name;
int grade, count=0;
Scanner fileInput = new Scanner(new File("students.txt"));
//Object st;
ArrayList<Student> st = new ArrayList<Student>();
while (fileInput.hasNext())
{
first_name = fileInput.next();
last_name = fileInput.next();
grade = fileInput.nextInt();

if (grade>89)
st.add(new Excellent(first_name, last_name, grade));
else
st.add(new Ok(first_name, last_name, grade));

count++;
}
  
for (int i=0; i<st.size(); i++)
{
if (st.get(i) instanceof Excellent)
st.get(i).info();
else
st.get(i).info();
}   
  
System.out.println("There are " + count + " students");
  
}
}

public class Ok implements Student
{
private String fname, lname;
private int grade;
  
public Ok(String fname, String lname, int grade)
{
this.fname = fname;
this.lname = lname;
this.grade = grade;
}

public void info()
{
System.out.println(fname + " " + lname + " "+ grade + "\t" + "ok");
}
}

public class Excellent implements Student
{
private String fname, lname;
private int grade;

public Excellent(String fname, String lname, int grade)
{
this.fname = fname;
this.lname = lname;
this.grade = grade;
}

public void info()
{
System.out.println(fname + " " + lname + " "+ grade + "\t" + "excellent");
}
}


public interface Student
{
void info();
}

In: Computer Science

I need to create Create a new empty ArrayList, Ask the user for 5 items to...

I need to create Create a new empty ArrayList, Ask the user for 5 items to add to a shopping list and add them to the ArrayList (get from user via the keyboard). Prompt the user for an item to search for in the list. Output a message to the user letting them know whether the item exists in the shopping list. Use a method that is part of the ArrayList class to do the search. Prompt the user for an item to delete from the shopping list and remove it. (be sure to handle the case where they don’t want to delete anything). Use a method that is part of the ArrayList class to do the delete. Prompt the user for an item to insert into the list. Ask them what they want to insert and where they want to insert it (after which item). Use a method that is part of the ArrayList class to do the insertion. Output the final list to the user. It keeps giving me cannot define errors import java.util.ArrayList; import java.util.Scanner;

I keep getting cannot define errors

import java.util.ArrayList;
import java.util.Scanner;

public class ShoppingList {
   private static Scanner scanner = new Scanner(System.in);
   private static ShoppingList shoppingList = new ShoppingList();
  
   public static void main (String[] args) {
       boolean quit = false;
       int choice = 0;
       printInstructions();
      
       while(!quit) {
           System.out.println("Enter your choice: ");
           choice = scanner.nextInt();
           scanner.hasNextLine();
          
           switch(choice) {
           case 0:
               printInstructions();
               break;
              
           case 1:
               shoppingList.getShoppingList();
               break;
              
           case 2:
               addItem();
               break;
              
           case 3:
               modifyItem();
               break;
              
           case 4:
               removeItem();
               break;
              
           case 5:
               searchForItem();
               break;
              
           case 6:
               processArrayList();
               break;
              
           case 7:
               quit = true;
               break;
           }
       }
       }
       public static void printInstructions() {
           System.out.println("\nPress");
           System.out.println("\t - To Print The Instructions");
           System.out.println("\t - To Add Item");
           System.out.println("\t - To Modify Item");
           System.out.println("\t - To Remove Item");
           System.out.println("\t - To Search for an Item");
           System.out.println("\t - To Process Array List");
           System.out.println("\t - To Not Continue");
          
       }
      
       public static void addItem() {
           System.out.print("Add : Shopping Item: ");
           shoppingList.addShoppingItem(scanner.nextLine());
          
       }
       public static void modifyItem() {
           System.out.print("Modify: Enter the Item: ");
           String curItem = scanner.nextLine();
          
           System.out.print("Modify: Replace with: ");
           String newItem = scanner.nextLine();
          
           shoppingList.modifyShoppingItem(curItem, newItem);
          
       }
      
       public static void searchForItem() {
           System.out.print("Item Search: ");
           String searchItem = scanner.nextLine();
           if(shoppingList.onFile(searchItem)) {
               System.out.println("Item " + searchItem + " is on the list");
           }
           else {
               System.out.println(searchItem + "Is not found");
           }
       }
       public static void processArrayList() {
           ArrayList<String> newArrayList = new ArrayList<String>();
           newArrayList.addAll(shoppingList.getShoppingList());
          
           ArrayList<String> anotherArrayList = new ArrayList<>(shoppingList.getShoppingList());
          
           String[] myArray = new String[shoppingList.getShoppingList().size()];
           myArray = shoppingList.getShoppingList().toArray(myArray);
       }
public static void setShoppingList(ArrayList<String> shoppingList) {
   this.shoppingList = shoppingList;
           }
  
public void getShoppingList() {
   System.out.println("You have " + shoppingList.size() + " items")
   for(int i=0; i< shoppingListsize(); i++) {
       System.out.println((i+1) + " . " + shoppingList.get(i));
   }
}
public void modifyShoppingItem(String currentItem, String newItem) {
   int position = findItem(currentItem);
   if(position >= 0) {
       modifyShoppingItem(position, newItem);
   }
   }
private void modifyShoppingItem(int position, String item) {
   shoppingList.set(position, item);
   System.out.println("Shopping Item " + (item) + " has been modified");
}
public void removeItem(String item) {
   int position = findItem(item);
   if(position >= 0) {
       removeItem(position);
   }
}
private void removeItem(int position) {
   shoppingList.removeItem(position);
}
private int findItem(String searchItem) {
   return shoppingList.indexOf(searchItem);
}
public boolean onFile(String item) {
   int position = findItem(item);
   if(position >= 0) {
       return true;
   }
   return false;
}
}

In: Computer Science

•Preferred customers who order more than $1000 are entitled to a 5% discount, and an additional...

•Preferred customers who order more than $1000 are entitled to a 5% discount, and an additional 5% discount if they used the store credit card. •Preferred customers who do not order more than $1000 receive a $25 bonus coupon. •All other customers receive a $5 bonus coupon.Design the Logic in Structured English Design the Logic using Decision Tablex•Preferred customers who order more than $1000 are entitled to a 5% discount, and an additional 5% discount if they used the store credit card. •Preferred customers who do not order more than $1000 receive a $25 bonus coupon. •All other customers receive a $5 bonus coupon.

In: Computer Science

If a superclass is abstract, then its subclass must implement all of the abstract methods in...

If a superclass is abstract, then its subclass must implement all of the abstract methods in the superclass. Is this statement true or false?A. trueB. false

I appreciate if you add some descriptions

In: Computer Science

In the java programming language. How would you find if THREE (3) numbers in an array...

In the java programming language. How would you find if THREE (3) numbers in an array add up to a certain sum so for example if my array element consists of: INPUT: 200, 10, 50, 20 and my output asks if these elements add to: 270? YES (200+50+70) 260? YES (200+10+50) 30? NO What method would you suggest to look through the elements in an array (which im going to add through a text file) and determine if these sums exist in O(n^2)?

In: Computer Science

Does every algorithm have a running-time equation? In other words, are the upper and lower bounds...

Does every algorithm have a running-time equation? In other words, are the upper and lower bounds for the running time (on any specified class of inputs) always the same?

In: Computer Science

Write a program to compute answers to some basic geometry formulas. The program prompts the user...

Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is the length of a side. For the circles, this same value becomes the diameter. Use the meter value input to calculate the results in square (or cubic) meters and then print the answers in square (or cubic) meters. Area of a square (length times width) Area of a circle (pi times radius squared) How much bigger the area of the square is than the circle (see previous calculations) Round the length down to the next whole number of meters, compute the volume of a cube with this value as the length of its side Round the length up to the next whole number of meters, compute the volume of a cube with this value as the length of its side. You are to run the program three times using the following input values: 1000 1999.9 299.4 Please turn in the program and the outputs of running the program three times as directed. Be sure to use good style, appropriate comments and make use of constants in this program. Important Notes For the constant PI, please use 3.14159 Use the floor() and ceil() functions to round down and up respectively. For example, ceil(3.02) is 4. Be sure to #include to get access to these two functions Sample Output Your output format should look similar in style to the one below. Geometry formulas by (Your name) Enter one floating point number for length, 123.4 The number you entered is 123.4 cm or 12.34xx m. Area of square xx.xxxxxxx sq. m. Area of a circle xx.xxxxxxx sq. m. Difference is xx.xxxxxxxx sq. m. Cube volume rounded down is xx.xxxxxxxx cu. m. Cube volume rounded up is xx.xxxxxxxx cu. m. Press any key to continue

In: Computer Science