Questions
java Given a sequence of integers as an array, determine whether it is possible to obtain...

java

Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. Here are the constraints. 1. You must use only arrays. 2. You are not allowed to make copies of the array (use only the one that is passed). 3. Your algorithm running time must be at most O(n 2 ). i.e. You can have only one loop within another. Ideally, you should be able to find a linear running time algorithm. i.e. you can even solve this problem using a single loop. Note: Sequence a0, a1, . . . an is considered to be a strictly increasing if a0 < a1 < . . . < an. Sequence containing only one element is also considered to be strictly increasing. Assuming your method is almostIncreasingSequence, following main method could be used to test your code.

public static void main(String[] args) { int[] a1 = {1, 3, 2, 1}; // false int[] a2 = {1, 3, 2}; // true int[] a3 = {1, 2, 1, 2}; // false int[] a4 = {3, 6, 5, 8, 10, 20, 15}; // false int[] a5 = {1, 1, 2, 3, 4, 4}; // false int[] a6 = {1, 4, 10, 4, 2}; // false int[] a7 = {10, 1, 2, 3, 4, 5}; // true int[] a8 = {1, 1, 1, 2, 3}; // false int[] a9 = {0, -2, 5, 6}; // true int[] a10 = {1, 2, 3, 4, 5, 3, 5, 6}; // false int[] a11 = {40, 50, 60, 10, 20, 30}; // false int[] a12 = {1, 1}; // true int[] a13 = {1, 2, 5, 3, 5}; // true int[] a14 = {1, 2, 5, 5, 5}; // false int[] a15 = {10, 1, 2, 3, 4, 5, 6, 1}; // false int[] a16 = {1, 2, 3, 4, 3, 6}; // true int[] a17 = {1, 2, 3, 4, 99, 5, 6}; // true int[] a18 = {123, -17, -5, 1, 2, 3, 12, 43, 45}; // true int[] a19 = {3, 5, 67, 98, 3}; // true int[] a20 = {1, 1, 1}; // false System.out.println(Arrays.toString(a1) + ": " + (almostIncreasingSequence(a1) == false)); System.out.println(Arrays.toString(a2) + ": " + (almostIncreasingSequence(a2) == true)); System.out.println(Arrays.toString(a3) + ": " + (almostIncreasingSequence(a3) == false)); System.out.println(Arrays.toString(a4) + ": " + (almostIncreasingSequence(a4) == false)); System.out.println(Arrays.toString(a5) + ": " + (almostIncreasingSequence(a5) == false)); System.out.println(Arrays.toString(a6) + ": " + (almostIncreasingSequence(a6) == false)); System.out.println(Arrays.toString(a7) + ": " + (almostIncreasingSequence(a7) == true)); System.out.println(Arrays.toString(a8) + ": " + (almostIncreasingSequence(a8) == false)); System.out.println(Arrays.toString(a9) + ": " + (almostIncreasingSequence(a9) == true)); System.out.println(Arrays.toString(a10) + ": " + 2 (almostIncreasingSequence(a10) == false)); System.out.println(Arrays.toString(a11) + ": " + (almostIncreasingSequence(a11) == false)); System.out.println(Arrays.toString(a12) + ": " + (almostIncreasingSequence(a12) == true)); System.out.println(Arrays.toString(a13) + ": " + (almostIncreasingSequence(a13) == true)); System.out.println(Arrays.toString(a14) + ": " + (almostIncreasingSequence(a14) == false)); System.out.println(Arrays.toString(a15) + ": " + (almostIncreasingSequence(a15) == false)); System.out.println(Arrays.toString(a16) + ": " + (almostIncreasingSequence(a16) == true)); System.out.println(Arrays.toString(a17) + ": " + (almostIncreasingSequence(a17) == true)); System.out.println(Arrays.toString(a18) + ": " + (almostIncreasingSequence(a18) == true)); System.out.println(Arrays.toString(a19) + ": " + (almostIncreasingSequence(a19) == true)); System.out.println(Arrays.toString(a20) + ": " + (almostIncreasingSequence(a20) == false)); }

Output should be the following (Please carefully look at why it prints all true before asking questions). [1, 3, 2, 1]: true [1, 3, 2]: true [1, 2, 1, 2]: true [3, 6, 5, 8, 10, 20, 15]: true [1, 1, 2, 3, 4, 4]: true [1, 4, 10, 4, 2]: true [10, 1, 2, 3, 4, 5]: true [1, 1, 1, 2, 3]: true [0, -2, 5, 6]: true [1, 2, 3, 4, 5, 3, 5, 6]: true [40, 50, 60, 10, 20, 30]: true [1, 1]: true [1, 2, 5, 3, 5]: true [1, 2, 5, 5, 5]: true [10, 1, 2, 3, 4, 5, 6, 1]: true [1, 2, 3, 4, 3, 6]: true [1, 2, 3, 4, 99, 5, 6]: true [123, -17, -5, 1, 2, 3, 12, 43, 45]: true [3, 5, 67, 98, 3]: true [1, 1, 1]: true

In: Computer Science

Compare and contrast the 3 types of facts tables: Additive, Semi-Additive, and Non-Additive.

Compare and contrast the 3 types of facts tables: Additive, Semi-Additive, and Non-Additive.

In: Computer Science

Answer all the questions given below Explain the difference between edge triggered and level triggered interrupt...

  1. Answer all the questions given below

  1. Explain the difference between edge triggered and level triggered interrupt by sketch. Where the starting address of the memory location of every interrupt is stored?

              (b) Consider the following 8051 interfacing problem. Crystal frequency: 11.059MHz. The LED  

                D8 will light up with every key press as shown below.

  1. Initialize IE register for external interrupt at INT0

  2. Initialize TCON register for the appropriate type of interrupt

  3. Declare and define the interrupt service routine

  4. Access and configure relevant pin as needed

  5. Call back action in the main function as needed

In: Computer Science

what are Media Selection Criteria? Include in your descriptions Cost, Speed, Distance and expandability, Environment and...

what are Media Selection Criteria? Include in your descriptions Cost, Speed, Distance and expandability, Environment and Security. Why each criteria is important?

In: Computer Science

(Python language) Going out with the gang? You are planning an outing with some friends and...

(Python language)

Going out with the gang?

You are planning an outing with some friends and need to calculate the total price of the tickets. A regular ticket usuallycosts$3.99 and a student ticket costs only $2.99. If the total number of tickets being ordered (including both students andregular tickets) is at least 10, then a 10% discount is applied to the order. However, if it is a holiday, then the at-least-tengroup discount is only 5% (not 10%).Write a functiontotalticketprice: given three parameters (the number of regular tickets, the number of studenttickets, and whether or not it is a holiday), compute and return the total. Be sure to define and use constants forREGULARTICKETPRICEandSTUDENTTICKETPRICE. We’ll check for this.

Is it time for tea?

Your friend lives in London, England in a timezone that is normally 6−hours ahead of Toronto, Canada. But sometimesEngland and Canada switch to daylight savings time on different dates. If Toronto is on daylight savings time and Londonis not, then the time difference is only 5−hours. Conversely, if London is on daylight savings time and Toronto is not, thetime change is 7−hours. Of course, if both are on daylight savings time, the difference is back to the standard 6−hours. Write the functionbritishtimewhose first parameter is a float value representing the time in Toronto as 24-hour time.The next two parameters are booleans indicating whether Toronto and London are on daylight savings time, respectively.Your function should return the time in London as a float.One last complication is that your function should not return a time greater or equal to 24.0 or less than 0.0.Suggestion: at first do not consider this final complication and write test cases where the expected output is already less than24.0(in the same day). Once that is working, add a test case where the time in Toronto is so late at night that London isalready the next morning. Fix the body of your function to work correctly.For the purpose of this lab, afunctiontakes some input (not always) and returns some output (not always). Go back and makesure that none of your functions print anything!Printing is notthe same as returning!

In: Computer Science

Write a program in Java Swing that can Display all the name list then will generate...

Write a program in Java Swing that can Display all the name list then will generate and display the longest name out of a list of names. Thank you...

In: Computer Science

Structured query language (SQL): A. Does not allow conditions to be put on the query. B....

Structured query language (SQL):

A. Does not allow conditions to be put on the query. B. Is a complex language used to extract data from a limited number of tables. C. Isolates data within tables. D. Takes advantage of the primary record key to link tables.

In: Computer Science

Use the Web, University Library, or other sources to find out specifics about the Encrypted File...

Use the Web, University Library, or other sources to find out specifics about the Encrypted File System that is part of Windows. Describe this file system, and any strengths and any weaknesses you find. Write a 3 to 4 page paper use APA format and adhere to the writing rubric.

In: Computer Science

Conduct some research and find a recent computer virus that has attacked either a company or...

Conduct some research and find a recent computer virus that has attacked either a company or individuals. Explain how the virus effects computers or networks and how to stop the virus.

In: Computer Science

I am taking TECH490: Integrated Technology Management Assessment and need to show that I have accoplished...

I am taking TECH490: Integrated Technology Management Assessment and need to show that I have accoplished this task by school work or on my job.

What examples can I use to show that I met this outcome?

Apply knowledge of mathematics to problem-solving in management contexts.

In: Computer Science

The purpose of the program is to play the game of M.A.S.H. (Mansion, Apartment, Shack, House)....

The purpose of the program is to play the game of M.A.S.H. (Mansion, Apartment, Shack, House). This program asks the user multiple questions and then randomly generates answers based on the answers to predict the user’s future. By the time you finish this program, you will have learned how to make a menu based program, use switch statements, validate user input with loops, allow a program to run multiple times until user wants to quit, and mix cin>> and getline() intermittently in a program.

  1. Names of three people (2 they like & one they don’t like)
  1. Three integer numbers between 1 and 100
  2. Three locations including city & state (2 they like & one they don’t like)
  3. Three job titles (2 they like & one they don’t like)
  4. Three companies or restaurants (2 they like & one they don’t like)
  5. Three integer numbers between 10000 and 500000
  6. Three types of cars (2 they like & one they don’t like
  7. You will be predicting the user’s future by selecting one of their three choices randomly. You will need to create a random number for each “category” – this means there should be in total 7 numbers randomly generated between 1 and 3. So for example, you will generate a random number between 1 and 3 for the names of people.

    You will also generate one more random number (this would make 8 total) between 1 and 4 which will indicate if the user will live in a mansion (1), apartment (2), shack (3), or house(4).

  8. Indent and comment your code properly.
  9. MENU - You will have a main menu that will ask the user to either

    1) Play MASH or
    2) End the program.

    You must have a switch statement to figure out which choice the user selected. The program should run over and over until the user selects to end the program using a do-while loop. Use a Boolean variable to help with this!
  10. You MUST validate user input with while loops if the input is a number to ensure the number is in the specified range. You may assume the user will enter in a number (not a character or string), but you can’t assume they enter a number within the specified range.
  11. You MUST allow spaces to be included in all string input.
  12. For housing you are not asking the user for the data. The acronym MASH stands for the different types of housing. There are four choices (Mansion, Apartment, Shack or House). You will need to generate a number between 1 and 4. If it is a 1, you will print out that the user will live in a mansion. If it is a 2, you will print out that the user will live in an apartment……and so on.
  13. For all the other “categories” you have three choices, not four. So you will need to generate a number between 1 and 3. If it is a 1, you print out the first one, 2 the second one, and 3 the third one. For example, for spouse – generate a number between 1 and 3. If it is a 1, then print out the first person that the user said they like. If it is a 2, then print out the second person that the user said they like. If it is a 3, then print out the third person that the user dislikes.    Before printing out the spouse, you should say “You will be happily married to “ and then print out the name.
  14. For the answers you should say something like:
    • You will live in ….
    • You will be happily married to …
    • You and your spouse will have ….. children.
    • You will live in …..      (name city, state here)
    • You will work at ……. (place) as a ……… (job title) making $ ……… (salary) a year.
    • You will drive a ……

In: Computer Science

In Java, code an intelligent system for diagnosis breast cancer. There are no special requirements, you...

In Java, code an intelligent system for diagnosis breast cancer. There are no special requirements, you have free range to do so, as this is a learning experience. Be sure to use block comments and it would be beneficial to provide explanation. Thanks

In: Computer Science

Cplusplus Task: You are to write a class called Monomial, using filenames monomial.h and monomial.cpp, that...

Cplusplus

Task: You are to write a class called Monomial, using filenames monomial.h and monomial.cpp, that will allow creation and handling of univariate monomials, as described below.

Monomial Description

Each monomial object has following properties:

  • Each monomial has a coefficient and a power.
  • Monomial power is always positive.
  • Monomial power is always integer.
  • Monomials cannot be added if they have different powers

Class Details

  1. The single constructor for the Monomial class should have 2 parameters: an floating point coefficient value (optional, with a default value of 1.0); and an integer power value (optional, with a default value of 1). If the power value is less then 1, set the power to 1. The class will need to provide internal storage for any member data that must be kept track of.

  2. There should be member functions GetCoefficient, and GetPower, which will return the monomial’s coefficient value, and monomial’s power value, respectively. The GetPower method should return integer results. The GetCoefficient function should return its result as a float.

  3. There should be member functions SetPower, which will set the monomial’s power to the arbitrary positive value. If the parameter is not positive then set the power to the default value 1.

  4. There should be member function Add, which adds the one monomial to the other. The parameter of this member function need to be a constant reference to the other monomial object. The monomials can only be added if they have the same power, otherwise error message must be printed. The result of the addition is saved in the caller object.

  5. There should be two member functions Multiply (overrides), which each allow to multiply a monomial to a number and to another monomial. The first member function need to accept floating point parameter that is used to perform multiplication of the real number on the the monomial object. The second member function need to accept a constant reference to the other monomial object. Use monomials to coefficients and powers to perform their multiplication. The result of the multiplication is saved in the caller object.

  6. There should be a member function called Exponent that perform exponentiation (raise to power) of the monomial to the specified power value. You only can raise monomial to the positive power, if the power parameter is not positive print error message. The result of the exponentiation is saved in the caller object.

  7. A sample driver program (called monomial-driver.cpp) is provided. It uses objects of type Monomial and illustrates sample usage of the member functions.

  8. Your class declaration and definition files must work with my main program from the test driver, as-is (do not change my program to make your code work!). You are encouraged to write your own driver routines to further test the functionality of your class, as well. Most questions about the required behavior of the class can be determined by carefully examining my driver program and the sample execution. Keep in mind, this is just a sample. Your class must meet the requirements listed above in the specification - not just satisfy this driver program. (For instance, I haven’t tested every illegal fill character in this driver program - I’ve just shown a sample). Your class will be tested with a larger set of calls than this driver program represents.

General Requirements

  • No global variables, other than constants!
  • All member data of your class must be private
  • You can only use the <iostream> library for output. !!! No other libraries are allowed !!!.
  • When you write source code, it should be readable and well-documented.
  • Here are some general notes on style guidelines
  • Your monomial.h file should contain the class declaration only. The monomial.cpp file should contain the member function definitions.

Test Driver:

//
// driver.cpp -- driver program to demonstrate the behavior of
//               the Monomial class

#include <iostream>
#include "monomial.h"

using namespace std;

int main()
{
    // create some monomial: x, 2x, 12.5x³, -3xâ¶
    Monomial m1, m2( 2.0 ), m3( 12.5, -1 ), m4( -3.0 , 6);
    // display monomial
    cout << "Monomial `m1` has the coefficient " << m1.GetCoefficient()
         << " and power " << m1.GetPower() << ": ";
    m1.Print();
    cout << "Monomial `m2` has the coefficient " << m2.GetCoefficient()
         << " and power " << m2.GetPower() << ": ";
    m2.Print();
    cout << "Monomial `m3` has the coefficient " << m3.GetCoefficient()
         << " and power " << m3.GetPower() << ": ";
    m3.Print();
    cout << "Monomial `m4` has the coefficient " << m4.GetCoefficient()
         << " and power " << m4.GetPower() << ": ";
    m4.Print();

    // Change monomial power
    cout << "Monomial `m3` power wasn't changed: ";
    m3.SetPower(-1);
    m3.Print();
    cout << "Monomial `m3` power was changed: ";
    m3.SetPower(3);
    m3.Print();

    // can add monomials with the same powers
    cout << "Monomial addition" << endl;
    m1.Add(m2);
    cout << "x + 2x = ";
    m1.Print();
    // cannot add monomials with different powers
    cout << "x³ + 12.5x³ = ";
    m2.Add(m3);

    // can multiply monomial to a number
    cout << "Monomial multiplication by a number" << endl;
    m2.Multiply(2.5);
    cout << "2x * 2.5 = ";
    m2.Print();

    // can multiply monomials
    cout << "Monomial multiplication by a monomial" << endl;
    m3.Multiply(m4);
    cout << "12.5x³ * -3xⶠ= ";
    m3.Print();

    // can raise monomial to the power
    cout << "Monomial exponentiation" << endl;
    m4.Exponent(3);
    cout << "(-3xâ¶)³ = "; // -27x^18
    m4.Print();
    cout << "(3x)â° = "; // -27x^18
    m1.Exponent(-10);

    return 0;
}

Test Driver Output

Monomial `m1` has the coefficient 1 and power 1: 1x^1
Monomial `m2` has the coefficient 2 and power 1: 2x^1
Monomial `m3` has the coefficient 12.5 and power 1: 12.5x^1
Monomial `m4` has the coefficient -3 and power 6: -3x^6
Monomial `m3` power wasn't changed: 12.5x^1
Monomial `m3` power was changed: 12.5x^3
Monomial addition
x + 2x = 3x^1
x³ + 12.5x³ = Cannot add monomials with different powers
Monomial multiplication by a number
2x * 2.5 = 5x^1
Monomial multiplication by a monomial
12.5x³ * -3x⁶ = -37.5x^9
Monomial exponentiation
(-3x⁶)³ = -27x^18
(3x)⁰ = Can raise only to a positive power

In: Computer Science

C++ ONLY Binary Search and Selection Sort A binary search first requires a sort. Use a...

C++ ONLY Binary Search and Selection Sort

A binary search first requires a sort.

Use a selection sort to organize an array, then find the value using a binary search.

Input the array, and a value to find.

Output the sorted array and the value if contained in the array.

/*
* File: main.cpp
* Author:
* Created on:
* Purpose: Binary Search
*/

//System Libraries
#include <iostream> //Input/Output Library
#include <cstdlib> //Random Functions
#include <ctime> //Time Library
using namespace std;

//User Libraries

//Global Constants, no Global Variables are allowed
//Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...

//Function Prototypes
void fillAry(int [],int);
void prntAry(int [],int,int);
void selSrt(int [],int);
bool binSrch(int [],int,int,int&);

//Execution Begins Here!
int main(int argc, char** argv) {
//Set the random number seed
srand(static_cast<unsigned int>(time(0)));
  
//Declare Variables
const int SIZE=100;
int array[SIZE];
int indx,val;
  
//Initialize or input i.e. set variable values
fillAry(array,SIZE);

//Sorted List
selSrt(array,SIZE);
  
//Display the outputs
prntAry(array,SIZE,10);
cout<<"Input the value to find in the array"<<endl;
cin>>val;
if(binSrch(array,SIZE,val,indx))
cout<<val<<" was found at indx = "<<indx<<endl;

//Exit stage right or left!
return 0;
}

In: Computer Science

Java Question I have a Queue containing String type taking in a text file with an...

Java Question

I have a Queue containing String type taking in a text file with an iterator.

I need to use ArrayList and HashMap for freqHowMany to get a frequency table in descending order by the highest frequency words in the text. Any help would be much appreciated and thanks!

final Iterator input = new Scanner(System.in).useDelimiter("(?U)[^\\p{Alpha}0-9']+");
        final Queue queueFinal = new CircularFifoQueue<>(wordsLast);

        while (input.hasNext()) {
            final String queueWord = input.next();
            if (queueWord.length() > minimumLength) {
                queueFinal.add(queueWord); // the oldest item automatically gets evicted
            }

            System.out.println(queueFinal);
        }
    }
}

EXAMPLE:

Your program prints an updated word cloud for each sufficiently long word read from the standard input.

The program takes up to three positive command-line arguments:

  • freqHowMany indicates the size of the word cloud, i.e., the number of words in descending order of frequency to be shown
  • wordMinLength indicates the minimum length of a word to be considered; shorter words are ignored
  • wordLastNwords indicates the size of a moving window of n most recent words of sufficient length for which to update the word cloud

Your program then reads a continuous stream of words, separated by whitespace or other non-word characters, from the standard input. (A word can have letters, numbers, or single quotes.) For each word read, your program prints to standard output, on a single line, a textual representation of the word cloud of the form

The idea is to connect this tool to a streaming data source, such as Twitter, or speech-to-text from a 24-hour news channel, and be able to tell from the word cloud in real time what the current "hot" topics are.

THANKS!

In: Computer Science