Write a program to multiply a polynomial with a given number.
Code needed in java.
In: Computer Science
LAUNGEG: C#
Objective:
For this assignment you will be creating two classes, an interface, and a driver program:
Class Calculator will implement the interface CalcOps
o As such it will implement hexToDec() - a method to convert
from
Hexadecimal to Decimal.
Class HexCalc will inherit from Calculator.
Interface CalcOps will have abstract methods for add( ), subtract( ),
multiply( ) and divide( ).
Both classes will implement the CalcOps interface.
o Class Calculator’s add, subtract, multiply and divide will take in 2 integers and return an integer. If you prefer it can take in 2 strings, and return a string.
o Class HexCalc’s add, subtract, multiply and divide will take in 2 strings (hexadecimal numbers) and return a string (hexadecimal number).
This Calculator class will work with whole numbers (int) and hexadecimal (String) values. The hexToDec ( ) method is a helper method included in interface CalcOps, that requires the Calculator class to implement the method which converts hexadecimal numbers to decimal. (Hint: Use language specific utility methods to convert hexadecimal to decimal.)
Submission Guidelines:
Program code – 1 interface program, 2 Classes and a driver program UML diagram - PDF format.
Assignment Requirements:
Create a parent class calculator that implements the arithmetic operations. You may use input values of integers or Strings.
Implement method public int hexToDec (String hexValue) which converts hexadecimal numbers to decimal numbers in the parent calculator class.
Create a class hexCalc which is a child class of the calculator class
o This class performs basic arithmetic operations such as addition,
subtraction, multiplication and division on hexadecimal numbers by
reusing the methods in parent class.
o To do hexadecimal arithmetic, convert the hexadecimal values
to
integers, perform the arithmetic operation using the parent class methods
and then convert the result back to hexadecimal string.
o For conversion between hexadecimal and integer values use the
following language specific methods.
C#
Convert.ToString(int,16) Convert integer to hexadecimal
Convert.ToInt32(hex, 16) Convert hexadecmial to integer
Run the driver program for all calculator operations using decimal and hexadecimal values.
The biggest challenge you will run into in this assignment will be calling methods with the correct data types as parameters to each method. If you are
getting errors, be sure to double check that what you passed to the method as arguments matches the methods parameter types. Where possible, use your language’s methods to convert to the appropriate type before calling.
• Be sure to convert from integers to strings and vice versa before and after converting from decimal to hex.
Skeleton:
//Design an interface public interface CalcOps
{
// ... includes basic arithmetic operations
public int hexToDec (String hexToDecimal) ;
}
//Parent class
public class Calculator implements CalcOps
{
}
//Hexadecimal arithmetic calculator that extends calculator
public class HexCalc extends Calculator{
@implement add, subtract, multiply, divide methods
//Reuse parent class methods.
}
public class TestCalculator {
//Provide choice between executing hexadecimal and decimal arithmetic //operations.
// Menu of choices
} // Driver class.
OUTPUT:
Would you like to do calculations with decimal or hexadecimal numbers (1 for Decimal, 2 for Hexadecimal
1
---MENU---
0 - Exit
1 - Addition
2 - Subtraction
3 - Multiplication
4 - Division
Please Choose an Option: 1 Please enter the first number
45
Please enter the second number
67
112 ---MENU---
0 - Exit
1 - Addition
2 - Subtraction
3 - Multiplication
4 - Division
Please Choose an Option: 2 Please enter the first number
34
Please enter the second number
1
33
---MENU---
0 - Exit
1 - Addition
2 - Subtraction
3 - Multiplication
4 - Division
Please Choose an Option: 3 Please enter the first number
23
Please enter the second number
12
276
---MENU---
0 - Exit
1 - Addition
2 - Subtraction
3 - Multiplication
4 - Division
Please Choose an Option: 4 Please enter the first number
10
Please enter the second number
3
3
---MENU---
0 - Exit
1 - Addition
2 - Subtraction
3 - Multiplication 4 - Division
Please Choose an Option: 0
You chose to Exit> THANK YOU !!! HAVE A GREAT DAY!!
Thank you!
In: Computer Science
In order to borrow an item from the library, a member first enters the membership card into a card reader of the library. The system retrieves the membership details and contacts the university system UniSys to find if the member is an active staff or student. If not, the system does not allow the member to borrow any item from the library and terminates the function. Otherwise, the system asks the member to place the item in the scanner. Once the member does this, the system gets the item details and its type. It also checks if the item is available for loan. The system also finds out the total items already borrowed but not returned. If the item is available for loan, and the total item borrowed but not returned is less than 5, it makes a loan for the member. The item is included in the membership account with the borrowing date and due date for return. The system then increments the total borrowed items by 1, and it makes the item unavailable for other members. The system also decrements the total items reserved of the member if the item was reserved by the member. The member has also choice to request for extended loan time for one more week. If the item was not reserved, one more week is added with the original return date. Finally, it creates a receipt of the loan, and releases the security code of the item. The receipt includes information such as membership number, item call number, loan date, and return date..... in use case diagram
In: Computer Science
In a few words, explain how a preemptive scheduling policy differs from a non-preemptive scheduling policy.
In: Computer Science
Using Perl language: Write a program that reads a string from the standard input, and uses a Perl regular expression to test whether the string looks like a valid credit card number. The card numbers of four major companies follow the following formats:
Visa
13 or 16 digits, starting with 4.
MasterCard
16 digits, starting with 51 through 55.
Discover
16 digits, starting with 6011 or 65.
American Express
15 digits, starting with 34 or 37.
You should test your script with following numbers:
(1)4941 5968 0539 2447
(2) 371642190784801
(3) 5168441223630339
(4) 6011988461284820
Please include screenshots for your output.
In: Computer Science
Write a program to multiply two polynomials.
Code needed in Java.
In: Computer Science
Give reasons why one might conjecture that the following language is not deterministic.
L = {anbmck: n = m or m = k}.
In: Computer Science
The following program supposes to calculate the area of a rectangle and square. Then, produce the following output.
Area of Rectangle:
50
Unfortunately, the program has compile-time and run-time errors that prevent the program from running and producing the correct result. Using table 3.1 below, allocate the error(s) on each program line.
1 public class RectangleArea {
2 Public static void main() {
3 int width == 10;
4 int height = 5;
5 int recArea = width + height;
6 System.Out.print(Area of
Rectangle:);
7 System.out.println(“recArea”)
8
9
Note:
Some of the answers are given to you as an example.
Table 3.1: compile-time / run-time error
Line No |
compile-time / run-time error |
1 |
No error |
2 |
Error.
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
In: Computer Science
Consider the following java class:
class Student {
private int student_Number;
private String student_Name;
public Student(int stNo,String name) {
student_Number=stNo;
student_Name=name;
}
public String getName() {
return student_Name;
}
public int getNumber() {
return student_Number;
}
public void setName(String st_name) {
student_Name = st_name;
}
}
Write a Tester class named StudentTester which contains the following instruction:
Note:
Include the screenshot of the program output as a part of your answer. Otherwise, you will be marked zero for this question.
In: Computer Science
In: Computer Science
What java program would you write to solve the following problems and why does it work? Please also comment on other students’ code at least three times. 1) Implement MyArrayList and MyLinkedList using MyList interface and MyAbstractList as defined in Java Collection Framework. 2) For the following problem use your own created MyArrayList or MyLinkedList if needed. Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters. Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right. For the last line of text, it should be left justified and no extra space is inserted between words.
In: Computer Science
Write a complete program called EvenNums that uses a
method to create arrays of even numbers starting 1 of the given length:
public static int[] getEvenNums(int length) {}
EX:
int[] nums = getEvenNumbers(6);
System.out.println(Arrays.toString(nums));
expected output:
[2, 4, 6, 8, 10, 12]
In: Computer Science
Matlab
Theoretical Calculations:
t = (-.00025: .00025: 100000);
A1 = 29;
A2 = 1.2*A1;
t1 = (37.2/2)*.00025;
t2 = -(41.3/10)*.00025;
x1 = A1*co(2*pi*(4000)*(t-t1));
x2 = A2*co(2*pi*(4000)*(t-t2));
x3 = x1 + x2;
Remember that the phase of a sinusoid can be calculated after measuring the time location of a positive peak,3 if we know the frequency.
(a) Make measurements of the “time-location of a positive peak” and the amplitude from the plots of x1(t) and x2(t), and write those values for Ai and ti directly on the plots. Then calculate (by hand) the phases of the two signals, x1(t) and x2(t), by converting each time-shift ti to phase. Note: when doing computations, express phase angles in radians, not degrees!
(b) Measure the amplitude and time-shift of x3(t) directly from the plot and then calculate the phase φ3 by hand. In your report, show how the amplitude and time-shift were measured, and how the phase was calculated.
(c) Now use the phasor addition theorem. Carry out a phasor addition of complex amplitudes for x1(t) and x2(t) to determine the complex amplitude for x3(t). Use the complex amplitude for x3(t) to verify that your previous calculations of A3 and φ3 were correct.
In: Computer Science
In: Computer Science
Use c++language Use the pseudocode description below to write a program that uses an if, else if, else decision structure for a program that will determine if someone lives in Boston. 1. display message that describes what the program will do. 2. ask the user to input an answer to the question: Do you live in Boston?. 3. if they entered 'y', display a message confirming that they live in Boston. 4. if they entered 'n' , display a message confirming that they don't live in Boston. 5. if they entered an invalid entry, display a message telling them.
In: Computer Science