The program Nadha Skolar wrote is supposed to read an integer value supplied by the user that should be between 1-30. Using the value supplied (let's call it n), three different summation formulas should be calculated using three different methods. Nadha Skolar was supposed to write a program to read the user's input, ensure that it is a value between 1-30 and then call the appropriate methods to calculate the summations and print the results:
Sample Runs:
Run #1 (bad value for n):
Enter a number between 1-30 for the value of n: 0 <--- user enters the number for n Program cannot continue. n must be a value 1-30. <--- use a println
Run #2 (bad value for n):
Enter a number between 1-30 for the value of n: 31 <--- user enters the number for n Program cannot continue. n must be a value 1-30. <--- use a println
Run #3:
Enter a number between 1-30 for the value of n: 3 <--- user enters the value for n The summation of the first n numbers is: 6 The summation of the n odd numbers is: 9 The summation of n numbers squared is: 14 <--- use a println
Tips:
import java.util.*;
/* Name: NadhaSkolar Solution
public class NadhaStrikesAgain { //my best work yet! I have just
learned about methods!
public static void main(String[] args) {
//get the value for n
Scanner scnr = new Scanner(System.in);
int n = getN();
//ensure n is usable
if ((n <= 0) && (n > 30)){
System.out.println("Program cannot continue. n must be a value
1-30.");
}
int sum = summationN(n);
int sumodd = sumofOddN(sum);
int sumSquares = sumOfSquaresN(n);
displayResults(sumodd, sum, sumSquares); //print them out
}
}
// ************************************************
// DESCRIPTION - getN() - prompts for n and returns value to
main
// ************************************************
public static void getN(Scanner scnr) {
//prompt for a number,
System.out.print("Enter a number between 1-30 for the value of n:
");
int n = scnr.nextInt();
return n;
}
// ************************************************
// DESCRIPTION - addOdd() computes summation of first "num" odd
numbers using the formula n^2
// ************************************************
public static double sumofOddN(int num) {
return(num^2);
}
// ************************************************
// DESCRIPTION - summation() - computes and returns the summation
of i from to N
// ************************************************
public static int summationN(int num) {
return(num * num + 1 / 2);
}
// ************************************************
// DESCRIPTION - sumOfSquares() - computes and returns the sum of
squares of first "num" numbers
// ************************************************
public static int sumOfSquaresN(int n) {
return((num * (num + 1) * (2 * num + 1) / 6));
}
// ************************************************
// DESCRIPTION - displayResults() - displays the various
summations
// ************************************************
public static void displayResults(int sum, int oddSum, int
sumSquares) {
System.out.println();
System.out.println("The summation of the first n numbers is: " +
sum);
System.out.println("The summation of the n odd numbers is: " +
oddSum);
System.out.println("The summation of n numbers squared is: " +
sumSquares);
}
}
}
In: Computer Science
Instructions
Write a Circle class (Circle.java) that has the following fields:
- radius (double)
- PI (final double initialized to 3.1415) // no need to have setters or getters for this
Include the following methods:
- Constructor (accepts radius of circle as an argument)
- Constructor (no argument that sets radius to 0.0)
- setRadius (set method for radius field)
- getRadius (get method for radius field)
- calcArea (calculates and returns area of circle: area = PI * radius * radius)
- calcDiameter (calculates and returns diameter of circle: diameter = radius * 2)
- calcCircumference (calculates and returns circumference of circle: circumference = 2* PI * radius)
Write a test program (TestCircle.java) that will ask user for the radius, creates the circle object, and then displays the area, diameter, and circumference.
Make sure to create 2 circle object instances - one with the radius as an argument, one without but sets the radius with the setRadius() method.
Thank you so much for your help!!
In: Computer Science
Create 2 more batch files called devTracker.bat and
showTracker.bat as follows:
devTracker.bat
a. This batch logs an entry into a log file called
C:\myTemp\devTracker.log
b. The entry in the log file should indicate the date and time of
the VS launch as well as a message indicating
that you started Visual Studio. Please log all of this information
on 1 line in the devTracker.log file
c. After making this log entry, devTracker.bat should run
myStart.bat for you
showTracker.bat
d. Create another batch file called showTracker.bat that displays
the contents of the devTracker.log
file in the command prompt window.
In: Computer Science
| Java Prorgramming |
|
Description In this assignment, you'll be URL encoding of a line of text. Web browsers URL encode certain values when sending information in requests to web servers (URL stands for Uniform Resource Locator). Your program needs to perform the following steps:
To convert a String to URL encoded format, each character is examined in turn:
Use a for loop which increments it's index variable from 0 up to the last character position in the input string. Each iteration of the loop retrieves the character at the 'index' position of the input string (call the String class charAt() method on the input string). Use if statements to test the value of the character to see if it needs to be encoded. If encoding is not required, just concatenate it to the output encoded String. If encoding is required, concatenate the encoded value to the output encoded String. For example, if the input character is a blank, you want to concatenate a '+' character to the output encoded String (as described above). Note: one technique to determine if a character is one that remains the same is to first create an initialized String containing all of the letters (both upper and lower case), digits, and other special characters that remain the same as described above. Then, call the String indexOf method on that String, passing the character to be tested. If -1 is returned from indexOf, the character was not one of those that remains the same when URL encoding. For those characters that need to be converted into hex format (%xy above), you can call the pre-defined static Integer.toHexString method, passing the character as an argument. It returns the hex value of the character as a String, which you can concatenate to the encoded output String with the accompanying '%' symbol: String hexValue =
Integer.toHexString(srcChar); Values that are URL encoded in this manner can be URL decoded by reversing the process. This is typically done by a web server upon receiving a request from a browser. Sample Output Enter a line of text to be URL encoded Test Data Use all the following test data to test your program, plus an example of your own: This should have hex 2f for / Getting started Before you start writing Java code, it's usually a good idea to 'outline' the logic you're trying to implement first. Once you've determined the logic needed, then start writing Java code. Implement it incrementally, getting something compiled and working as soon as possible, then add new code to already working code. If something breaks, you'll know to look at the code you just added as the likely culprit. To help you get started with this homework, here's an outline of the logic you'll need (sometime referred to as 'pseudo-code'): Prompt for the line of input. if (the character is a blank) Print the encoded output string. Once you understand this logic, start writing your Java code. An example of the steps you could take are as follows:
With this much done, if you read in a line containing "hello", you'd get output something like this from the temporary output statement within the loop: char 0 is h Once you've got this compiled and working, starting adding the if/else-if/else logic inside the loop to build the encoded output string. I have this so far.What am I doing wrong here,please let me know. The code has to fit this requirement. For those characters that need to be converted into hex format (%xy above), you can call the pre-defined static Integer.toHexString method, passing the character as an argument. It returns the hex value of the character as a String, which you can concatenate to the encoded output String with the accompanying '%' symbol: String hexValue =
Integer.toHexString(srcChar); Values that are URL encoded in this manner can be URL decoded by reversing the process. This is typically done by a web server upon receiving a request from a browser. I don't how to fit the last requirement here is my code so far import java.util.Scanner; public class URLEncoding { public static final String
Notencodedchars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~*'()";
} System.out.println("Length in chars is :" + encodedString.toString().length()); } }
|
In: Computer Science
As it relates to C#:
Though the function of switch case and else if ladder is same, there are a number of difference between switch case and else if ladder, Explain the differences in two areas such (memory consumption, speed of processing, variable requirement) etc.
In: Computer Science
Please code in c# (C-Sharp)
Write a program that will ask the user for their name. If the user does not input anything, display a
warning before continuing. The program will then ask the user whether they want to have an addition,
subtraction, multiplication, or division problem. Once the user indicates their choice, the program will
display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice.
Example: user selects addition, the equation presented is:
(random number from 1 to 9) + (random number from 1 to 9)
The user will then input an answer as a whole number. If the answer they entered is not a whole
number, tell the user their input is invalid and end the program. If the input is valid, check to see if it is
the correct answer. If correct, congratulate the user by name. If incorrect, output the correct answer.
Tasks
1) The program needs to contain the following
a.
A comment header containing your name and a brief description of the program
b. At least 5 comments besides the comment header explaining what your code does
c.
A string variable that captures the user’s name
d. A way to validate user input to determine if they entered an empty string
i. Warn the user if they enter an empty string
ii. Continue the program after warning the user
e. A prompt for what type of quiz the user wants
f.
Display of a quiz matching the type the user requested
g.
A prompt for an answer in the form of a whole number
i. A message if the user enters an invalid number
1. Do not check the user’s answer if their input is invalid
ii. If input is valid:
1. Check the answer
2. If the answer is correct, congratulate the user by name
3. If incorrect, output the correct answer
h. “Press enter to continue” and Console.ReadLine(); at the end of your code
i. Note: if you write a try-catch statement, these lines will be after your last catch
2) Upload a completed .cs file onto the Assignment 4 submission folder and a word document
containing the following six (6) screenshots:
a.
The warning displayed when the user enters a blank value for the name
b. One test run for each equation with valid input
i. Answer 2 quizzes correctly
ii. Answer 2 quizzes incorrectly
c.
One test run with invalid input
In: Computer Science
Write C functions to do each of the following. Make sure your function has exactly the same name, parameters, and return type as specified here. Please place all of the functions in a single .c file and write a main() to test them.
int process(const char *input_filename, const char *output_filename) — reads the file named input_filename and processes it, putting results in output_filename. The input file consists of lines of the form "number operation number," for example:
15 - 4 3.38 / 2.288 2 ^ -5 35.2 + 38
The possible operations are +, -, *, /, and ^ (power). Your function should calculate the value of each line's expression and save it (one to a line) to the output file. For example, the input file shown above would result in an output file of
11.000000 1.477273 0.031250 73.200000
The return value of the function should be the number of calculations that it did (4 for this example file).
(Hints: fscanf() returns the constant value EOF when the end of file is reached. The pow(x, y) function defined in <math.h> calculates xy; you will need to add -lm to the command line when compiling your code to link the math library.)
In: Computer Science
In C++
You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an arrayy of objects and practice passing objects to and return objects from functions. String functions practice has also been included. You have been given a template in Zylabs to help you with this work. The data file is also uploaded.
|
BankAccount |
|
-string accountName // First and Last name of Account holder -int accountId // secret social security number -int accountNumber // integer -double accountBalance // current balance amount |
|
+ BankAccount() //default constructor that sets name to “”, account number to 0 and balance to 0 +BankAccount(string accountName,int id, int accountNumber, double accountBalance) // regular constructor +getAccountBalance(): double // returns the balance +getAccountName: string // returns name +getAccountNumber: int +setAccountBalance(double amount) : void +equals(BankAccount other) : BankAccount // returns BankAccount object ** -getId():int ** +withdraw(double amount) : bool //deducts from balance and returns true if resulting balance is less than minimum balance +deposit(double amount): void //adds amount to balance. If amount is greater than rewards amount, calls // addReward method -addReward(double amount) void // adds rewards rate * amount to balance +toString(): String // return the account information as a string with three lines. “Account Name: “ name “Account Number:” number “Account Balance:” balance |
The order in the file is first name, last name, id, account number, balance. Note that account name consists of both first and last name
Create BankAccount.h.
This is given for BankAccount.cpp:
#include <string>
#include <iostream>
#include "BankAccount.h"
// BankAccount::BankAccount();
BankAccount::BankAccount(std::string accountName, int id, int
accountNumber, double accountBalance){
//
}
//getters
std::string BankAccount::getAccountName(){
//
}
int BankAccount::getAccountNumber(){
//
}
double BankAccount::getAccountBalance(){
//
}
void BankAccount::setAccountBalance(double accountBalance){
//
}
std::string fixPoint(std::string number){
//adjust the two decimal places
}
std::string BankAccount::toString(){
}
bool BankAccount::withdraw(double amount){
//
}
void BankAccount::deposit(double amount){
//
}
This is given for main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include //your header file
using namespace std;
const int SIZE = 8;
void fillArray (ifstream &input,BankAccount
accountsArray[]);
int largest(BankAccount accountsArray[]);
int smallest(BankAccount accountsArray[]);
void printArray(BankAccount accountsArray[]);
int main() {
//open file
//fill accounts array
//print array
//find largest
//find smallest
//find duplicates and print if necessary
BankAccount accountsArray[SIZE];
fillArray(input,accountsArray);
printArray(accountsArray);
cout<<"Largest Balance: "<<endl;
cout<<accountsArray[largest(accountsArray)].toString()<<endl;
cout<<"Smallest Balance :"<<endl;
cout<<accountsArray[smallest(accountsArray)].toString()<<endl;
}
}
void fillArray (ifstream &input,BankAccount
accountsArray[]){
}
int largest(BankAccount accountsArray[]){
//returns index of largest account balance
}
int smallest(BankAccount accountsArray[]){
//returns index of smallest
}
BankAccount removeDuplicate(BankAccount account1, BankAccount
account2){
return (account1.equals(account2));
}
void printArray(BankAccount accountsArray[]){
cout<<" FAVORITE BANK - CUSTOMER DETAILS "<<endl;
cout<<" --------------------------------"<<endl;
//print array using to string method
}
file "BankData.dat" contains:
Matilda Patel 453456 1232 -4.00
Fernando Diaz 323468 1234 250.0
Vai vu 432657 1240 987.56
Howard Chen 234129 1236 194.56
Vai vu 432657 1240 -888987.56
Sugata Misra 987654 1238 10004.8
Fernando Diaz 323468 1234 8474.0
Lily Zhaou 786534 1242 001.98
In: Computer Science
Debug the following program.Each line that has a number and line at the end of it has an error. The error can be syntax or logic. Correct the error. Rewrite the correct answer in place of the original code :
private void btnCalculate_Click (object sender, System.EventArgs e)
{
intLimit = zero; //
intCounter == 1; // counter need to begin at 1
lstResults.Items.Empty(); // clear ListBox
intLimit = Int32.Parse( txtInput); // retrieve user input from GUI
lstResults.Items.Add( "N/tN^2/tN^3" ); // add header with tabs
calculate and display square and cube of 1 to intLimit
while ( intCounter <= intLimit ) ;
lstbx.Items.Add( intCount = "\t" + Math.Pow( intCount, 2 );
Math.Pow( intCount 3^ );
intCount++; // increment counter
}
In: Computer Science
Convert 0xCD001234 from IEEE-754 hexadecimal to single-precision floating point format. Please show every single detail for upvote. Please do not answer otherwise.
In: Computer Science
a style sheet was not new with HTML and even today other languages use a similar approach. JavaFX uses an almost identical style definition as CSS for its style sheets. .NET's Windows Presentation Foundation (WPF) uses an XML like style definition in a language named XAMLAll these different technologies have one thing in common: they separate what is being displayed from how it is being displayed. Why? What is the benefit of doing so, if any? What are the drawbacks, if any? For those of you who may have taken a software architecture/engineering class, the style sheet follows a, currently, very popular architecture, do you know what it is?
120 WORDS MINIMUM
In: Computer Science
Scenario
Create an algorithm to solve the maximum subarray problem. Find the
non-empty, contiguous subarray of the input array whose values have
the largest sum. You can see an example array with the maximum
subarray indicated in the following diagram:
Screen Shot 2019-01-07 at 10.58.06 AM.png
The O(n2) brute force algorithm that tests all combinations for the
start and end indices of the subarray is trivial to implement. Try
to solve this using the divide and conquer algorithm.
Aim
To design and implement an algorithm to solve the maximum subarray
problem with a better runtime than the O(n2) brute force algorithm,
using a divide and conquer approach.
Prerequisites
You need to implement the maxSubarray() method of the
MaximumSubarray class in the source code, which returns the sum of
values for the maximum subarray of the input array. Assume that the
sum always fits in an int, and that the size of the input array is
at most 100,000.
public class MaximumSubarray {
public Integer maxSubarray(int[] a) {
return null;
}
}
The divide and conquer approach suggests that we divide the
subarray into two subarrays of as equal size as possible. After
doing so, we know that a maximum subarray must lie in exactly one
of following three places:
Entirely in the left subarray
Entirely in the right subarray
Crossing the midpoint
Steps for Completion
The maximum subarray of the arrays on the left and right is given
recursively, since those subproblems are smaller instances of the
original problem.
Find a maximum subarray that crosses the midpoint.
In: Computer Science
C#
What to submit:
One zip file named Ass3.zip
This zip must contain one VS 2017 solution named Ass3, which contains one C# Windows Forms App project also named Ass3 and the project contains a default form, Form1.cs and Program.cs.
No change should be made in Program.cs, but your Form1 must be designed and implemented to satisfy the following requirements.
**Do not submit only a single file of the solution or project. The whole solution folder of VS 2017 must be zipped and submitted for grading.
Requirements:
In: Computer Science
Discuss how a malware can maintain persistence. What do malwares use the SetWindowsHookEx function for?
In: Computer Science
Do not use awk.
Using the fixed length field file called famous.dat,
make a one-line Unix command - using pipe(s) - to
display an alphabetical list of the last and first names
in upper case of the last 8 people in the file. Hint:
Names are in columns 6 through 35. Output is this..
DARWIN
CHARLES
EINSTEIN
ALBERT
GALILEO
GALILELI
GOLDMAN
EMMA
LOVELACE
ADA
MANDELA
NELSON
PARKS
ROSA
RUSSELL BERTRAND
Hint: famous.dat uses space(s) to separate the fields
In: Computer Science