Write a JAVA program that allow a user to enter 2 number, starting point and end point. For example a user me enter 1 and
100. Your program will
Add numbers from 1 to 100, add all the even number, and add all the odd numbers
Output:
The sum of number 1 to 100 is:
The sum of even number 1 to 100 is:
The sum of odd number 1 to 100 is:
In: Computer Science
Hi. Are you familiar with deunions? The objective of the task is to undo the last union operation in a weighted quick-union find implementation, of which I have partly written here (see below). I push the unions on a stack. The code is not finished though, and far from perfect. Can you point out my mistakes and figure out how to create the deunion-operation correctly?
Best regards,
Eirik
public class UFwithDeunion { private int[] id; //parent link (site indexed) private int[] sz; // size of component for roots (site indexed) private int count; //number of components Stack stack = new Stack(); //maa bruke weighted-quick union for at det skal kjoere i ¨log N kjoeretid public UFwithDeunion(int n) { count = n; id = new int[n]; for (int i = 0; i < n; i++) id[i] = i; } //set the total number of elements public static int setSize(int n){ sz = new int[n]; for (int i = 0; i < n; i++) sz[i] = 1; } //return an identifier for the set containing a public static int find(int a){ //follow links to find a root while (a != id[a]) a = id[a]; //pop return a; //merge the set containing a with the set containing b public static void union(int a, int b){ int i = find(a); int j = find(b); if (i == j) return; //make smaller root point to larger one if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; stack.push(id[i]); } else { id[j] = i; sz[i] += sz[j]; stack.push(id[j]); } } // undo the last union operation public static void deUnion(){ stack.pop(); //sz--; } //Return the number of elements in the set containing a public static int elementsInSet(int a){ int sum = 0; for (int i : id) { if (a == id[i]) sum++; } return sum; }
In: Computer Science
MATLAB Question
Write a script to plot the function 'x times sine-squared of x' over a user-specified interval. It should prompt the user to enter the starting and stopping values of x, perform the calculation, and plot the result. Test the script using start/stop values 28 and 42.
In: Computer Science
52) Metro Food Services Company delivers fresh sandwiches each morning to vending machines throughout the city. The company makes three kinds of sandwiches—ham and cheese, bologna, and chicken salad. A ham and cheese sandwich requires a worker 0.45 minutes to assemble, a bologna sandwich requires 0.41 minutes, and a chicken salad sandwich requires 0.50 minutes to make. The company has 960 available minutes each night for sandwich assembly. Vending machine capacity is available for 2,000 sandwiches each day. The profit for a ham and cheese sandwich is $0.35, the profit for a bologna sandwich is $0.42, and the profit for a chicken salad sandwich is $0.37. The company knows from past sales records that its customers buy as many ham and cheese sandwiches as the other two sandwiches combined, if not more so, but custom- ers need a variety of sandwiches available, so Metro stocks at least 200 of each. Metro manage- ment wants to know how many of each sandwich it should stock to maximize profit. Formulate a linear programming model for this problem. (USE EXCEL SOLVER) (SHOW WORK)
53. Solve the linear programming model formulated in Problem 52 for Metro Food Services Company by using the computer. (USE EXCEL SOLVER) (SHOW WORK)
a. If Metro Food Services could hire another worker and increase its available assembly time by 480 minutes or increase its vending machine capacity by 100 sandwiches, which should it do? Why? How much additional profit would your decision result in?
b. What would the effect be on the optimal solution if the requirement that at least 200 sand- wiches of each kind be stocked was eliminated? Compare the profit between the optimal solution and this solution. Which solution would you recommend?
c. What would the effect be on the optimal solution if the profit for a ham and cheese sandwich was increased to $0.40? to $0.45?
In: Computer Science
In your current business environment, or one you were in at one time, which of the four cloud computing service models do you think might be good for that company to consider? How would a change to one of the cloud computing service models change the way that company does business?
In: Computer Science
4. Define briefly the different activities of the Software lifecycle.
In: Computer Science
Project 2c (Javascript/HTML/CSS)– Mouse Chase: Create a page with a nice, shiny, pretty button on it. The button should say ‘Click to receive $10!’ However, any time the user’s mouse cursor gets over the button, the button should move to a random location on the page, making the button essentially impossible to click! However, if they do somehow manage to click the button, redirect the user to an image of a 10 trillion Zimbabwe Dollar. Finally, the background color of the page should change every 3 seconds to a random color.
In: Computer Science
Which of these is/are true about stored procedures?
A user defined stored procedure can be created in a user-defined database or a resource database
Repeatable & abstractable logic can be included in user-defined stored procedures
To call output variables in a stored procedure with output parameters, you need to declare a variables outside the procedure while invocation
Temporary stored procedures are nothing but system stored procedures provided by SQL Server
In: Computer Science
Hello,
In C#, we are creating a simple calculator that takes two operands and one operator and calculates a result. We need to include a private method to calculate the result as well as try-catch statements for exceptions. My code that i have so far is below, it executes and calculates, but there is an issue with the way i have done the method. Any help or info about my method errors would be great, Thank you!
**********************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimpleCalculator
{
/***********************************
* Displays simple calculations from the
* data the user enters.
* *********************************/
public partial class simpleCalculator : Form
{
public simpleCalculator()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs
e)
{
/*******************************
* This method calcultes the result from the
* user entry in the operands and operaator boxes.
* *****************************/
try
{
//converts the data frm the user entry frm txt to decimal and
string.
decimal operand1 = Convert.ToDecimal(txtOperand1.Text);
decimal operand2 = Convert.ToDecimal(txtOperand2.Text);
string operator1 = Convert.ToString(txtOperator1.Text);
//method to perform the calculations.
decimal result = Calculate(operand1, operand2, operator1);
}
//the catch exceptions, will try the above code and any exceptions
will be caught by the ones below
//and throw uo a message box with an error message.
catch (FormatException)
{
MessageBox.Show("A format exception has occurred. Please check all
entries." + "\n\n",
"Entry Error");
}
catch (OverflowException)
{
MessageBox.Show("An overflow exception has occurred. Please enter
smaller values",
"Entry Error");
}
catch (DivideByZeroException)
{
MessageBox.Show("Divide-by-zero error. Please enter a non-zero
value",
"Entry Error");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" +
ex.GetType().ToString() + "\n" +
ex.StackTrace, "Exception");
}
//where the calculate method is called.
private decimal Calculate(decimal operand1, decimal operand2,
string operator1)
{
//initilized the result to decimal and zero.
decimal result = 0m;
//code to check the operator1 entry and compare it to either /,
*, - or +
//then do the corresponding calculation.
if (operator1 == "/")
{
result = operand1 / operand2;
}
else if (operator1 == "*")
{
result = operand1 * operand2;
}
else if (operator1 == "+")
{
result = operand1 + operand2;
}
else if (operator1 == "-")
{
result = operand1 - operand2;
}
//code to display the reslt in the result box
txtResult.Text = result.ToString();
}
}
//code to exit form
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
//code to clear the result box after calculation has been performed
and the operand1 box is cleared.
private void ClearResult(object sender, EventArgs e) =>
txtResult.Text = "";
}
}
In: Computer Science
You have a rental company with properties in 3 different cities Columbus Ohio, Florida and Colorado. You are currently using Linux as your operating system to run your business. Your goal is to switch over to using a Windows operating system. Which operating system would you use and what would be the benefits of using such system?
In: Computer Science
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
In: Computer Science
Write a C function, for example void sumOfPrime(int n), that takes a positive int n as a parameter, put all prime numbers less than n into an array, and print out the array and the sum of the numbers in that array. You can use the isPrime function above to save time.
In: Computer Science
in Java
Write a function that inputs a 4 digit year and outputs the
ROMAN numeral year
M is 1,000
C is 100
L is 50
X is 10
I is 1
Test with 2016 and 1989
In: Computer Science
Write a program that allows 2 players to play the marble game using combinations of loop and conditional statements. In the marble game, you ask the user to enter how many marbles to start with. Then, the game begins. The first player must take 1, 2 or 3 marbles. Then the second player goes and must take 1, 2 or 3 marbles. The winner is the player who takes the last marble. Allow two users to play this game and print out the winner (player #1 or player#2). Assume that both players enter valid inputs (1, 2 or 3, and they never try to take more marbles than there are in the pile.)
In: Computer Science
java
In one program, write 3 separate functions, and use them.
1) Write the function body for each:
int squareInteger s( int x)
double squareDouble( double d)
float squareFloat ( float f)
They basically do the same thing, square a number, but use
different argument datatypes.
2) Test Each function with: Using int 4, double 4.9, float
9.4
What happened when you use the correct numerical data type as input
?
What happened when you use the incorrect numerical data types as
inputs ?
What is the lesson this teaches you about functions/methods ?
In: Computer Science