Categories
Java

What is Generics? Why Generics? Show example of the Generic type and Generic Ins

What is Generics?
Why Generics?
Show example of the Generic type and Generic Instantiation.
A raw type is unsafe. Show an example of avoiding unsafe raw types.

Categories
Java

1) Find a real-world information problem that you argue demonstrates one of the

1) Find a real-world information problem that you argue demonstrates one of the common growth functions in the Algorithms materials. Explain how the problem demonstrates the function.
Think about how the number of required steps of work grows as the number of data elements to work on grows.
For example, a problem with linear complexity growth means that the work steps grow just as much as the number of data elements does, while a problem with a constant time complexity problem would not grow at all as the data elements grow. If my program must add up the sum of a set of ‘n’ integers, it will require processing every one of the ‘n’ integers, in the worst case (and average case and best case,here). Also, in terms of ‘n’, if ‘n’ grows by 1, my program’s work load also grows by 1, meaning that the work load of my program in terms of n grows just like a linear mathematical function does.
2) Is there a way to solve your problem recursively? If you argue there is, briefly explain an approach. If not, explain what prevents the use of recursion.
In fact, representing the problem well is key to realizing that it can be solved recursively. As I commented in a recent lecture, I can represent my task of scoring a set of assignments (very time-consuming) as :
1) Select the first assignment ‘a’ in set ‘S’. Score ‘a’
2) Score the rest of the set S
Notice that we can repeatedly replace “Score the rest of the set S” with

1) Select the first assignment ‘a’ in set ‘S’. Score ‘a’
2) Score the rest of the set S

until there are no assignments left in S.

Categories
Java

Data cleansing is an important part of data integrity. Part of data cleansing is

Data cleansing is an important part of data integrity. Part of data cleansing is properly formatting data. Phone numbers are notoriously inconsistent when it comes to data formatting, so you will do cleaning phone numbers.
Using java programming language, write a function that takes a phone number in the form of a string and returns the phone number as a cleansed string. You may assume that all phone numbers will be from the US and will contain an area code. The proper output is a 10-digit number (e.g. 2345678901).
Below are examples of possible input formats:
+1 (234) 567-8901
234.567.8901
(234) 567-8901
(234)567-8901
(234)567-8901
234 567-8901
1 (234) 567-8901
12345678901

Categories
Java

Animal, with the String attributes name and breed. 2. Cat and Dog are subclasses

Animal, with the String attributes name and breed.
2. Cat and Dog are subclasses of Animal.
3. AnimalI, an interface declaring two methods makeSound and whatAmI.
4. Each of the three classes will implement the interface, have a constructor and a getter. I suggest using the Generate option from the Code dropdown menu to generate these “boilerplate” methods. Also, the Animal class needs a toString method.
5. Finally, a Main class that will create a Scanner object to read a text file, containing three fields, separated by commas, type, name, and breed. Depending upon the type (A, C or D), create an Animal or Cat or Dog object and store it in an ArrayList of animals.
6. After all records have been read, iterate through the ArrayList to print the animal using the toString method.
7. Don’t forget to close the text file.