Questions
search the file "myfile.txt" for any occurrences of "Some target string" and print the lines where...

search the file "myfile.txt" for any occurrences of "Some target string" and print the lines where the string is found.

In this assignment, write your own java version of this program:

  1. Name the program LastnameFirstname1 (this is not really an appropriate name for such a program, but following this convention greatly eases the grading process). Example: WhiteMax1
  2. Allow the user to specify the string they are searching for and the file they wish to search with command line arguments. To replicate the above findstr and grep examples, the program would be executed with the following command: java WhiteMax1 "Some target string" myfile.txt  (for help using command line arguments, see this article).
  3. Search each line of the file for the target string. For every occurrence found, first print out the line number where it has been found, the index of the target string's start position in that line, and the entire line itself. For example, searching line 5, "My dog is a good boy" for the target string "dog" would print: 5:3 My dog is a good boy   (If no occurrences are found, nothing needs to be printed. If multiple occurrences are found in the same line, print the line multiple times with each index position. File line numbers start at 1, not 0)

To complete this assignment you will need to use Scanner, File, and String. Consider reviewing the documentation for these classes. The attached file is provided as an example text file for developing and testing your program.

In: Computer Science

Describe two debugging techniques that are used for C programs. Which of these techniques do you...

Describe two debugging techniques that are used for C programs. Which of these techniques do you use most often and why do you use it rather than another technique? Why do you find this technique works better than the other technique?

i need help with this question

In: Computer Science

Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you...

Assignment 1: JAVA Classes, Objects, and Constructors

The goal of this assignment is to get you familiar with some of the most used JAVA syntax, as well as constructors objects, objects calling other objects, class and instance attributes and methods. You will create a small program consisting of Musician and Song classes, then you will have Musicians perform the Songs.

Included is a file “Assignment1Tester.java”. Once you have done the assignment and followed all instructions, you should be able to compile and run “Assignment1Tester.java”. If “Assignment1Tester.java” compiles and runs, this does not mean your code is correct. But it will make sure that your public facing interface and member variables have the correct specification.

Make certain all member variables and methods are exactly as requested. We may use automated marking, and if we do and you spell a member variable differently, you will not get the mark. That is why we highly encourage you to compile and run “Assignment1Tester.java”. It will check some of these things for you.

Every question is worth 5 marks.

1. Open the file “Musician.java”. There is a “static final” variable defaultNumberOfKnownSongs that has been initialized to 3. In the Musician class, we will add 3 more instance variables. The first should be called name and should be of typeString. The second should be called knownSongs and it should be an array of type Song. The third should be an int callednumKnownSongs.

2. Write a constructor that takes two arguments, “String name” and “int numberOfSongs”. Have this constructor initializeknownSongs to an array of Song with length numberOfSongs, and initialize the name instance variable to the name String that was passed in through the constructor. You should make use of the this keyword. Write a second constructor for theMusician class with a single argument “String name” that initializes knownSongs to an array of Song with lengthdefaultNumberOfKnownSongs. In both constructors initialize numKnownSongs to zero.

3. Write a public String toString(). If the name = “Slash” and he knows 2 songs, it should return a String “My name is Slash and I know 2 songs.”

4. Open the class “Song.java”. Write three constructors. Write a no-argument constructor that assigns the name “unknown” to the song name and “pop” to genre. Write a constructor that takes a String argument and assigns it to name, and assigns “pop” to genre. Write a constructor that takes two String arguments, the first of which is assigned to name and the second is assigned to genre. Make sure that “name” comes first in the constructor method signature.

5. Write a static method “randomSong()” that returns a Song object with a random name from the songNames array and a random genre from the songGenre array.

6. Write a method “public String toString()” that returns a String object describing the Song. That is, if name = “Paradise City” and genre = “hard rock”, then “public String toString()” should return the String “the hard rock song ‘Paradise City’.”

7. Write a method “equals(Song song)” in the Song class that compares the current Song object to the song variable. It returns true if the two songs have the same name and same genre, and false otherwise.

8. In the Musician class, write a method “public boolean learnSong(Song song)”. It should assign the song argument to the first open position in the knownSongs array. If the array is full it should not change the array and return false. If the array is not full, add the song and return true.

9. In the Musician class, write a method “public boolean playSong(Song song)”. If the song argument is equal to a song in the knownSongs array, then the method should output the Musicians name followed by “performs” followed by the song. For instance, if the Musician is named “Slash” and the song was ‘Paradise City’, it would print “Slash performs the hard rock song ‘Paradise City’.” to the screen and return true. Hint: you can make use of the toString() method of the Song class. If the Song argument is not equal to any Song in the knownSongs array, then this method should print “Slash does not know the hard rock song ‘Paradise City’.” and return false.

10. In the Musician class, write a method “public void playAllKnownSongs()”. This method should play every song in the knownSong array with each song formatted as in Question 9.

In: Computer Science

Please write this code in C++, also if you could please bold the names of the...

Please write this code in C++, also if you could please bold the names of the input files and provide comments for each choice.

For this part, the program gives the user 4 choices for encrypting (or decrypting) the first character of a file. Non-lowercase characters are simply echoed. The encryption is only performed on lowercase characters.

  • If c is char variable, then islower(c) will return true if c contains an lowercase character, false otherwise
  • To read a single character from a file (let inFile be the name of your ifstream), you can use: inFile.get(c);
    • This will read one character, even the whitespace characters
  • Choice 1 – No encryption, echo the character from the file
  • Choice 2 – Encrypt by shifting. For example, shifting by 3 characters would change an ‘a’ to a ‘d’ because that is 3 letters later. If you reach the end of the alphabet then you need to roll over. For example ‘z’ plus 3 is ‘c’.
    • NOTE: The process of converting the ‘z’ to a ‘c’ should NOT need the use of an if, switch, or loop statement.
    • For this week, you may use an if or switch if you need, but next week you’ll have to do it without
  • Choice 3 – This is the opposite of choice 2. Instead of moving 3 letters forward, it will move 3 letters backwards. A ‘d’ will become ‘a’.
    • Like choice 2, the shifting can be accomplished without if’s, switch’s, and loop’s.
  • Choice 4 – This will calculate a hash value. You sum the ASCII values of all of the characters and at the end of the file print the last 2 digits of the sum. For example, “abc” is 94 because ‘a’ is 97, ‘b’ is 98, ‘c’ is 99, which has a sum of 294.
    • Remember, this week we are only reading a single character
  • Your program should prompt the user for:
    • The encryption type
    • The name of a file
    • For this week, the prompt will be very short, just a ?
  • Your program should output the encrypted characters (or a hash value).

This is the input files named file1.txt and file2.txt

  • file1.txt has the following contents:
yippee
  • file2.txt has the following contents:
A-bba cc
xyyz

This is what the user is typing it's in bold, and the output is under it.

Sample Run #1 (bold, underlined text is what the user types):

? 1 file1.txt

y

Sample Run #2 (bold, underlined text is what the user types):

? 2 file1.txt

b

Sample Run #3 (bold, underlined text is what the user types):

? 3 file1.txt

v

Sample Run #4 (bold, underlined text is what the user types):

? 4 file1.txt

21

Sample Run #5 (bold, underlined text is what the user types):

? 1 file2.txt

A

Sample Run #6 (bold, underlined text is what the user types):

? 2 file2.txt

A

Sample Run #7 (bold, underlined text is what the user types):

? 4 file2.txt

0

In: Computer Science

What do the following terms mean in the context of software development? a. Portability b. Interoperability...

What do the following terms mean in the context of software development?

a. Portability b. Interoperability c. Maintainability d. Robustness

In: Computer Science

write a c# program that: The file is using a very simple form of compression in...

write a c# program that:

The file is using a very simple form of compression in which there are no spaces, each word is separated by camel casing. For Example, the string "TheCatWillRun" is parsed as "The Cat Will Run".

*Now for the statistics*

Prints to the console the following statistics about the content in the file retrieved above.

- How many of each letter are in the file
- How many letters are capitalized in the file
- The most common word and the number of times it has been seen.
- The most common 2 character prefix and the number of occurrences in the text file.

In: Computer Science

1. Create a flow chart from the algorithm then create python code. Algorithm: Tell the user...

1. Create a flow chart from the algorithm then create python code.

Algorithm: Tell the user to enter their name, how many cars the user has, and the average number of cars per family in the users state. Create a variable to show the difference between the users number of cars and the average number of cars per family. Print the values of name, number of cars, average number of cars, and the difference in 2 decimal places.

In: Computer Science

java CLASS DESIGN GUIDELINES 1. Cohesion • [✓] A class should describe a single entity, and...

java

CLASS DESIGN GUIDELINES

1. Cohesion • [✓] A class should describe a single entity, and all the class operations should logically fit together to support a coherent purpose. • [✓] A single entity with many responsibilities can be broken into several classes to separate the responsibilities.

2. Consistency • [✓] Follow standard Java programming style and naming conventions. Choose informative names for classes, data fields, and methods. A popular style is to place the data declaration before the constructor and place constructors before methods. • [✓] Make the names consistent. It is not a good practice to choose different names for similar operations. • [✓] In general, you should consistently provide a public no-arg constructor for constructing a default instance. If a class does not support a no-arg constructor, document the reason. If no constructors are defined explicitly, a public default no-arg constructor with an empty body is assumed. • [✓] If you want to prevent users from creating an object for a class, you can declare a private constructor in the class, as is the case for the Math class.

3. Encapsulation • [✓] A class should use the private modifier to hide its data from direct access by clients. This makes the class easy to maintain. • [✓] Provide a getter method only if you want the data field to be readable, and provide a setter method only if you want the data field to be updateable.

4. Clarity • [✓] Cohesion, consistency, and encapsulation are good guidelines for achieving design clarity. Additionally, a class should have a clear contract that is easy to explain and easy to understand. • [✓] Users can incorporate classes in many different combinations, orders, and environments. Therefore, you should design a class that imposes no restrictions on how or when the user can use it, design the properties in a way that lets the user set them in any order and with any combination of values, and design methods that function independently of their order of occurrence. • [✓] Methods should be defined intuitively without causing confusion. • [✓] You should not declare a data field that can be derived from other data fields.

5. Completeness • [✓] Classes are designed for use by many different customers. In order to be useful in a wide range of applications, a class should provide a variety of ways for customization through properties and methods.

6. Instance vs. Static • [✓] A variable or method that is dependent on a specific instance of the class must be an instance variable or method. A variable that is shared by all the instances of a class should be declared static. • [✓] Always reference static variables and methods from a class name (rather than a reference variable) to improve readability and avoid errors. • [✓] Do not pass a parameter from a constructor to initialize a static data field. It is better to use a setter method to change the static data field. • [✓] Instance and static are integral parts of object-oriented programming. A data field or method is either instance or static. Do not mistakenly overlook static data fields or methods. It is a common design error to define an instance method should have been static. • [✓] A constructor is always instance, because it is used to create a specific instance. A static variable or method can be invoked from an instance method, but an instance variable or method cannot be invoked from a static method.

7. Inheritance vs. Aggregation • [✓] The difference between inheritance and aggregation is the difference between an is-a and a has-a relationship.

8. Interfaces vs. Abstract Classes • [✓] Both interfaces and abstract classes can be used to specify common behavior for objects. How do you decide whether to use an interface or a class? In general, a strong is-a relationship that clearly describes a parentchild relationship should be modeled using classes. A weak is-a relationship, also known as an is-kind-of relationship, indicates that an object possesses a certain property. A weak is-a relationship can modeled using interfaces. • [✓] Interfaces are more flexible than abstract classes, because a subclass can extend only one superclass but can implement any number of interfaces. However, interfaces cannot contain concrete methods. The virtues of interfaces and abstract classes can be combined by creating an interface with an abstract class that implement it. Then you can use the interface or the abstract class, whichever is convenient.

Please choose 5 guidelines and discuss them in depth. For each guideline, use at least half a page for your discussion.

In: Computer Science

JAVA: Lab11C:Behaviors.In the context of OOP, functions are called methods or behaviors because they typically do...

JAVA: Lab11C:Behaviors.In the context of OOP, functions are called methods or behaviors because they typically do something. Most often, they read or change the values of one or more variables in the class. For example, you may have a weight variable in a class, and a method called gainWeight( ) that increases the weight variable by a certain amount.

For this part of the lab, create class KoalaBear that has a weightattribute(in kilograms). Create a constructor for the class that takes in (as a parameter) the initial weight of the koala bear. Then, write a function called eat( ) that takes in the number of leaves the koala bear should eat. Each leaf weighs one gram, so you must increase the weight of the koala bear by one gram. According to a site dedicated to saving Koala bears, they can eat between 200-500 grams of leaves per day. To finish the class out, include a showWeight() method that prints out how much the koala weighs.

In main, create a koala object starting at 100 kilos and show the koala’s weight. Then, make the koala eat 400, 300, and 650 leaves, showing the weight of the koala after each time it eats.

NOTE: if you’re output does not match exactly (because of the rounding of floating point math), that’s OK. For example, Java will include some extra “precision”.

Sample output #1

This koala weighs 100.4 kilos

This koala weighs 100.7 kilos

This koala weighs 101.35 kilos

In: Computer Science

Using Java please implement a 4x4 Tic-Tac-Toe with Minimax with alpha-beta pruning. Please comment code heavily...

Using Java please implement a 4x4 Tic-Tac-Toe with Minimax with alpha-beta pruning. Please comment code heavily so I can follow along and understand the steps. Also, inlcude a screenshot of the final output. Do not include code for GUI, a GUI is not needed. Thank you

In: Computer Science

C++ Create a recursive program what will test three recursive functions. It would have a menu...

C++

Create a recursive program what will test three recursive functions. It would have a menu like:

1. Recursive factorial

2. Towers of Hanoi

3. Recursive summation

0. Exit

Enter selection: 3

Enter number: 4

The recursive summation will take an integer and sum value from 1 to the integer. Don’t enter a number if the selection is 0 for quit. Please have the functions in an implementation file and the prototypes of the functions in a header file and the main in a separate file.

In: Computer Science

Java Question: Which of the following statements about the reference super is true? a) It must...

Java Question:

Which of the following statements about the reference super is true?

a)

It must be used every time a method from the superclass is called.

b)

It must be the last statement of the subclass constructor.

c)

It must be the first statement of the subclass constructor.

d)

It can only be used once in a program.

In: Computer Science

C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...

C# ( asp.net ) 2019 Visual Studio

I have a dropdown where you can select ( integer, string, date )

After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4

And then , I have a 'sort' button

Can you please help me with the code behind for sorting them( For integer, string, and date )

Thank you.

In: Computer Science

What countermeasures can be adopted to mitigate SYN flood attacks?

What countermeasures can be adopted to mitigate SYN flood attacks?

In: Computer Science

Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It...

Python Question

Using lists, write the function non_unique(list) that takes a list list as argument. It
returns a list which duplicated elements remains and each duplicated element is followed by
a number which shows how many times it appears. All elements in return list should be in
the same order as their appearance in the original list.
For example, given the input [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘d’, ‘a’,‘e’], the function
would return [‘a’, 3, ‘b’, 2]. Another example, ['abc', 'def', 'abc', 'xyz', 'def','def', 'qwe'] -> ['abc', 2, 'def', 3]


If no such non_unique list exist, just return an empty list.
Your program should contain the function with format shown as below:

def non_unique(list):
# Your codes here
return result # ‘result’ is a list.

In: Computer Science