Questions
Java program Create two classes based on the java code below. One class for the main...

Java program

Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below.

1.The Investment class has the following members:

a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission and sales commission.

b. Write set and get methods to access each of the private fields

c. “InvestmentSummary” method to print Investment Information including the result of

3. Create two different objects of the investment class

4. Create an object of java.util.Scanner to input the information about each investment, one at a time form the keyboard, and track the information in the proper Investment objects by placing calls to the proper set methods for each of the two objects.

5. When invoking the InvestmentSummary method, use the get method found in the Investment class to access the private members.

    a. Print the investment information including gain or loss using the string %s specifier.

StockProfit.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class StockProfit {

   public static void main(String[] args) {
  
       DecimalFormat df=new DecimalFormat("#.##");
       //Scanner class object is used to read the inouts entered by the user
       Scanner kb=new Scanner(System.in);
      
       int ns; // Number of shares
double sp; // Sale price per share
double sc; // Sale commission
double pp; // Purchase price per share
double pc; // Purchase commission
double prof; // Profit from a sale
  
// Get the number of shares.
System.out.print("How many shares did you buy and then sell? ");
ns=kb.nextInt();
  
// Get the purchase price per share.
System.out.print("What price did you pay for the stock per share? ");
pp=kb.nextDouble();

// Get the purchase commission.
System.out.print("What was the purchase commission? ");
pc=kb.nextDouble();

// Get the sale price per share.
System.out.print("What was the sale price per share? ");
sp=kb.nextDouble();

// Get the sales commission.
System.out.print("What was the sales commission? ");
sc=kb.nextDouble();

// Get the profit or loss.
prof = profit(ns, pp, pc, sp, sc);

// Display the result.
System.out.print("The profit from this sale of stock is $"+df.format(prof));

   }
   // ********************************************************
   // The profit function accepts as arguments the number of *
   // shares, the purchase price per share, the purchase *
   // commission paid, the sale price per share, and the *
   // sale commission paid. The function returns the profit *
   // (or loss) from the sale of stock as a double. *
   // ********************************************************
   private static double profit(int ns, double pp, double pc, double sp,
           double sc) {
       return ((ns * sp) - sc) - ((ns * pp) + pc);
   }

}

In: Computer Science

How to write this Python You are a small business owner and you have six employees....

How to write this Python
You are a small business owner and you have six employees. All the employees have the same pay rate, that is $12 per hour. Write a program that will ask the user to enter the number of hours worked by each employee, then display the amounts of gross pay for each employee.

1.    Get the number of worked hours for each employee and store it in a list.
2.    Use the stored value in each element to calculate the gross pay for each employee and display the amount. 
3.    Match your output format to the below sample output.

Answer should look like this

Enter the hours worked by employee 1: 20
Enter the hours worked by employee 2: 25
Enter the hours worked by employee 3: 29
Enter the hours worked by employee 4: 30
Enter the hours worked by employee 5: 20
Enter the hours worked by employee 6: 19

Enter the hourly pay rate: 12

Gross pay for employee 1: $240.00
Gross pay for employee 2: $300.00
Gross pay for employee 3: $348.00
Gross pay for employee 4: $360.00
Gross pay for employee 5: $240.00
Gross pay for employee 6: $228.00

In: Computer Science

What decimal value does the 8-bit binary number 10011110 have if: a) it is interpreted as...

What decimal value does the 8-bit binary number 10011110 have if:

a) it is interpreted as an unsigned number?

b) It is on a computer using signed-magnitude representation?

c) It is on a computer using one’s complement representation?

d) It is on a computer using two’s complement representation?

In: Computer Science

when the user entered a negative number, you output a message that it was not possible...

when the user entered a negative number, you output a message that it was not possible to take the square root of a negative number. This time you will write a Python program that asks the user to enter a non-negative number (float). If the user does enter a negative number, you will use a while loop to continue prompting the user until you get a valid number (i.e. a number >= 0). Once the user enters a valid number, you calculate and print the square root. Test your program twice, once using a negative number and once using a non-negative number.

In: Computer Science

Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a...

Write a python function called HackCaesar with the following requirements:

def hack_caesar(cyphertext): ‘’’ cyphertext is a text encoded using Caesars encryption. The encryption key is unknown. The function returns the correct encryption key. Hint: Use the function we wrote was called caesar(c, key) and could encode a single character.

# YOUR CODE GOES HERE


def is_odd(n):
return n%2 == 1


def caesar(c, key):
""" Encrypts a lower case character c using key
Example: if c = "a" and key=3 then the function should return d
"""
return chr((ord(c)-97+key) % 26 + 97)


n = input("enter a number:")
n = int(n)
if n > 10:
print("hello")
print("your number if more than 10")
else:
print("else block")



for i in range(5):
print(i)
print(i*i)
print(is_odd(i))
print(caesar("a", 3))

In: Computer Science

Write a decorator function that has the following property: 1.  The name of a decorator is uppercase...

Write a decorator function that has the following property:

1.  The name of a decorator is uppercase and takes a function as input.

2.  The decorator has an inner function called wrapper with no input argument.

3.  The wrapper function has two local variables: original and modified.

4.  The input function argument of decorator gets assigned to the original variable inside the wrapper function and the upper case version of the input function gets assigned to the modified variable.

5.  The wrapper function returns the modified variable.

6.  The decorator returns the wrapper (per the usual of the inner functions in decorators)

7.  Write a new function called greetings that prints “Hello”.

8.  Decorate the greetings function with the uppercase decorator function.

9.  Run the program by invoking the greetings function. Record the output and include it with your code.

10. Save the decorator uppercase as a separate Python file and import it to a new file that defines the greetings function as a decorated function that simply prints the “Hello” message.

11. Generate the output by invoking the greetings function.

In: Computer Science

Q2) How thick does paper folding get? Take one sheet out of your newspaper, and fold...

Q2) How thick does paper folding get? Take one sheet out of your newspaper, and fold it in half, then fold it in half again, and again, and again. Can you fold it 30 times? Pretending that you can (you probably can’t fold it more than 8 times), how thick would it be after 30 times? Assume the paper is 1/200 cm. thick. Write a program to solve this puzzle. Prompt for the number of folds and output the thickness in meters. Note : Run by pycharm

In: Computer Science

Hank & Sons is a retail seller of computers. At the end of the month, each...

Hank & Sons is a retail seller of computers. At the end of the month, each salesperson’s commission is calculated according to the commission table in the previous question. Salespersons also need to pay a monthly admin fee based on their total monthly sales for office supply.

For example, a salesperson with $16,000 in monthly sales will earn a 12% commission minus admin fee ($1,920 - $150). Another salesperson with $20,000 in monthly sales will earn a 15% commission minus admin fee ($3,000 - $200).

Because the staff gets paid once per month, Hank & Sons allows each employee to take up to $1,500 per month in advance. When sales commissions are calculated, the amount of each employee’s advanced pay is subtracted from the commission. If any salesperson’s commission is less than the amount of this advance, he or she must reimburse Hank & Sons for the difference.

Write the pseudo code for calculating the total monthly net income for Hank & Sons sellers. The program should first ask the user to enter the salesperson’s monthly sales and the amount of advanced pay. Then draw the flowchart for your pseudo code.

In: Computer Science

This is a very simple program that will ONLY print a heading and columns of text...

This is a very simple program that will ONLY print a heading and columns of text to emulate the following information:

Sales This Month

Admin Fee

Commission Rate

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

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

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

Less than $10,000

$150

5%

$10,000 – 14,999

$150

10%

$15,000 – 17,999

$150

12%

$18,000 – 21,999

$200

15%

$22,000 or more

$200

16%

******Salesperson of the month******

Name: STUDENT NAME

ID: STUDENT ID

public class SalesResult {

public static void main(String[] args) {

System.out.println();

. . .

}

}

Create a Java project in Eclipse named SalesProject and add a class named SalesResult to reproduce a table like the above. In your program repeat the System.out.println(); as many times as needed.

I was wondering how to write the code to create such a table...

In: Computer Science

Why is the output for LowestSales a negative number? I am using Visual Studio. _______________________________________*_________________________________________ int...

Why is the output for LowestSales a negative number? I am using Visual Studio.

_______________________________________*_________________________________________

int main()
{
   const int STORE = 10;
   double Sales[STORE];//array for sales
   double HighestSales = Sales[], LowestSales = Sales[]; //arrays to capture highest and lowest sales
   double AverageSale = 0.00; //stores average sale amount

   for (int i = 0; i < 10; i++) // gather sales from 10 stores
   {
       cout << "Enter Store " << (i + 1) << " daily sales: \n";
       cin >> Sales[i]; //prompt the user to enter the daily sales
  
       int HighStoreNo = 0, LowStoreNo = 0; //initialize variables for high store number and low store number

       if (HighestSales > Sales[i] && (isdigit(Sales[i]) != 0) //check to see if this the highest sale, and check for positive integer
       {
           HighestSales = Sales[i]; //assign value to array member to store 'highest sales'
           HighStoreNo = i; //if highest value, assign stored value
       }
       if    (LowestSales <= Sales[i] && (isdigit(Sales[i]) != 0); //assign value to array member to store 'lowest sales'
               LowestSales = Sales[i];
               LowStoreNo = i;   //if lowest value, assign stored value
       }
  
   AverageSale += Sales[i]; //keep accumulating sales total

   }
   cout << fixed << showpoint << setprecision(2);//sets output precision to two decimals
   AverageSale = AverageSale/10; //calculate the average sale by dividing by 10 stores
  
   cout << "Highest Sale: " << HighestSales << ", Store number: " << (HighStoreNo + 1) << endl; //highest sale
   cout << "Lowest Sale: " << LowestSales << ", Store number: " << (LowStoreNo + 1) << endl; //lowest sale
   cout << "Average Sale: " << AverageSale << endl; //average sale

In: Computer Science

Write a program that loops, prompting the user for their full name, their exam result (an...

Write a program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules:

  • First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long.
  • Exam result (an integer between 1 and 100 inclusive)

The file should record each customers information on a single line and the output file should have the following appearance.

Nurke Fred 58

Cranium Richard 97

Write a second program that opens the ‘customers.txt’ file for reading and then reads each record, splitting it into its component fields and checking each field for validity.

The rules for validity are as in your first program, with the addition of a rule that specifies that each record must contain exactly 3 fields.

Your program should print out each valid record it reads.

The program should be able to raise an exception on invalid input, print out an error message with the line and what the error was, and continue running properly on the next line(s).

In: Computer Science

Python It's time to put everything together!  This week you will write a program that mimics an...

Python

It's time to put everything together!  This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. I leave the bulk of design up to you (hint - think A LOT about it before you start programming!!) but it should include all of the following:

The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price.

- Ensure the user types in numbers for quantities
- "Hardcode" the price of items into a list and pick from it randomly for each item
- Get the user's name and shipping address
- Separate functions that compute tax (bonus - different based on shipping state?) and shipping costs (based on number of items?), and returns their values to the main program
- Bonus: Set up a list of lists with all the items/prices in your store and only let users pick from that list

In: Computer Science

To play the PowerBall lottery, you buy a ticket that has five unique numbers in the...

To play the PowerBall lottery, you buy a ticket that has five unique numbers in the range of 1–69, and a “PowerBall” number in the range of 1–26. (You can pick the numbers yourself, or you can let the ticket machine randomly pick them for you.) Then, on a specified date, a winning set of numbers is randomly selected by a machine. If your first five numbers match the first five winning numbers in any order, and your PowerBall number matches the winning Pow-erBall number, then you win the jackpot, which is a very large amount of money. If your numbers match only some of the winning numbers, you win a lesser amount, depending on how many of the winning numbers you have matched. In the student sample programs for this book, you will find a file named pbnumbers.txt, containing the winning PowerBall numbers that were selected between February 3, 2010 and May 11, 2016 (the file contains 654 sets of winning numbers). Figure 8-6 shows an example of the first few lines of the file’s contents. Each line in the file contains the set of six numbers that were selected on a given date. The numbers are separated by a space, and the last number in each line is the PowerBall number for that day. For example, the first line in the file shows the numbers for February 3, 2010, which were 17, 22, 36, 37, 52, and the PowerBall number 24. Write a program that works with this file to display the 10 most common numbers, ordered by frequency.

In: Computer Science

This is a question about coding in python. I think that the question is asking me...

This is a question about coding in python. I think that the question is asking me to code the following: Implement the scalar product of 2 vectors in 2-space, using two tuple parameters (the function scalarProduct2). Write a docstring; then write some test function calls (can I pick any data for this? - the question gave these examples data examples: (1., 1.) dot (2,3) = (1.,1.) dot (2,0) = (1., 1.) dot (0,2) = (1., 1.,) dot (4,5) = ); then implement the body of the function ( I am not sure what this means - run the function?)

In: Computer Science

Perform a Web search for “Announcing the Advanced Encryption Standard (AES).” Read this document, which is...

Perform a Web search for “Announcing the Advanced Encryption Standard (AES).” Read this document, which is a FIPS 197 standard. Write a short overview of the development and implementation of this cryptosystem. Your response must include the type of Algorithm used, the size of data blocks that can be processed, and the lengths of the cipher keys.

In: Computer Science