Questions
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...

how to write in java;

Write a method int[] coPrime[int num, int[]numbers]

{

// instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x

}

Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.

In: Computer Science

no need to explain 11. What is output by the following code segment? boolean isHighTemp =...

no need to explain

11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot

12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”); }while (???) A) n < 10 B) n = 2

13. In Java, the value of the expression 23 % 6 is: A) 5 B) 2 C) 3 D) 4

14. Given the constant declaration final int CAPACITY = 10; which of the following is NOT a valid use of CAPACITY? A) CAPACITY += CAPACITY; B) CAPACITY = 100; C) int currentSize = CAPACITY + 9; D) A and B above

15. Given the following declaration and the method header for the Max method double x, y, z; Page 4 double Max(double, double); which of the following shows a syntactically invalid call to Max method: A) z = Max(x, y); B) z = Max((x+y+z); C) System.out.print(Max(x, (y+x) )); D) z = y + Max((y-x), (x+y));

In: Computer Science

This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much! Create...

This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much!

  1. Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field.

  2. Use class named ShowStudent that instantiates a Student object to test your class. Compute the Student grade point average, and then display all the values associated with the Student.

  3. Create a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values.

Please double check your work and complete all three parts. This is my FOURTH TIME posting and each solution I've received has been incomplete/had errors. Please only help if you can complete all parts, I would appreciate it.

In: Computer Science

Write a program to use Math methods to calculate and display the followings: Prompts the user...

Write a program to use Math methods to calculate and display the followings:

  1. Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle.
  2. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is entered.
  3. Prompts the user to enter two integers m & n, and displays the result of m^n.
  4. Prompts the user to enter a decimal number and displays the number rounded, the floor, and the ceiling of the number.
  5. Prompts for lower bound number L and upper bound number U, and displays a random number between L and U using the following formula:  L + (int)(Math.random() * (U - L + 1))

Evaluate all your answers to avoid shock & regret.

Display meaningful output for each task.

You only need to check if the input is valid in requirement # 2. For all the others, you can assume valid input is entered.

In JAVA

In: Computer Science

I am a travel agent, I book in-city ride tickets and also ship your luggage to...

I am a travel agent, I book in-city ride tickets and also ship your luggage to the next destination. 1-NYC All Around Town it is $29.00 2-Big Bus NYC Tour it is $49.00 3-NYC one day guided Sightseeing Tour it is $89.00 4-Circle Line Complete Manhattan Island Cruise is $44.00 5-Viator VIP: Empire State Building, Statue of Liberty and 9/11 Memorial is $129.00 I also provide a quote for your shipment to be mailed to your next destination. In order to calculate our quote, we need to know the total weight of the shipment in pounds, the distance in miles and whether or not there are hazardous materials in the shipment (e.g. batteries). The calculation for the quote is as follows: Quote = .65 * # of miles + .83 * # of pounds If there is hazardous materials in the shipment, there is an extra cost of .20 * # of pounds If the distance for the delivery is less than 150 miles and the total weight for the shipment is greater than 500 pounds, then there should be a 10% discount off of the total quote. Create a c# console app using conditional statement

In: Computer Science

string string_long_division (string dividend, string divisor) { string ans; //code in here return ans; } Create...

string string_long_division (string dividend, string divisor)
{
string ans;


//code in here


return ans;
}

Create a function that takes in 2 strings called dividend (is a string because this could be greater than the size of an int) and divisor (is a string because this could be greater than the size of an int) and performs long division on them and returns the result as a string.
It would be preferred if the code was written in c++.
THIS CODE SHOULD WORK IN CASES WHERE THE DIVISOR IS ALSO GREATER THAN THE SIZE OF ANY VARIATION OF AN INT.

For example: dividend = "10000000000000000000000" and divisor = "1000000000000000000000" should be able to work in the code.
Thanks!

In: Computer Science

Use inheritance to implement the following classes: A: A Car that is a Vehicle and has...

Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the number_of_engines it has. Add public methods to set and get the values of these variables. When an airplane is printed (using the toString method), its name, max_speed and number_of_engines are shown. C: Write a VehicleDemo.java class that does the following: 1- Creates an instance of a Car and an Airplane class. 2- Assign values to the name, speed, number_of_cylinders (for the Car object) and number_of_engines (for the Airplane object) variables. 3- Compares which vehicle goes faster and prints the result. 4- Prints the instances of the car and airplane classes.needed coding in java

In: Computer Science

Implement a dictionary application using C++ with the following features: Load a dictionary file. Given a...

Implement a dictionary application using C++ with the following features:

  • Load a dictionary file.

  • Given a prefix string that the user specifies, print the first word or all words in the dictionary with that string as their prefix.

  • Given two strings A and B that the user specifies, replace all occurrences of A in the dictionary file with B.

  • Spawning a new editor (e.g., vim) to allow the user to modify the dictionary file. Save the dictionary file afterwards.

All your source code must be put within one (1) file and your program should not have any extra library dependencies.

Please provide the coding in C and should compile with "$ gcc dict.c -g -O1 -o dict"

Good example of the file running is "./dict -d dict.txt"

In: Computer Science

Create a scenario on University management system that provides services to students and professors alike. and...

Create a scenario on University management system that provides services to students and professors alike. and prepare use case diagrams, sequence diagrams, activity diagram(s), and class diagrams for the system developing.

In: Computer Science

Give a bash command that runs "ps -ef" , but only displays items whose UID is...

Give a bash command that runs "ps -ef" , but only displays items whose UID is not equal to root

In: Computer Science

Right now Lili is in a strange planet and she wants to study the calendar system...

Right now Lili is in a strange planet and she wants to study the calendar system of said planet. Each year on the planet consists of N months and each month on the planet consists of exactly K days. Bibi arrived on the planet on the first day of the first month, and now she has T questions: What’s the month and date on Bibi’s A i-th day on the planet? Help her to answer the questions!

Format Input

The first line contains the numbers N and K. The next N lines contain Si which is the name of the i-th month. The next line then contains T and next T lines contain A i.

Format Output

For each question, output one line starting with “Case # X: ” (without quotes) where X is the question number (starting from 1) followed by the month and date on Bibi’s A i-th day on the planet.

Constraints

• 1 ≤ N, K ≤ 100

• 1 ≤ Q ≤ 1000

• 1 ≤ A i ≤ 1000000

• 1 ≤ | Si | ≤ 100 (|Si| means the length of Si )

• Si only contains lowercase English letters a-z

Sample Input 1 (standard input)

12 30

january

february

march

april

may

june

july

august

september

october

november

december

10

1

2

31

69

360

361

362

420

720

1337

Sample Output 1 (standard output)

Case #1: january 1

Case #2: january 2

Case #3: february 1

Case #4: march 9

Case #5: december 30

Case #6: january 1

Case #7: january 2

Case #8: february 30

Case #9: december 30

Case #10: september 17

NOTE: USE C LANGUAGE, DONT USE FUNCTION(RESULT,RETURN),VOID,RECURSIVE, USE BASIC CODE AND CODE IT UNDER int main (){, constraint must be the same

In: Computer Science

Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal...

Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal fractions given the number of threads and perform Parallel MergeSort pThreads. Your algorithm should work for 2 threads.

ParallelMergeSort.c

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

#define SIZE 100

int array[SIZE];

void fillArrayWithRandomNumbers(int arr[SIZE]) {
for(int i = 0; i<SIZE; i++) array[i] = rand()%100;
}

void printArray(int arr[SIZE]) {
for(int i = 0; i<SIZE; i++) printf("%5d", arr[i]);
printf("\n");
}

typedef struct StartEndIndexes {
int start;
int end;
} StartEndIndexes;

// Runs mergesort on the array segment described in the argument. Spawns two threads to mergesort each half
// of the array segment, and then merges the results.
void* mergeSort(void* args) {

// Please fill this out!
return NULL;
}

int main() {
srand(time(0));
StartEndIndexes sei;
sei.start = 0;
sei.end = SIZE - 1;
  
// 1. Fill array with random numbers.
fillArrayWithRandomNumbers(array);
  
// 2. Print the array.
printf("Unsorted array: ");
printArray(array);
  
// 3. Create a 2 threads for merge sort.
  
// 4. Wait for mergesort to finish.
  

// 5. Print the sorted array.
printf("Sorted array: ");
printArray(array);
}

Pease fill out bolded sections!

In: Computer Science

**** PLEASE DO NOT COPY AND PASTE FROM ANOTHER SOURCE BECAUSE THE ANSWER IS INCOMPLETE********* Introduction:...

**** PLEASE DO NOT COPY AND PASTE FROM ANOTHER SOURCE BECAUSE THE ANSWER IS INCOMPLETE*********

Introduction: IN C PROGRAMMING

For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the position of a word in the key text (starting at 0), and the second number denotes the position of the letter in the word (also starting at 0). For instance, given the following key text (the numbers correspond to the index of the first word in the line)

[0] 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe;

[13] All mimsy were the borogoves, And the mome raths outgrabe.

[23] "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!

[36] Beware the Jubjub bird, and shun The frumious Bandersnatch!"

[45] He took his vorpal sword in hand: Long time the manxome foe he sought—

The word "computer" can be encoded with the following pairs of numbers:

35,0 catch!

5,1 toves

43,3 frumious

48,3 vorpal

22,1 outgrabe.

34,3 that

23,6 "Beware

7,2 gyre

Placing these pairs into a cipher text, we get the following:

35,0,5,1,43,3,48,3,22,1,34,3,23,6,7,2

If you are encoding a phrase, rather than just a single word, spaces in the original english phrase will also appear in the ciphered text. So, the phrase "all done" (using the above Jabberwocky poem) might appear as: 0,3,1,4,13,1 6,0,46,2,44,2,3,2

Only spaces in the key text should be considered delimiters. All other punctuation in the key text are to be considered part of a key word. Thus the first word in the Jabberwocky poem, 'Twas, will have the following characters and positions for key word 0:

Position 0: '

Position 1: T

Position 2: w

Position 3: a

Position 4: s

Developing the Program:

You should approach this assignment in several parts. The first part will be to write a menu driven program that prompts the user for the following actions:

  1. Read in the name of a text file to use as a cipher key
  2. Create a cipher using the input text file (and save the result to a file)
  3. Decode an existing cipher (prompt user for a file to read containing the cipher text)
  4. Exit the program

For each choice, create a stub function that will be completed in the remaining steps.

After testing your menu, continue to fill in the stub functions with the following specifications:

Choice #1

For this menu choice, you will prompt the user for the name of a cipher text file (such as the Declaration of Independence). You will read this text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. You may assume that you will use no more than the first 5,000 words in the text, and no more than the first 15 characters in a word. However, there is no guarantee that the text will have 5000 words or less and any word in the text is 15 characters or less.

Choice #2

If no file has been chosen for Choice #1 (i.e. the user goes directly to Choice #2 without first choosing Choice #1), you will first prompt the user to enter a cipher text and read it into memory (presumably by calling the function that would be called by Choice #1). You will prompt the user to enter a secret message (in plain text - such as "Computer Science is the best major at GMU!") that is terminated by pressing the "Enter" key. You can assume that the length of this message will be less than 1500 characters (including the carriage return and NULL terminator). You will then parse this message, character by character, converting them to lower case as you go, and find corresponding characters in the words found in the key text word array. You can do this by going through each word in the word array, and then each character in each word, until you find a match with the current message character. There are more efficient ways to perform this operation, and you are encouraged to implement them instead of the given method. Once a character match is found, you will write the index of the word and the index of the character to a character string that you will later write out to a text file. Spaces are to be placed into the text as found in the message and will be used to delimit the separate words in the secret message. Once the message has been encoded, prompt the user for the name of a file to save the encoded message to, and save it to that file.

Choice #3

You will prompt the user for the name of a file containing an encoded text (i.e. a file containing number pairs). Your program will read the file and decode the the text using the indexes pairs given for each character in the word and the text file chosen for Choice #1. If no file has been chosen for Choice #1 (i.e. the users goes directly to Choice #3 without first choosing Choice #1), you will prompt the user to enter a cipher text and read it into memory (presumably by calling the function that would be called by Choice #1). Spaces found in the file are to be treated as spaces in the decoded text. You can assume that the number of characters in the encoded text file is 5000 or less, including any carriage returns or NULL terminator characters. Once the text is decoded, print the message to standard output.

Choice #4

Exit the program.

Additional Specifications:

  • In order to introduce some "randomness" in the specific character encoding, you will generate a random number i from 0..9 inclusive (use the last four digits of your G Number as the seed), and use the ith instance of that character found in the text. (If fewer than i instances of the character is found in the text, loop back and continue the search from the beginning of the document.)
    • Example: Suppose the letter to encode is a 'c'. Using the sentences just above, we find that there are the following 'c' characters:
      • In order to introduCe some "randomness" in the speCifiC CharaCter enCoding, you will generate a random number i from 0..9 inClusive (use the last four digits of your G Number as the seed), and use the ith instanCe of that CharaCter found in the text.
      • If the random number returns 6, then you will use the 'c' from the word "inclusive." (Start counting from 0). If the random number returns 2, you would the second c found in the word "specific."
  • If a given character in the secret message is not found in any word of the text, replace that character with the '#' character in the encoded text (a single '#' character replaces a word/position pair).
  • Files and filenames will follow the standard CS262 conventions (username, lab section, etc. at top of file, and as part of filename).
  • Each menu choice (except #4) should call a separate function to perform the operation.
  • You can assume that the message to encrypt or decrypt will be less than 1500 characters.
  • Your program will be compiled using a Makefile

Predefined C functions that may be useful for this project:

strtok()

strlen()

tolower()

atoi()

Options for extra credit:

  1. Use dynamic memory for the arrays (up to 5 points additional credit)
  2. Finding the original Beale treasure and sharing it with your professor (up to 1000 points additional credit)

In: Computer Science

Today BandN book stores is currently running a deal on e-books. Customers will receive a 15%...

Today BandN book stores is currently running a deal on e-books. Customers will receive a 15% discount off their entire order. Customers who buy 20 or more e-books will receive 20% off instead. Each book costs a flat $8.99. Write a C++ program that will calculate the final cost of your order, using functions. Global variables are not allowed unless they are constant. Information should be passed with parameters. Your main function should not do any of the tasks in the list below. The program will print a set of instructions for the user and give a brief explanation of the purpose. It will ask the user for the number of books you wish to download. It will display the number of books to be downloaded, the subtotal for the books, the discount earned and the total cost for the books. You should write a user-defined function to perform each of the following tasks: • print the instructions • prompt and read the number of books to be downloaded • calculate the sub total for those books • calculate the discount for your order • calculate the total cost for the downloaded books • print the results in a neat and well-labeled form

In: Computer Science

public boolean areArrays(int[] arr1, int[] arr2){ // 1. initial check: both arrays need to have the...

public boolean areArrays(int[] arr1, int[] arr2){
// 1. initial check: both arrays need to have the same length, return false if not the same
// 2. return true if both given arrays are equals(same values in the same indices), false otherwise
if(arr1.length != arr2.length){
return false;
}
for(int i = 0; i < arr1.length; i++){
if(arr1[i] != arr2[i]){

}
}
return true;
}

public int getIndexOfWord(String[] arr, String word){
// if found, return the index of word, otherwise return -1
for(int i = 0; i < arr.length; i++){
if(arr[i].equals(word)){
return i;
}
}
return -1;
}

public boolean arrayContainsWord(String[] arr, String word){
// return true if array contains specific word, false otherwise
for(int i = 0; i < arr.length; i++){
if(arr[i].equals(word));
return true;
}
return false;
}

--- Scanner ------

In: Computer Science