The primary objective of this assignment is to reinforce the concepts of string processing.
Part A: Even or Odd
For this first part, write a function that will generate a random number within some range (say, 1 to 50), then prompt the user to answer if the number is even or odd. The user will then input a response and a message will be printed indicated whether it was correct or not. This process should be repeated 5 times, using a new random number for each play, regardless of whether the user was correct or not.
Notes
>>> assign2PartA()
Is 41 odd or even? Odd
Correct
Is 48 odd or even? Even
Correct
Is 3 odd or even? e
Incorrect
Is 20 odd or even? o
Incorrect
Is 42 odd or even? xyz
You did not enter a correct reply.
Please answer using Odd or Even
Part B: Vowel Counting
The second task is to write a function that counts, and prints, the number of occurrences for each vowel (a, e, i, o and u) in a given phrase and outputs a (new) phrase with the vowels removed. The phrase should be accepted as a parameter to the function. If the (original) phrase is empty, you should output an appropriate error message, and obviously with no vowel counts. If the phrase contains no vowels, a message should be displayed, and the count can be omitted – since there is no point in displaying 0 for each vowel! A message should also be displayed if the phrase contains only vowels, but the counts should still be displayed.
Notes
>>> assign2PartB("Remember that context here defines
\"+\" as 'Concatenate'")
A E
I O U
4 10 1
2 0
The original phrase is: Remember that context here defines "+"
as 'Concatenate'
The phrase without vowels is: Rmmbr tht cntxt hr dfns "+" s
'Cnctnt'
>>> assign2PartB("bcdfghjklmnpqrstvwxyz")
The phrase contains no vowels: bcdfghjklmnpqrstvwxyz
>>> assign2PartB("aeiouAEIOU")
A E
I O U
2 2
2 2 2
The phrase contains only vowels: aeiouAEIOU
>>> assign2PartB("")
The input phrase is empty!
>>>
In: Computer Science
Java Class
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class ReadInData {
public static double readData(String fileName)
{
File file = new
File(fileName);
Scanner scan;
double sum = 0;
try {
scan = new
Scanner(file);
int numOfValues
= Integer.parseInt(scan.nextLine()); // Read in Val for #
values
for(int i = 0; i
< numOfValues; i++) { // for-loop to get that many values
sum += scan.nextDouble(); // add the values
together (doubles)
}
scan.close();
return sum; //
return the sum of all the values in the file
}//add catch statements
here
}
public static void main(String[] args) {
System.out.println(readData("Test3.txt"));
System.out.println(readData("Test2.txt"));
System.out.println(readData("Text4.txt")); // notice spelling of
the file name!
System.out.println(readData("Test4.txt"));
}
}
Test2.txt
6 5 3.0 "9.8" -19.8 -54.1 85.5
Test3.txt
4.0 5.0 6.2 4.2 1.0
Test4.txt
5 4.2 3.1 2.2 6.1
In: Computer Science
In: Computer Science
Find the computational complexity i.e. O(n) etc. for the following four loops and explain why you came to that answer:
In: Computer Science
I am writing a scheme function that pairs an element to every element in a list, and I have the following code so far:
(define (pair-element e l)
(cond ((null? l) (list e))
(else (cons e (car l)) (pair-element (cdr l)))))
(pair-element 4 `(4 3 5))
What is my error? I'm getting a pair element mismatch when I run it. I need to do this without using built-in functions. Thanks!
In: Computer Science
For a given CPU, the cycle latency for a set of operations are given as follows:
Addition: 4
Subtraction: 8
Multiplication: 64
Division: 80
If the clock of this CPU runs at 3GHz, find the following
How many operations of each of the list above can this CPU perform in 5 minutes?
If we have a set of operations that contains 10^9 of each operation in the list in part 1, compute the required time in seconds to execute the set. Please explain the formula used.
In: Computer Science
Please make your Task class serializable with a parameterized and copy constructor, then create a TaskListDemo with a main( ) method that creates 3 tasks and writes them to a binary file named "TaskList.dat". We will then add Java code that reads a binary file (of Task objects) into our program and displays each object to the console. More details to be provided in class.
Here is a sample transaction with the user (first time the code is run):
Previously saved Tasks from binary file:
[None, please enter new Tasks]
Please enter task name (or "quit" to exit): Ace CS 112 Final
Exam
Please enter due date (in form MM/DD/YYYY): 10/10/2019
Please enter deadline : 3:20 PM
Please enter priority : 1
After 1 Task has been saved (second time the code is run):
Previously saved Tasks from binary file:
Task [name=Ace CS 112 Midterm Exam, dueDate=10/10/2019,
deadline=3:20 PM, priority=High]
Please enter task name (or "quit" to exit): quit
I don't know how to print the priorities High, medium, and Low in the toString method to where it is stored in the binary file after the user types 1, 2, or 3. 1 for high, 2 for medium, and 3 for low.
import java.io.*;
import java.util.Scanner;
public class IC10_TaskList {
public static void main(String[] args) {
String name, dueDate, deadline;
int priority;
Scanner keyboard = new Scanner(System.in);
Task[] allTasks = new Task[10];
int count = 0;
File binaryFile = new File("Task.dat");
try {
System.out.println("\nPreviously saved tasks from the binary file:");
if (binaryFile.exists()) {
ObjectInputStream inFile = new ObjectInputStream(new FileInputStream(binaryFile));
allTasks = (Task[]) inFile.readObject();
inFile.close();
for(int i = 0; i < allTasks.length; i++){
if(allTasks[i] != null){
System.out.println(allTasks[i]);
count++;
}
else
break;
}
}
else
System.out.println("[None, Please enter new task data]");
}
catch(IOException e){
System.err.println("Cannot find Task.dat");
}
catch(ClassNotFoundException e){
System.err.println("Serial Task version does not match.");
}
do{
System.out.print("\nPlease enter task name(or \"quit\" to exit): ");
name = keyboard.nextLine();
if(name.equalsIgnoreCase("quit"))
break;
System.out.print("Please enter due date(in form MM/DD/YYYY): ");
dueDate = keyboard.nextLine();
System.out.print("Please enter deadline: ");
deadline = keyboard.nextLine();
System.out.print("Please enter priority: ");
priority = keyboard.nextInt();
allTasks[count++] = new Task(deadline, dueDate, name, priority);
keyboard.nextLine();
} while(!name.equalsIgnoreCase("quit"));
try{
ObjectOutputStream outFile = new ObjectOutputStream(new FileOutputStream(binaryFile));
outFile.writeObject(allTasks);
outFile.close();
}
catch(IOException e){
System.err.println("File Task.dat cannot be found and/or written.");
}
}
}
import java.io.Serializable;
import java.util.Objects;
public class Task implements Serializable {
public static final long serialVersionUID = 1;
private String mDeadline;
private String mDueDate;
private String mName;
private int mPriority, mChoice;
public Task(String deadline, String dueDate, String name, int priority) {
mDeadline = deadline;
mDueDate = dueDate;
mName = name;
mPriority = priority;
}
public String getDeadline() {
return mDeadline;
}
public void setDeadline(String deadline) {
mDeadline = deadline;
}
public String getDueDate() {
return mDueDate;
}
public void setDueDate(String dueDate) {
mDueDate = dueDate;
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
public int getPriority() {
return mPriority;
}
public void setPriority(int priority) {
mPriority = priority;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return mPriority == task.mPriority &&
mDeadline.equals(task.mDeadline) &&
mDueDate.equals(task.mDueDate) &&
mName.equals(task.mName);
}
@Override
public int hashCode() {
return Objects.hash(mDeadline, mDueDate, mName, mPriority);
}
@Override
public String toString() {
return "Task[" +
"Name = " + mName +
", Due Date = " + mDueDate +
", Deadline = " + mDeadline +
", Priority = " + mPriority +
"]";
}
}In: Computer Science
You will create a program that will follow the queuing theory of the Barbershop Problem. You will initially create a flow chart for the assignment to be uploaded to the Queuing Theory Flowchart assignment drop box. In this you will use queues and random number generators to complete this project. You will create three queues
You will create a container for the barbers chairs (list) . The wait times for the barbers will be random. Barber one will be the fastest and barber three will be the slowest. Randomize the wait times accordingly.
The cashier wait times will also vary randomly.
Barber wait times.
Cashier wait time
In: Computer Science
How has bribery been changed since it has become a statutory crime?
In: Computer Science
JAVA CODE
Give the definition of a static method called showArray that has an array of base type char as a single parameter and that writes to the screen each character in the array on a separate line. It then writes the same array characters in reverse order. This method returns a character array that holds these two lines of characters in the order that you printed them.
In: Computer Science
3) Please answer full question thoroughly (A- J) showing detailed work. Double check answer and work to ensure it is correct for thumbs up.
Boolean Functions, Truth Tables, Logic Minimization, Two-Level Forms Consider a boolean function f (a, b, c, d). Suppose that the function is 1 if
• There is a single 1 among the inputs, or
• There is a single 0 among the inputs, or
• There are exactly two 1’s among the inputs
and it is 0 otherwise.
(a) Write down a truth table for the function
(b) Using a Karnaugh map, provide a minimal sum-of-products (AND-OR) expres- sion.
(c) Using a Karnaugh map, provide a minimal product-of-sums (OR-AND) expres- sion.
(d) Provide a minimal NAND-NAND expression
(e) Provide a minimal OR-NAND expression (f) Provide a minimal NOR-OR expression
(g) Provide a minimal NOR-NOR expression (h) Provide a minimal AND-NOR expression
(i) Provide a minimal NAND-AND expression
(j) Provide a AND-XOR expression (with no negations)
In: Computer Science
The data warehouse is one of the most important business intelligence tools a business needs to have. It turns the massive amount of data generated from multiple sources into a format that is easy to understand.
Discuss the data warehouse concept?
In: Computer Science
JAVA CODE
Using the PurchaseDemo program and output from the previous problem as your guide, write a program that uses the Purchase class to set the following prices, and buy the number of items as indicated. Calculate the subtotals and total bill called total. Using the writeOutput() method display the subtotals as they are generated as in the PurchaseDemo program. Then print the total bill at the end. You may use integer, double, and String variables as needed but you may use only one object of the Purchase class and a for loop.
(Use the readInput() method for the following input data, you may assume the prompts and Scanner for the readInput() method takes place but you need not include either in your program output. )
Oranges: 10 for 2.99 buy 2 dozen oranges
Eggs; 12 for 1.69 buy 3 dozen eggs
Apples: 3 for 1.00 buy 20 apples
Watermelons: 4.39 each buy 2 watermelons
Bagels; 6 for 3.50 buy 1 dozen bagels
public class PurchaseDemo
{
public static void main(String[] args)
{
Purchase oneSale = new Purchase();
oneSale.readInput();
oneSale.writeOutput();
System.out.println("Cost each $" + oneSale.getUnitCost());
System.out.println("Total cost $" + oneSale.getTotalCost());
}
}
import java.util.Scanner;
/**
Class for the purchase of one kind of item, such as 3
oranges.
Prices are set supermarket style, such as 5 for $1.25.
*/
public class Purchase
{
private String name;
private int groupCount; //Part of a price, like the 2 in //2 for
$1.99.
private double groupPrice; //Part of a price, like the $1.99
// in 2 for $1.99.
private int numberBought; //Number of items bought.
public void setName(String newName)
{
name = newName;
}
/**
Sets price to count pieces for $costForCount.
For example, 2 for $1.99.
*/
public void setPrice(int count, double costForCount)
{
if ((count <= 0) || (costForCount <= 0))
{
System.out.println("Error: Bad parameter in " +
"setPrice.");
System.exit(0);
}
else
{
groupCount = count;
groupPrice = costForCount;
}
}
public void setNumberBought(int number)
{
if (number <= 0)
{
System.out.println("Error: Bad parameter in " +
"setNumberBought.");
System.exit(0);
}
else
numberBought = number;
}
/**
Reads from keyboard the price and number of a purchase.
*/
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter name of item you are purchasing:");
name = keyboard.nextLine();
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 3 for $2.99 is entered as");
System.out.println("3 2.99");
System.out.println("Enter price of item as two numbers, " +
"now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0))
{ //Try again:
System.out.println("Both numbers must " +
"be positive. Try again.");
System.out.println("Enter price of " +
"item as two numbers.");
System.out.println("For example, 3 for " +
"$2.99 is entered as");
System.out.println("3 2.99");
System.out.println(
"Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
}
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0)
{ //Try again:
System.out.println("Number must be positive. " +
"Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
/**
Displays price and number being purchased.
*/
public void writeOutput()
{
System.out.println(numberBought + " " + name);
System.out.println("at " + groupCount +
" for $" + groupPrice);
}
public String getName()
{
return name;
}
public double getTotalCost()
{
return (groupPrice / groupCount) * numberBought;
}
public double getUnitCost()
{
return groupPrice / groupCount;
}
public int getNumberBought()
{
return numberBought;
}
}
In: Computer Science
Respond to the following in a minimum of 175 words:
Organizations need to know the value of their data to find the best way to protect it. The data must be categorized according to the organization’s level of concern for confidentiality, integrity, and availability. The potential impact on assets and operations should be known in case data, systems, and/or networks are compromised (through unauthorized access, use, disclosure, disruption, modification, or destruction).
Choose an organization from the Health Care, Finance, or Education sector to study throughout this course.
Based on your chosen organization, ensure you:
In: Computer Science
6. Write a Python function that checks whether a passed string is palindrome or
not. Note:-A palindrome is a word, phrase, or sequence that reads the same backward
as forward
. Some examples you may try: “madam”
redder
“race car”
Eva, Can I Stab Bats In A Cave?
If the argument passed is not a string,
invoke an exception or an assertion
and state in a comment which one you have chosen and why.
In: Computer Science