Questions
JAVA Programming A complex number is a number in the form a + bi, where a...

JAVA Programming


A complex number is a number in the form a + bi, where a and b are real numbers and i is sqrt( -1). The numbers a and b are known as the real part and imaginary part of the complex number, respectively.

You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas:

a + bi + c + di = (a + c) + (b + d)i
a + bi - (c + di) = (a - c) + (b - d)i
(a + bi) * (c + di) = (ac - bd) + (bc + ad)i
(a+bi)/(c+di) = (ac+bd)/(c^2 +d^2) + (bc-ad)i/(c^2 +d^2)

You can also obtain the absolute value for a complex number using the following formula:

| a + bi | = sqrt(a^2 + b^2)

(A complex number can be interpreted as a point on a plane by identifying the (a, b) values as the coordinates of the point. The absolute value of the complex number corresponds to the distance of the point to the origin, as shown in Figure 13.10.)

Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, and abs for performing complex number operations, and override the toString method for returning a string representation for a complex number. The toString method returns (a + bi) as a string. If b is 0, it simply returns a. Your Complex class should also implement Cloneable and Comparable. Compare two complex numbers using their absolute values.

Provide three constructors Complex(a, b), Complex(a), and Complex(). Complex() creates a Complex object for number 0 and Complex(a) creates a Complex object with 0 for b. Also provide the getRealPart() and getImaginaryPart() methods for returning the real and imaginary part of the complex number, respectively.

Use the code at

https://liveexample.pearsoncmg.com/test/Exercise13_17.txt

to test your implementation.

Sample Run

Enter the first complex number: 3.5 5.5

Enter the second complex number: -3.5 1

(3.5 + 5.5i) + (-3.5 + 1.0i) = 0.0 + 6.5i

(3.5 + 5.5i) - (-3.5 + 1.0i) = 7.0 + 4.5i

(3.5 + 5.5i) * (-3.5 + 1.0i) = -17.75 -15.75i

(3.5 + 5.5i) / (-3.5 + 1.0i) = -0.5094339622641509 -1.7169811320754718i

|3.5 + 5.5i| = 6.519202405202649

false

3.5

5.5

[-3.5 + 1.0i, 4.0 + -0.5i, 3.5 + 5.5i, 3.5 + 5.5i]

The Output must be similar to the Sample Run

The Class Name MUST be Exercise13_17

If you get a logical or runtime error, please refer https://liveexample.pearsoncmg.com/faq.html.

In: Computer Science

(Palindrome number - A number is a palindrome if it reads the same from right to...

(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not

In Java Please

In: Computer Science

A prime number is a number that is only evenly divisible by itself and 1. For...

A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.


Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise. Use the function in a program that prompts the user to enter a number and then displays a message indicating whether the number is prime. The following modules should be written:


getNumber, that accepts a Ref to an integer, prompts the user to enter a number, and accepts that input


isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise


showPrime, that accepts an integer as an argument , calls isPrime, and displays a message indicating whether the number is prime


The main module, that will call getNumber and showPrime


In: Computer Science

. A simple way to encrypt a number is to replace each digit of the number...

. A simple way to encrypt a number is to replace each digit of the number with another digit. Write a C program that asks the user to enter a positive integer and replace each digit by adding 6 to the digit and calculate the remainder by 10. For example, if a digit is 6, then the digit is replaced by (6+6)%10, which is 2. After all the digits are replaced, the program then swap the first digit with the last digit. The main function reads in input and displays output.

A sample input/output:

Enter the number of digits of the input number: 3

Enter the number: 728

Output: 483

2) The user will enter the total number of digits before entering the number.

3) You can use format specifier "%1d" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num.

4) As part of the solution, write and call the function encrypt() with the following prototype.

The function assumes that the digits are stored in the array a and computes the encrypted digits and store them in the array b. c represents the size of the arrays. void encrypt(int *a, int *b, int n); The function should use pointer arithmetic – not subscripting – to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.

5) As part of the solution, write and call the function swap() with the following prototype. void swap(int *p, int *q);

When passed the addresses of two variables, the swap() function should exchange the values of the variables: swap(&i, &j); /* exchange values of i and j */

In: Computer Science

This C++ program is to validate the ISBN number and output "Valid" if the number is...

This C++ program is to validate the ISBN number and output "Valid" if the number is valid, and "Invalid"
otherwise.


The ISBN number for a book is a 10-digit number made up of 4 sections separated by '-'. In the ISBN
number 1-214-02031-3:
1 represents a country (must be 1 digit)
214 represents the publisher (must be 3 digits)
02031 represents the book number (must be 5 digits)
3 is the checksum (must be 1 digit or the letter 'x').
The checksum is a digit to see if the ISBN number is a valid number. If the checksum is 'x', then that
represents the digit 10.
A weight is associated with each digit:
10 with the first digit (1 in the example)
9 with the second digit (2 in the example)
8 with the 3rd digit (1 in the example)
7 with the 4th digit (4 in the example)
6 with the 5th digit (0 in the example)
5 with the 6th digit (2 in the example)
4 with the 7th digit (0 in the example)
3 with the 8th digit (3 in the example)
2 with the 9th digit (1 in the example)
1 with the 10th digit (3 in the example)
To check to see if an ISBN number is valid, you multiply the digit by its weight and add the resulting
products. If the sum is evenly divisible by 11, then it is a valid ISBN number.


In the example: 1-214-02031-3
1*10+2*9+1*8+4*7+0*6+2*5+0*4+3*3+1*2+3*1 = 88
Since 88 is evenly divisible by 11, the above number is a valid ISBN number.

The main function will create an array of pointers of type char to store all the ISBN numbers I'll give
you in a separate text file for the convenience of copying. The main should iterate over that array and for
each ISBN number call the function checkDigits which will return true is there are digits and a correct
number of digits in each section, and if each section is separated by a '-'. Otherwise, it will return false.
If checkDigits returns true, the main will call checkSum, which will return true if the sum of the
products of the weights and digits is divisible by 11. Otherwise, it returns false. The main program will
output "valid" or "not valid" for each ISBN number.

In this program, do not use subscripted variables. Use the pointers to the characters. The declaration for
the checkSum would be:
bool checkSum(char *);

Note that functions take a single pointer as a parameter, not a char ** (i.e. array of pointers).
Note, that *(ptrISBN + 3) is the same as ptrISBN[3]
To check to see if there is an '-' in the i-th position you can use the statement:
if(*(ptrISBN + i) == '-')
Your program should not be like that:
if(ISBN[0] == '-' || ISBN[1] == '-' || ISBN[2] == '-' ….. || ISBN[10] == '-')
To check for each element in the array.
I want you to use the loop and iterate over the arrays using the loop.

However, if you need to check just a couple (maybe three, max), that is OK.

Should use:

2 functions with using const arguments
Using enum valid, invalid in place of bool

Do not use:
Declaring array according to standards
off-by-one errors
Using global variables

Run the program with the data from the data file “test_data.txt”
Note, I want you to hard code the array of pointers. I don't want you to read the data from the file on
the fly.

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

Expected output would be similar to the following:

Input ISBN numbers:

(input number from given .txt file)

Array filled! //use a loop to get input from the user

Checking ISBN numbers...

//(for ISBN #'s return False/Invalid)

Invalid ISBN #

//(for ISBN #'s return True/Valid)

Checking sum of Valid ISBN numbers

Valid/Invalid ISBN # : (return sum of ISBN number)

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

Given text file: Note, I want you to hard code the array of pointers. I don't want you to read the data from the file on
the fly. IF applicable/possible try to make another function to show the difference.

1-214-02031-3
0-070-21604-5
2-14-241242-4
2-120-12311-x
0-534-95207-x
2-034-00312-2
1-013-10201-2
2-142-1223
3-001-0000a-4
done

In: Computer Science

A prime number is a number that is only evenly divisible by itself and 1. For...

A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that displays all of the prime numbers from 1 to 100. The program should have a loop that calls the is_prime function.

In: Computer Science

In a factory, it is known that the probability of fixing a particular production error is...

In a factory, it is known that the probability of fixing a particular production error is 1/3. For production of 10 units with this error;
a-)Write the probability function.
b-)What is the probability that all three can be corrected?
c-)What is the probability that one of the most errors can be fixed?
d-)What is the probability that two or more errors can be corrected?
e-)What is the probability that more than three, 5 or fewer errors can be corrected?

In: Statistics and Probability

Given a normal population whose mean is 575 and whose standard deviation is 26, find each...

Given a normal population whose mean is 575 and whose standard deviation is 26, find each of the following (use Excel to obtain more accuracy):

A. The probability that a random sample of 4 has a mean between 578 and 587.

Probability =

B. The probability that a random sample of 15 has a mean between 578 and 587.

Probability =

C. The probability that a random sample of 22 has a mean between 578 and 587.

Probability =

In: Statistics and Probability

Suppose x has a normal distribution with a mean of 78 and a variance of 484.00....

Suppose x has a normal distribution with a mean of 78 and a variance of 484.00. If a sample of 19 were randomly drawn from the population, find the probability of      for each of the following situations.

a) less than 79:
probability =  

b) greater than 85:
probability =  

c) in between 68 and 84:
probability =  

d) in between 77 and 91:
probability =  

Note: Do NOT input probability responses as percentages; e.g., do NOT input 0.9194 as 91.94.

In: Statistics and Probability

Given a normal population whose mean is 680 and whose standard deviation is 48, find each...

Given a normal population whose mean is 680 and whose standard deviation is 48, find each of the following (use Excel to obtain more accuracy):

A. The probability that a random sample of 3 has a mean between 687 and 699.

Probability =

B. The probability that a random sample of 18 has a mean between 687 and 699.

Probability =

C. The probability that a random sample of 27 has a mean between 687 and 699.

Probability =

In: Statistics and Probability