Questions
How do I add a method to make sure that the user inputs in uppercase only...

How do I add a method to make sure that the user inputs in uppercase only and anything entered in lower case throws an error as well as to make sure when they are halving the questioned number they don't enter any decimals?

import java.util.*;

public class TestCode {
public static void main(String[] args) {
String choice = "YES";
Random random = new Random();
Scanner scanner = new Scanner(System.in);
ArrayList data = new ArrayList();
int count = 0,correct=0;
while (!choice.equals("NO")) {
int randomInt = 2 * (random.nextInt(5) + 1);
System.out.println(randomInt);
System.out.println("Enter half of the random number");
int temp=scanner.nextInt();
if(2*temp==randomInt){
correct++;
System.out.println("Correct");
}
else{
System.out.println("Incorrect");
}
data.add(randomInt);
count++;
System.out.print("Want another number (Yes / No)? ");
choice = scanner.next();
}
System.out.println("You got like "+correct+" answers and "+(count-correct)+" incorrect answers");
int min = Collections.min(data);
int max = Collections.max(data);

System.out.print("Values are: ");
for (int i = 0; i < data.size(); i++) {
System.out.print(data.get(i) + " ");
}
System.out.println();

System.out.println("Percentage of Yes values is " + (((count - 1) * 100.0) / count));
System.out.println("Maximum value is " + max);
System.out.println("Minimum value is " + min);
}
}

In: Computer Science

In 2-3 pages, develop a Secure Application Development Procedure which addresses each of the OWASP Top...

In 2-3 pages, develop a Secure Application Development Procedure which addresses each of the OWASP Top Ten Vulnerabilities. Make sure to address the following:

  • Software Development Processes
  • Secure Coding Techniques
  • Application Configuration Techniques
  • Web Server Configuration Techniques

In: Computer Science

How can I fix this code to accomplish the goal of reading and writing on binary...

How can I fix this code to accomplish the goal of reading and writing on binary or text files?

3 import java.io.*;
4 import java.io.FileOutputStream;
5 import java.io.FileInputStream;
6 import java.util.Scanner;
7
8 public class ReadAndWrite implements Serializable
9 {
10 public static void main(String[] args)
11 {
12 boolean file = true;
13 Scanner inputStream;
14 PrintWriter outputStream;
15 FileInputStream inputBinary;
16 FileOutputStream readBinary;
17 FileInputStreamText writeText;
18 FIleOutputStreamText readText;
19 StringBuffer contents = new StringBuffer();
20 Scanner keyboard = new Scanner(System.in);
21 String yn = "Y N", fileName = " ", line = " ", tb = "T B", rw = "R W";
22
23 while(file)
24 {
25 System.out.println("Enter the file name.");
26 fileName = keyboard.nextLine();
27 System.out.println("Choose binary or text file (b/t):");
28 tb = keyboard.nextLine();
29 if (tb.equalsIgnoreCase("b"))
30 {
31 System.out.println("Choose read or write (r/w):");
32 rw = keyboard.nextLine();
33 if (rw.equalsIgnoreCase("r"))
34 {
35 inputBinary = new PrinterWriter(new FileInputStream(fileName));
36 System.out.println("File contains:" + readBinary);
37 inputBinary.close();
38 }
39 else
40 {
41 System.out.println("Enter a line of information to write to the file:");
42 line = keyboard.nextLine();
43 System.out.println("Would you like to enter another line? (y/n)");
44 yn = keyboard.nextLine();
45 if(yn.equalsIgnoreCase("n"))
46 {
47 file = false;
48 }
49 }
50 }
51 }
52
53 do
54 {
55 System.out.println("Choose read or write (r/w):");
56 rw = keyboard.nextLine();
57 if (rw.equalsIgnoreCase("r"))
58 {
59 FileInputStreamText = new Scanner(new FileInputStream(outputStream + ".txt"));
60 String textLine = null;
61 }
62 else
63 {
64 System.out.println("Enter a line to write to the file:");
65 line = keyboard.nextLine();
66 System.out.println("Would you like to enter another line? (y/n)");
67 yn = keyboard.nextLine();
68 if(yn.equalsIgnoreCase("n"))
69 {
70 file = false;
71 }
72 }
73 }while(tb.equalsIgnoreCase("t"));
74 System.out.println("Process completed");
75 }
76 }

In: Computer Science

Prompt user to enter an integer number from console. Use 2 methods to multiply this number...

Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result. This is required to be done in MIPS Assembly Language.

In: Computer Science

I am struggling with this java code ublic class HW2_Q4 {    public static void main(String[]...

I am struggling with this java code

ublic class HW2_Q4 {

   public static void main(String[] args) {

       // Define the input string. Note that I could have written it all on a
       // single line, but I broke it up to match the question.
       String input = "Book , Cost , Number\n"
                   + "Hamlet , 24.95 , 10\n"
                   + "King Lear , 18.42 , 13\n";
      
       // Construct a Scanner, but have it read the String defined above,
       // rather than System.in. Note that I'm leaving the name of the
       // variable as "keyboard" so that it matches the question.
       Scanner keyboard = new Scanner(input);
      
       // Declare and initialize variables to store the total cost and number.
       double totalCost = 0;
       int totalNumber = 0;

       // Write your code below using only these variables. Your code
       // should not contain literal values. For instance, do not calculate
       // the total cost with the statement "totalCost = 24.95 + 18.42".
       // Instead, use the Scanner to read the values from the keyboard.

In: Computer Science

Python DESCRIPTION Write a program that will read an array of integers from a file and...

Python

DESCRIPTION

Write a program that will read an array of integers from a file and do the following:

Task 1: Revert the array in N/2 complexity time

(i.e., number of steps)

.

Task 2: Find the maximum and minimum element of the array.

INPUT OUTPUT

Read the array of integers from a file named “

inputHW1.txt

”. To do this, you can use code snippet

from the “

file.py

” file. This file is provided in

Canvas. Copy the “

read

” function from this file and

paste it to your program file. Then, if you call the read function like the following:

numbers = read()

# The following "read" function reads values from a file named "inputHW1.txt" and

returns the values in an array.

def read():

file = open("inputHW1.txt", "r")

line = file.readline()

values = []

for value in line.split(' '):

values.append(int(value))

return values

the integers will be read from file and loaded in the numbers array.

Now, print the reverted arra

y, minimum element and maximum element of the array.

For example, if the input array is: 1 4 9 11 8 3 2 5 10

the following will be printed on the screen:

Reverted array: 10 5 2 3 8 11 9 4 1

Maximum element: 11

Minimum element: 1

EXTRA CREDIT - 30%

Find the trend change points of the array. You will get

30% extra credit

for doing this task.

Trend

change points are those points where the array

changes its direction

and

goes from

increasing to decreasing order or decreasing to increasing order.

Note that, you have to find the trend change points of the input array, not the reverted array.

For example, if the input array is: 1 4 9 11 8 3 2 5 10

the following will be printed on the screen:

Trend change points: 11 8 5

In: Computer Science

/* Homework Lab 6 This program does not work. There are three errors that you will...

/* Homework Lab 6

This program does not work. There are three errors that you will need to fix:

TODO: Fix the following 3 errors.

ERROR #1) The compiler knows there is something wrong, and it will issue a
warning and and two error messages, all related to the same problem.
       Read the error and warning messages carefully to point you in the
       right direction. Did you know if you double-click on an error
       message (in the Error List) that it will take you to the spot in
       your program where the compiler detects the problem? Also, get
       in the habit of ALWAYS reading messages carefully. You may not
       understand them right now, but over time you will come to understand
       the messages better and better. One of these three messages will be
       most helpful, but it is still informative to see that the other two
       messages come as a result of this single problem.

ERROR #2) After fixing ERROR #1 your program will run. However, you will get
incorrect results. It will say "Congratulations!" even when not perfect.

ERROR #3)

But when you find and fix that error, something still lurks behind that the
compiler does not complain about and that will give incorrect output. The output
will still display a zero after the decimal point even if it should be .3 or .7...

IMPORTANT NOTE ON ERROR #3: You are NOT allowed to change the data type of any constant
or variable to make this work. You also MUST divide by NUM_OF_SCORES
when calculating the average.
*/

//------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;

//------------------------------------------------------------------------------

int main()
{
   int score1; // To hold three test scores
   int score2;
   int score3;
   double average; // To hold the average score

   const int NUM_OF_SCORES = 3;

   // Get the three test scores.
   cout << "Enter 3 test scores and I will average them: ";
   cin >> score1 >> score2 >> score3;

   // Calculate and display the average score.
   average = (score1 + score2 + score3) / NUM_OF_SCORES;
   cout << fixed << showpoint << setprecision(1);
   cout << "Your average is " << average << endl;

   // Follow up with a message.
   if (average = 100);
       cout << "Congratulations! Those are all perfect scores" << endl;
   else
       cout << "Not perfect yet - Better luck next time." << endl;

   cout << endl;

   return 0;
}

/* Sample program interactions:
------------------------------------------------------------------------------
BEFORE FIXING ERROR #1:
======================
The program will not run!


AFTER FIXING ERROR #1:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .


Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

AFTER FIXING ERROR #2:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3 (use calculator to see what this average should be):
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

AFTER FIXING ERROR #3:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.7
Not perfect yet - Better luck next time.

Press any key to continue . . .

*/

In: Computer Science

Create a C++ program that will prompt the user to input an positive integer number and...

Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)

In: Computer Science

Create your own data. Ensure the data will test all criteria and prove all sorts worked...

Create your own data. Ensure the data will test all criteria and prove all sorts worked as required. Be sure that all tables and queries have descriptive names. “Query 1” and “Step 1” are examples of poor names.

Step 1

Build a Database named DBMS Course Project. The database should include the following tables:

  • First Table – Students
    • ID
    • First Name
    • Last Name
    • Address
    • City
    • State
    • Zip Code
    • Phone Number with area code
  • Second Table – GPA
    • ID Current GPA (two decimal positions)
    • Class (numeric field, 1 = Freshman, 2 = Sophomore, etc.)
      • Freshman
      • Sophomore
      • Junior
      • Senior
      • Graduate Student
  • Third Table – Scholarships
    • ID
    • Major course of study
    • Academic Scholarship (Use Yes/No data type)
    • Athletic Scholarship (Use Yes/No data type)

Step 2

Extract the First and Last Name, Address, City, State, Zip Code and Phone Number of each Senior on the database. Sort by Last Name, then First Name (1 sort).

Step 3

Extract the First and Last Name, and GPA of each student who qualifies for the Dean’s List. Sort by GPA, then Last Name, then First Name (1 sort). A GPA of 3.25 is required to make the Dean’s List.

In: Computer Science

Write a program that asks the user for a Fahrenheit temperature and calls a function name...

Write a program that asks the user for a Fahrenheit temperature and calls a function name Celsius that returns the temperature in Celsius of the Fahrenheit temperature sent to it. Your function will look similar to this: double celsius(double f)

{

double c;

:

:

return c;

}

In: Computer Science

write a member function in C++ , that takes two lists and return list that contain...

write a member function in C++ , that takes two lists and return list that contain the merge of the two lists


in the returned list: first insert the first list and then the second list  

In: Computer Science

Accounting Program in c++ Write a class to keep track of a balance in a bank...

Accounting Program in c++

Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to be withdrawn than what is available in the account, nor should you allow for negative deposits. Finally, there should be a function that adds interest to the balance (interest accrual) at the current interest rate. This function should have a parameter indicating how many months’ worth of interest are to be added (for example, 6 indicate the account should have 6 months’ added). Interest is accrued from an annual rate. The month is representative of 1/12 that amount. Each month should be calculated and added to the total separately. For example: 1 month accrued at 5% APR is Balance = ((Balance * 0.05)/12) + Balance; For 3 months the calculations you repeat the statement above 3 times. Use the class as part of the interactive program provided below.

In: Computer Science

Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using...

Using Java

Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, NOT LOOPS. You may use JDK String Methods like substring() and length(), but do not use the JDK methods to avoid coding algorithms assigned. For example, don’t use String.revers().

public boolean recursiveContains(char c, String s) {

if (s.length() == 0)

return false;

if (s.charAt(s.length() - 1) == c)

return true;

else

return recursiveContains(c, s.substring(0, s.length() - 1));

}

public boolean recursiveAllCharactersSame(String s) return true if all the characters in the String are identical, otherwise false. if the String has length less than 2, all characters are identical.   

public String recursiveHead(int n, String s) returns the substring of s beginning with the first character and ending with the character at n-1; in other words, it returns the first n characters of the String. Return empty String("") in cases in which n is zero or negative or exceeds the length of s.

Write either a main() or a JUnit test case for test

In: Computer Science

I'm getting a conversion issue with this program. When I ran this program using the Windows...

I'm getting a conversion issue with this program. When I ran this program using the Windows command prompt it compiles and runs without issues. Although, when I run it using the zyBooks compiler it keeps giving me these conversion errors in the following lines:

main.c: In function ‘main’: 
main.c:53:24: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] averageCpi += cpi[i] * instructionCount[i] * Million;

main.c:57:29: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] averageCpi = averageCpi / (totalInstructions * Million);

main.c:58:47: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] mips = (frequency * Million) / (averageCpi * Million);

main.c:58:37: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] mips = (frequency * Million) / (averageCpi * Million);

main.c:59:32: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] executionTime = ((averageCpi * (totalInstructions * Million)) / (frequency * Million)) * 1000;

main.c:59:65: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] executionTime = ((averageCpi * (totalInstructions * Million)) / (frequency * Million)) * 1000;

cc1: all warnings being treated as errors


Is there a more efficient way to convert from float to long int?

Here is the program: 

#include <stdio.h>

int main() {

    int instructionCount[100], totalInstructions = 0, cpi[100], noOfClass = 0, frequency = 0, ch = 0;
    float averageCpi = 0 , executionTime , mips;
    const long MILLION = 1000000;
    do{
       
        printf("\n Performance Assessment: ");
        printf("\n ----------- -----------");
        printf("\n 1) Enter Parameters");
        printf("\n 2) Print Results");
        printf("\n 3) Quit");
        printf("\n Enter Selection: ");
        scanf("%d",&ch);

        if(ch == 1){

           printf("\n Enter the number of instruction classes:  ");
           scanf("%d",&noOfClass);
           printf("\n Enter the frequency of the machine (MHz): ");
           scanf("%d",&frequency);

            for (int i = 0; i < noOfClass; ++i) {
                printf("\n Enter CPI of class %d :  ",(i+1));
                scanf("%d", &cpi[i]);
                printf("\n Enter instruction count of class %d (millions): ",(i+1));
                scanf("%d", &instructionCount[i]);
                totalInstructions += instructionCount[i];

            }
        } else if(ch == 2){

            printf("\nFREQUENCY (MHz): %d", frequency);
            printf("\nINSTRUCTION DISTRIBUTION");
            printf("\nCLASS \t CPI \t COUNT");

            for (int i = 0; i < noOfClass; ++i) {

                printf("\n %d \t %d \t %d",(i+1), cpi[i], instructionCount[i]);
                averageCpi += (cpi[i] * instructionCount[i] * MILLION);

            }

            averageCpi = averageCpi / (totalInstructions * MILLION);
            mips = (frequency * MILLION) / (averageCpi * MILLION);
            executionTime = ((averageCpi * (totalInstructions * MILLION)) / (frequency * MILLION)) * 1000;


            printf("\n PERFORMANCE VALUES");
            printf("\n AVERAGE CPI \t %.2f", averageCpi);
            printf("\n TIME (ms) \t %.2f", executionTime );
            printf("\n MIPS \t %.2f", mips);
            printf("\n");
        }

    }while(ch != 3);

    return 0;
}

In: Computer Science

Answer each of the following. Assume that single-precision floating-point numbers are stored in 8 bytes, and...

Answer each of the following. Assume that single-precision floating-point numbers are stored in 8 bytes, and that the starting address of the array is at location 2030100 in memory. Each part of the exercise should use the results of previous parts where appropriate.

a) Define an array of type float called numbers with 5 elements, and initialize the elements to the values 0.11, 0.22, 0.33, …, 0.55. Assume the symbolic constant SIZE has been defined as 5.

b) Define a pointer, nPtr, that points to an object of typefloat.

c) Print the elements of array numbers using array subscript notation. Use a for statement and assume the integer control variable i has been defined. Print each number with 2 position of precision to the right of the decimal point.

d) Give two separate statements that assign the address of last element of array numbers to the pointer variable nPtr.

e) Printthe elements of array numbers using pointer/offset notation with the pointer nPtr.

f) Print the elements of array numbers using pointer/offset notation with the array name as the pointer.

g) Print the elements of array numbers by subscripting pointer nPtr. h) Refer to element 2 of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr. i) Assuming that nPtr pointsto the end of array numbers (i.e., the memory location after the last element of the array), what addressisreferenced by nPtr - 5? What value is stored at thatlocation? j) Assuming that nPtr points to numbers[5], what address is referenced by nPtr – = 2? What’s the value stored at that location?

In: Computer Science