Objective Today we're discussing Generics; be aware that not all languages support this construct , so fewer languages are enabled for this challenge. Task Write a single generic function named printArray ; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector ). The locked Solution class in your editor tests your function. Note: You must use generics to solve this challenge. Do not write overloaded functions. Input Format The locked Solution class in your editor will pass different types of arrays to your printArray function. Constraints You must have exactly function named printArray . Output Format Your printArray function should print each element of its generic array parameter on a new line. Solution : import java.util.*; class Printer <T> { ...
Objective In this challenge, we're going to learn about the difference between a class and an instance ; because this is an Object Oriented concept, it's only enabled in certain languages. Check out the Tutorial tab for learning materials and an instructional video! Task Write a Person class with an instance variable, , and a constructor that takes an integer, , as a parameter. The constructor must assign to after confirming the argument passed as is not negative; if a negative argument is passed as , the constructor should set to and print Age is not valid, setting age to 0. . In addition, you must write the following instance methods: yearPasses() should increase the instance variable by . amIOld() should perform the following conditional actions: If , print You are young. . If and , ...
Objective Today, we're learning about Key-Value pair mappings using a Map or Dictionary data structure. Task Given names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each queried, print the associated entry from your phone book on a new line in the form name=phoneNumber ; if an entry for is not found, print Not found instead. Note: Your phone book should be a Dictionary/Map/HashMap data structure. Input Format The first line contains an integer, , denoting the number of entries in the phone book. Each of the subsequent lines describes an entry in the form of space-separated values on a single line. The first value is a friend's name, and the second value is an -digit phone number. After the lin...
Comments
Post a Comment