Questions
Explain whether this statement is true or false. If false, explain the correct operation. “an LCD...

Explain whether this statement is true or false. If false, explain the correct operation. “an LCD segment is given 1 to turn it on and 0 to turn it off, just like the colored LEDs”. Explain whether it’

In: Computer Science

Write a program named Triangle.java that asks for the lengths of the three sides of a...

Write a program named Triangle.java that asks for the lengths of the three sides of a triangle and computes the perimeter if the input is valid. The input is valid if the sum of every pair of two sides is greater than the remaining side. For example, the lengths 3, 4, and 5 define a valid triangle: 3 plus 4 is greater than 5; 4 plus 5 is greater than 3, and 5 plus 3 is greater than 4. However, the lengths 7, 2, and 4 do not specify a valid triangle because 2 plus 4 is not greater than 7.

Here is the output from running the program twice. Your program’s output does not have to look exactly like this, but it must convey the same information. Use input is shown in bold.

Enter lengths of sides of the triangle: 3 4 5
The perimeter of the triangle is 12.0

Enter lengths of sides of the triangle: 7 2 4
Those sides do not specify a valid triangle.

In: Computer Science

Write one Java program and satisfy the following requirements: Rewrite the following if -else if -...

Write one Java program and satisfy the following requirements:

  1. Rewrite the following if -else if - else statement as an equivalent switch statement.  

if (letter == 'A' | | letter == 'a')

        System.out.println("Excellent");

        else if (letter == 'B' | | letter == 'b')

               System.out.println("You can do better");

        else if (letter == 'C' | | letter == 'c')

               System.out.println("Try harder");

        else if (letter == 'D' | | letter == 'd')

               System.out.println("Try much harder");

        else

               System.out.println("Try another major! ");

  1. Write a code to read three different integers and find the larger value by using       if ... else if … else statement.

3. Given the following tax table information, write Java code to assign the double taxRate appropriately given the double pay. Select the selection statement (if, if-else, or switch) that makes the most sense.

     If pay is more than 100,000, tax rate is 40%

     If pay is more than 60,000 and less than or equal to 100,000, tax rate is 30%

     If pay is more than 30,000 and less than or equal to 60,000, tax rate is 20%

     If pay is more than 15,000 and less than or equal to 30,000, tax rate is 10%

     If pay is more than 5,000 and less than or equal to 15,000, tax rate is 5%

     If pay is less than or equal to 5,000, tax rate is 0%

In: Computer Science

A shipping company uses the following function to calculate the cost (in dollars) of shipping based...

A shipping company uses the following function to calculate the cost (in dollars) of shipping based on the weight of the package in pounds:

Weight Cost
0 < w <= 1 3.5
1 < w <= 3 5.5
3 < w <= 10 8.5
10 < w <= 20 10.5

Your program, named  Shipping.java should ask for the weight of the package and display the shipping cost. If the weight is negative or zero, display a message “Invalid input.” If the weight is greater than 20, display a message “The package cannot be shipped.”

Here is an example of the output of the program. Your output does not have to look exactly like this, but it must reflect the same information. User input is shown in bold.

Enter weight of package in pounds: 5.7
Cost: $8.50

Enter weight of package in pounds: 25.2
The package cannot be shipped.

What I did:

import java.util.Scanner;

public class Shipping
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);

System.out.println("Enter weight of package in pounds"+" ");

double weight = input.nextDouble();

double cost;
  

if(weight<=1&&weight>0)
{
cost=3.5;
System.out.println("Cost:"+" "+"$"+cost);
  
  
}
else if(weight<=3&&weight>1)
{
cost=5.5;
  
System.out.println("Cost:"+" "+"$"+cost);
}
else if(weight<=10&&weight>3)
{
cost =8.5;
System.out.println("Cost:"+" "+"$"+cost);

}
else if(weight<=20&&weight>10)
{
cost=10.5;
System.out.println("Cost:"+" "+"$"+cost);
}
else if(weight==0||weight<0)
{
  
System.out.println( "Invalid input.");
  
  
}
else
{
  
System.out.println( "The package cannot be shipped.");

}
}   
}

Is this correct?

In: Computer Science

Question 11 (1 point) What is wrong with the following recursive method, which is meant to...

Question 11 (1 point)

What is wrong with the following recursive method, which is meant to compute the sum of all numbers from 1 to n? public int summation(int n) { return n + summation(n-1);}

Question 11 options:

The method lacks a base case

The method lacks a recursive step

The base case is incorrect

The recursive step is incorrect

Question 12 (1 point)

In which of these situations does it make sense to consider a recursive solution?

Question 12 options:

The problem involves arithmetic such as addition, multiplication, etc.

The problem is really confusing

The problem involves something that must be done repeatedly

The problem can be divided up into smaller, but identical, sub-problems

Question 13 (1 point)

An incorrect recursive algorithm sometimes results in a StackOverflowError. Which of the following statements is true about this type of error?

Question 13 options:

The recursive step may be incorrect

The base case may be missing

This is analogous to an infinite loop for an iterative solution

All of these

None of these

Question 14 (1 point)

The following two method signatures are equivalent.

public getItem(E[] items)

public getItem(T[] items)

Question 14 options:

True
False

Question 15 (1 point)

You are looking through the documentation for a software library you want to use in your application and see this method. What types of objects can be passed to it as an argument? Choose all valid options.

public int doSomething(E arg) { ... }

Question 15 options:

instances of Double

instance of Number

instances of a class called E

instances of Object

Question 16 (1 point)

Based on this method signature, what types of objects can be passed to it as an argument? Choose all valid options.

public <E extends Comparable<E>> int doWork(E arg) { 
}

Question 16 options:

instances of Double

instance of Number

instances of a class called E

instances of Object

In: Computer Science

Using Java Write a simple calculator which can add, subtract, multiply, and divide. Here are the...

Using Java

Write a simple calculator which can add, subtract, multiply, and divide. Here are the specifications for the calculator:

  • The calculator has one “accumulator”, which holds the result of all prior calculations. The calculator is set to 0.0 when the calculator is turned on (i.e., instantiated).
  • On the console, the user then enters an operator (+, -, *, or /) and a number. Your console will then apply the operator and operand to the number in the accumulator, and store the result back in the accumulator
  • The user can also enter ‘R’ to reset the accumulator to 0, or the letter “P” to turn the calculator’s power off

The calculator will need to trap the following exception conditions:

  • If the user enters something other than +, -, *, /, R, or P for the operator, an UnknownOperatorException exception should be thrown.
  • If the user enters something other than a valid number for the operand, a NumberFormatException exception should be thrown. (You can ignore this exception if the user enters R or P for the operator.)
  • If the user tries to divide by zero, an DivideByZeroException exception should be thrown.

The NumberFormatException is already provided in Java. You will write your own UnknownOperatorException and DivideByZeroException classes.

All exception classes should have at least two constructors:

  • one which takes no arguments and provides a default Exception message
  • another which takes a String as an argument and sets the contents of the String as the Exception message

Provide listings for your Calculator class (or classes) and your exception class. Also, provide a PrintScreen(s) demonstrating each of the six operators and three exceptions in use.

Here’s a sample dialog that a user might have with the calculator:

  Your calculator is now on.
  The result is currently 0.0

  Enter an operator (+, -, *, or /) and a number, 
     "R" to reset, or "P" to turn off power
  + 5
  The result of 0.0 + 5.0  is 5.0
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  / 2
  The result of 5.0 / 2.0 is 2.5
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  / 0
  You cannot divide by 0.  The result is still 2.5.
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power  
  R
  The calculator has been reset to 0.
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  – 18.4
  The result of 0.0 - 18.4 is -18.4
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  * 20
  The result of -18.4 * 20.0 is -368.0
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  + abc
  "abc" is not a valid number.  The result is still -360.0 

  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power
  & 15
  "&" is not a valid operator.  The result is still -368.0  
 
  Enter an operator (+, -, *, or /) and a number,
     "R" to reset, or "P" to turn off power  
  P
  Good bye.

In: Computer Science

Solve in C language This program outputs a downwards facing arrow composed of a rectangle and...

Solve in C language

This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width.

(1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt)

(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base. (1 pt)

(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head. (2 pts)

(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt)

while (arrowHeadWidth <= arrowBaseWidth) {
    // Prompt user for a valid arrow head value
}

Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:

Enter arrow base height:
5
Enter arrow base width:
2
Enter arrow head width:
4

**
**
**
**
**
****
***
**
*

In: Computer Science

Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...

Write a MIPS Assembly Language program to perform the following operations:

  1. Request and read two integers from the console (Dn and Up),
  2. Call a recursive function to compute the result

int RecurseFunc( int Dn, int Up )

{

if( Dn < 1 ) return 0;

return Dn * Up + RecurseFunc( Dn - 1, Up + 1 );

}

  1. Print out the results

In: Computer Science

open up a new Java project on Eclipse named Review and create a new class called...

  • open up a new Java project on Eclipse named Review and create a new class called Review.java.
  • Copy and paste the below starter code into your file:

/**

* @author

* @author

* CIS 36B
*/

//write your two import statements here

public class Review {
  
    public static void main(String[] args) { //don't forget IOException
        File infile = new File("scores.txt");
        //declare scores array
        //Use a for or while loop to read in data from scores.txt to the array
        //call method
        //Use a for loop to write data from array into extraCredit.txt
      
    }
    
        
    /**
     * Write complete Javadoc comment here
     */
    //write your addExtraCredit method here   
  
}

  • Next, create a new text file named scores.txt
    • Rick-click the project. Go to New->File.
    • Name your file scores.txt
    • Make sure the text file gets saved inside the overall project folder (Review), not in the src folder
  • Now, copy and paste the following data (exam scores) into your scores.txt file:

90
95
86
41
79
56
90
83
74
98
56
81
64
99
12

  • Your program must declare an array of integers, and populate the array with the contents of the file.
    • You may assume that the length of the array is known to be 15 elements.
  • Next, write a method called addExtraCredit:
    • The addExtraCredit method takes in one parameter - an array of integers
    • It adds 2 to each element in the array (hint: think for loop)
    • It returns nothing
  • Inside of main, call the addExtraCredit method, passing it the array of exam scores.
  • Next, write the contents of the array to a file named extraCredit.txt.
    • Use PrintWriter to write out to the file (see lesson notes above).
  • When you are finished, extraCredit.txt should contain the following:
    • Don't forget the title!

Scores with Extra Credit:
92
97
88
43
81
58
92
85
76
100
58
83
66
101
14

  • Hint: Your program should include either 3 for loops or 2 for loops and a while loop.
  • If you get stuck, review today's lesson notes.
  • When extraCredit.txt contains the above data, submit your program to Canvas.
  • Both partners must submit to receive credit.

In: Computer Science

Write a Visual C# project that will allow the user an option to choose from four...

Write a Visual C# project that will allow the user an option to choose from four different countries. When a country is chosen, the program will display the country flag and information that the user wishes to see. The name of the country selected will be displayed in a label under the country's flag image. The user may also choose to display or hide the form's title, the country name, and the name of the programmer/developer.   Check boxes will be used for the display/hide choices. Radio buttons will be used for the country selection.

You may choose the countries to display and their corresponding flags to display. In the Canvas module, you will see a zip file of flag images or you may choose your own.

Note: see the Note from the previous projects. These are now considered Basic Expectations and are expected in each program you develop and submit for grading.

Additionally, include keyboard access keys for all option buttons, check boxes, and command buttons. (add to Basic Expectations)
Be sure the tab order is set in the most logical order for the user.   (add to Basic Expectations)

In: Computer Science

How can i modify my c code so that each number stored in the array is...

How can i modify my c code so that each number stored in the array is not the array index but the value of the array index converted to radians. I have already made a function for this converion above main().

Below is the code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float Deg2Rad (float degrees)
{
// Calculate & return value
float Result;
Result = ((M_PI*degrees)/180.0);
return (Result);
}

int main(void)
{
// Declare variables
int Array[90];
int i;

// Loop from 0 to 90 inclusive
for ( i = 0 ; i < 91 ; i++ )
{
Array[i] = i;
printf ("Array number %d contains value %d\n", i, Array[i]);
}

// Exit the application
return 0;
}

In: Computer Science

1. What is the difference between Write and WriteLine in Visual Basic? 2. Can there be...

1. What is the difference between Write and WriteLine in Visual Basic?


2. Can there be more than one variable in a Write or WriteLine? Do they have to be all variables of the same type? Show it by modifying your program. Submit the modified and duly documented program in Visual Basic.


3. Explain the possible assignments of values to numerical variables of different primitive types: integer assigned to integer, integer assigned to real, real assigned to integer and real assigned to real. Which assignments are possible and which give an error in Visual Basic?

In: Computer Science

Question 17 (1 point) What is the return type of this method? public <E extends Comparable<E>>...

Question 17 (1 point)

What is the return type of this method?

public <E extends Comparable<E>> int theMethod(E arg)

Question 17 options:

E

Comparable

int

arg

Question 18 (1 point)

What is the primary benefit of writing generic classes and methods?

Question 18 options:

Generic classes and methods are more type-safe

Generic classes and methods are shorter

Generic classes and methods are faster

Generic classes and methods are backwards compatible

Question 19 (1 point)

What is wrong with the following method?

public static E copy(E arg) {

E theCopy = arg.clone();

return theCopy;

}

Question 19 options:

The method cannot be static if it uses generics

The method calls clone on the argument, but that method is not guaranteed to exist for the argument

You cannot declare a variable (e.g. theCopy) with a generic type

The returned value does not match the method signature

Question 20 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a class scheduling application, and you need to keep track of the wait list for overbooked classes. If a student tries to register for a course that is full, she should be placed at the end of the wait list. If a student drops the course, the student currently at the beginning of the wait list should be moved into the class.

Question 20 options:

list

stack

queue

priority queue

Question 21 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to play a card game, and you need to keep track of the discard pile. When a player discards a card, it is placed at the top of the discard pile. If a player wants to pick up a card from the discard pile, she must take the card that is currently on the top.

Question 21 options:

list

stack

queue

priority queue

Question 22 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to help the human resource department of a company in scheduling interviews. As applications come in, the hiring manager gives them a score from 0 to 100 according to how well the applicant appears to fit the needs of the position. After a period of two weeks, interviews need to be scheduled. You need a data structure to tell the HR employee which applicant should next be scheduled for an interview. The choice is based on the applicant with the highest score.

Question 22 options:

list

stack

queue

priority queue

Question 23 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to track various statistics for the players on the active roster of a baseball team. The order in which the players are stored is not important, but you will frequently need to iterate over all of the players to compute aggregate statistics for the team.

Question 23 options:

list

stack

queue

priority queue

Question 24 (1 point)

What is the output of the following code?

public class Widget implements Cloneable {

public int count;

public FiddlyBit bit;

public Widget() {

bit = new FiddlyBit();

}

public Object clone() throws CloneNotSupportedException {

  return super.clone();

}

public String toString() {

  return "count = " + count + "; bit part number = " + bit.partNo;

}

class FiddlyBit {

  int partNumber;

}

public static void main(String[] args) {

Widget widgetA = new Widget();

widgetA.count = 5;

widgetA.bit.partNo = 111;

Widget widgetB = (Widget) widgetA.clone();

widgetB.count = 6;

widgetB.bit.partNo = 222;

System.out.println("widgetA: " + widgetA);

System.out.println("widgetB: " + widgetB);

}

}

Question 24 options:

widgetA: count = 5; bit part number = 111;
widgetB: count = 6; bit part number = 222;

widgetA: count = 6; bit part number = 222;
widgetB: count = 6; bit part number = 222;

widgetA: count = 6; bit part number = 111;
widgetB: count = 6; bit part number = 222;

widgetA: count = 5; bit part number = 222;
widgetB: count = 6; bit part number = 222;

Question 25 (1 point)

Which of the following is valid, assuming myPetStore is an instance of PetStore? Choose all that apply.

public interface Animal { 
 public abstract void eat();
} 

public class Pet implements Animal { 
 public void eat() { 
  System.out.println("Eating pet food"); 
 }
} 

public class Dog extends Pet { 
}

public class PetStore { 
 public void feedingTime(Animal a) { 
  a.eat(); 
 }
}

Question 25 options:

Animal anAnimal = new Animal();myPetStore(anAnimal);

Pet aPet = new Pet();myPetStore(aPet);

Dog aDog = new Dog();myPetStore(aDog);

None of these are valid

Previous PageNext Page

In: Computer Science

Please read the Specifications carefully. Also do not use any C library. Program Specifications Assuming that...

Please read the Specifications carefully. Also do not use any C library.

Program Specifications

Assuming that all input strings are non-empty (having length of at least 1) and shorter than MAX_LENGTH, implement the following string functions: • strgLen( s ): return the length of string s. • strgCopy( s, d ): copy the content of string s (source) to d (destination). • strgChangeCase( s ): for each character in the string, if it is an alphabet, reverse the case of the character (upper to lower, and lower to upper). Keep the non-alphabet characters as is. • strgDiff( s1, s2 ): compare strings s1 and s2. Return the index where the first difference occurs. Return -1 if the two strings are equal. • strgInterleave( s1, s2, s3 ): copy s1 and s2 to s3, interleaving the characters of s1 and s2. If one string is longer than the other, after interleaving, copy the rest of the longer string to s3. For example, given s1 = “abc” and s2 = “123”, then s3 = “a1b2c3”. If s1 = “abcdef” and s2 = “123”, then s3 = “a1b2c3def”. Notes: • Do not use any C library function at all in your code. Do not add any header file to the code. • The functions (algorithms) must be the most efficient in terms of running time and memory usage. • Submit file strg.c. Complete the header with your student and contact information. Include sufficient comments in your code to facilitate code inspection. • Submit a report in PDF with following information: references (sources); error conditions and actions taken; brief algorithm; running time of the function (algorithm) and a brief explanation. See the template a2report.docx for an example. • See file a2output.txt for sample input and output. • Your code will be graded automatically by a script, so make sure to strictly follow the specifications. • Do not use any output statements (for example, printf) in your code, or they will mess up the grading scripts. • Use the main( ) function provided to test your code. Understanding the code in the main( ) function is part of the assignment. Do not change the code in the main( ) function in the final submission, or your program will mess up the grading script.

/***********************************
* Filename: strg.c 
* Author: Last name, first name
* Email: Your preferred email address
* Login ID: Your EECS login ID
************************************/

#include <stdio.h>
#define MAX_LENGTH 100   // DO NOT CHANGE THIS CONSTANT

/******************  YOUR CODE STARTS HERE ******************/
/************************************************************/

/*
 * Input: non-empty string s
 * Output: return the length of s
 */ 
int strgLen( char s[ ] )
{
   /* ADD YOUR CODE HERE */
  
   return 0;
}


/*
 * Input: non-empty string s
 * Output: copy the content of string s to string dest
 */ 
int strgCopy( char s[ ], char dest[ ] )
{
   /* ADD YOUR CODE HERE */
  
   return 0;
}


/*
 * Input: non-empty string s
 * Output: for each character in string s, if it is an alphabet, reverse the  
 * case of the character.  Keep the non-alphabet characters as is.  
 */ 
int strgChangeCase( char s[ ] )
{
   /* ADD YOUR CODE HERE */
  
   return 0;
}


/*
 * Input: non-empty strings s1 and s2
 * Output: Return the index where the first difference occurs.
 * Return -1 if the two strings are equal.
 */ 
int strgDiff( char s1[ ], char s2[ ] )
{
   /* ADD YOUR CODE HERE */
  
   return 0;
}


/*
 * Input: non-empty strings s1 and s2
 * Output: copy s1 and s2 to s3, interleaving the characters of s1 and s2.  
 * If one string is longer than the other, after interleaving, copy the rest 
 * of the longer string to s3.  
 */
int strgInterleave( char s1[ ], char s2[ ], char d[ ] )
{
   /* ADD YOUR CODE HERE */
  
   return 0;
}

/*******************  YOUR CODE ENDS HERE *******************/
/************************************************************/

/*********  DO NOT CHANGE ANYTHING BELOW THIS LINE IN THE FINAL SUBMISSION *********/

/* main() function 
 */
int main()
{
  char op[ MAX_LENGTH ]; 
  char str1[ MAX_LENGTH ]; 
  char str2[ MAX_LENGTH ];
  char str3[ MAX_LENGTH ];  
  int index;
  
  do {
    scanf( "%s %s", op, str1 );
    switch( op[ 0 ] )
    {
    case 'l':   // length
    case 'L':
      printf( "%d\n", strgLen( str1 ) );
      break;
          
    case 'c':   // copy
    case 'C':
      strgCopy( str1, str2 );
      printf( "%s\n", str2 );
      break;
      
     case 'h':   // cHange case
     case 'H':
      strgChangeCase( str1 );
      printf( "%s\n", str1 );
      break;     
                
    case 'd':  // difference  
    case 'D':
      scanf( "%s", str2 );
      index = strgDiff( str1, str2 );
      if ( index < 0 )
        printf( "Equal strings\n" );
      else
        printf( "%d\n", index );      
      break;    
    
    case 'i':  // interleave
    case 'I':
      scanf( "%s", str2 );    
      strgInterleave( str1, str2, str3 );
      printf( "%s\n", str3 );      
      break;

    case 'q':  // quit
    case 'Q':
      /* To quit, enter character (action) 'q' or 'Q' and an arbitrary string.
         This is not elegant but makes the code simpler.  */  
      /* Do nothing but exit the switch statement */    
      break;
            
    default:  
      printf( "Invalid operation %c\n", op[0] );         
    }  // end switch
  } while ( op[ 0 ] != 'q' && op[ 0 ] != 'Q' );
  
  return 0;
}

In: Computer Science

Consider a router that has the following Routing Table contents: Destination Subnet Outgoing Interface Next Hop...

Consider a router that has the following Routing Table contents:

Destination Subnet

Outgoing Interface

Next Hop

50.62.8.0/24

Fa0/0

118.2.77.4

24.19.0.0/16

Fa0/1

59.16.1.1

0.0.0.0/0

Fa0/2

18.12.52.43

0.0.0.0/0 is the default route. When a packet arrives, the router checks the destination IP address of the packet to see in which subnet it falls. If the destination IP address does not fall within any of the specified subnets, then the default route is used as a last resort. The packet is consequently forwarded out Fa0/2.

  1. A packet with destination IP address 50.62.8.154 arrives to this router. Out what interface will this packet be sent?
  2. A packet with destination IP address 50.62.25.2 arrives to this router. Out what interface will this packet be sent?
  3. A packet with destination IP address 50.61.9.93 arrives to this router. Out what interface will this packet be sent?
  4. A packet with destination IP address 24.19.104.3 arrives to this router. Out what interface will this packet be sent?
  5. A packet with destination IP address 24.18.8.1 arrives to this router. Out what interface will this packet be sent?

In: Computer Science