Calculator Class Instructions
Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation.
The class must check for a correct operator (+,*,-,/), and a number (integer) for the second and third argument entered. The calculator cannot divide by zero that will be an error.
Separate error messages will be displayed for all errors. Also, separate success messages will be displayed with each successful answer. This script will run using a browser. The output of the script will display after the web address is entered into the browser navigation window. There will be a separate file that will require the class. That file will be used to instantiate the class and call the appropriate method, while the class will do the heavy lifting.
You will have two files
One will be the file that is your class.
The other will be a file that requires your class and call the
appropriate method. This is the file you will provide the web
address for.
For example:
If you have a file with a class named $Calculator. You will have another class that uses the calculator class and displays the information. That file will have the code shown below.
NOTE: You are to use the code shown below as your test code.
NOTE: For this assignment you can write the following code within a PHP block within the HTML body element. You do not need to write the comments I did that to show you what needs to be outputted depending on what is sent as arguments.
<?php
require_once "Calculator.php";
$Calculator = new Calculator();
echo $Calculator->calc("/", 10, 0); //will output Cannot divide
by zero
echo $Calculator->calc("*", 10, 2); //will output The product of
the numbers is 20
echo $Calculator->calc("/", 10, 2); //will output The division
of the numbers is 5
echo $Calculator->calc("-", 10, 2); //will output The difference
of the numbers is 8 echo $Calculator->calc("+", 10, 2); //will
output The sum of the numbers is 12
echo $Calculator->calc("*", 10); //will output You must enter a
string and two numbers echo $Calculator->calc(10); //will output
You must enter a string and two numbers
?>
The browser will output (based upon the above methods):
Cannot divide by zero
The product of the numbers is 20
The division of the numbers is 5
The difference of the numbers is 8
The sum of the numbers is 12
You must enter a string and two numbers You must enter a string and
two numbers
in PHP/HTML
In: Computer Science
How would you call a username in a different function when coding in C?
I have a function that logs a user in, and I would like to say if (username == 'abc'){do function} but everytime I use the 'username' variable in a different function, it says it is an undeclared identifier.
In: Computer Science
User Python to solve; show all code:
Write a program that will prompt the user for the player data described above. The user does not know how many players are on the team so allow the user to enter the word end when he/she has finished entering data.
Validate that the player is not entered more than once.
After entering the data, compute the following:
In: Computer Science
Java Special Methods:
A) Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.
B) Write methods to implement the multiply, subtract and divide operations for integers. The results of all of these are integers. Use only the add operator.
In: Computer Science
Given the strings s1 and s2 that are of the same length, create a new string s3 consisting of the last character of s1 followed by the last character of s2, followed by the second to last character of s1, followed by the second to last character of s2, and so on
In: Computer Science
2. Convert the following decimal fractions to binary with a
maximum of six places to the right of the binary point: [12]
a. 25.84375 b. 57.55 c. 80.90625 d. 84.874023
In: Computer Science
In Java
In mathematics, factorial of a non-negative integer n, denoted by n! , is the product of all positive integers less than or equal to n. For example,
5! = 5 * 4 * 3 * 2* 1 = 120
3! = 3 * 2 * 1 = 6
2! = 2 * 1 = 2
The value of 0! is 1.
Write a program that asks user to enter an integer > 0; if a valid value is entered, it should calculate and display factorial of the number entered. If the user enters an integer <=0, display a message "Invalid entry - valid entry is an integer > 0" and have them re-enter the information.
In: Computer Science
Use Python to solve, show all code
Write a program that sums a sequence of integers from a starting integer to and ending integer. The sequence is generated by skipping a value (e.g. 1,3,5,… or 2,6,10,14…). Prompt the user for a) a starting value greater than 0. Validate the value is greater than 0.
b) the ending value.
c) the value to skip
Print out the sum of the numbers for the sequence. If the starting value is 2, the ending value is 10 and the value to skip is 2, the sequence would be 2,4,6,8,10
Sample Interaction:
Enter the starting value: -1
Error – invalid number
Enter the starting value: 2
Enter the ending value: 10
Enter the value to skip: 2
The sum of the integers from 2 to 10 skipping 2 is 30
In: Computer Science
For this Discussion, you will analyze mobile security threats and evaluate countermeasures.
Briefly describe your mobile device and another device currently on the market that uses a different OS. Explain the security vulnerabilities associated with each device. Explain the security solutions that would address the vulnerabilities. Finally, state which OS has more robust security and explain your reasoning.
In: Computer Science
Create a webpage with Margins, Padding, Alignment, and Floating:
In: Computer Science
Using the module discussion forum, work with your fellow students to identify any other database benefits you can think of, as say compared to a spreadsheet or basic file storage.
In: Computer Science
MACs
Question 3:
3a.) Why should a MAC be configurable?
3b.) What are the effects of RF radio realities on the MAC
layer?
In: Computer Science
In Java
A palindrome is a word or sequence of characters which reads the same backward and forward, such as madam, dad, racecar, 5885. In java Write a program that asks user to enter a word and prints if the word is a palindrome or not.
In: Computer Science
in Python,
Define the class called Line which represents a line with equation ?=??+? with input slope ? and intercept ? to initialize the instances. It should include:
attributes named ? and ? to represent slope and intercept.
method named intersect to return the list, containing coordinates
of the intersection point of two lines.
support for + operator to compute the addition of two equations.
The sum of two Line objects ?=?1?+?1 and ?=?2?+?2 is defined as the
line ?=(?1+?2)?+?1+?2 .
printable representation for the equation of line, which we have
already defined in __repr__ speical method below.
In: Computer Science
Wireless Sensor Networks/Internet of Things
What should be the major components of an energy consumption model for a sensor node?
In: Computer Science