Sei sulla pagina 1di 21

Skilling Lesson Plan:

Topics Skilling problems

Introducing the course 1.) Write a java Program to swap two static numbers without using third
handout. variable.
1
2.) Write a java program to find maximum and minimum number from given
three static numbers using conditional operator.
Introducing
Object
3.) Write a java program to print the prime number in the given range.
oriented
programming

1.) Write a Class Circle with a static member radius and a static method to
calculate area and perimeter of a circle that has a radius of 3.7
2 Introduction to Java- 2.) Write a Class runner with a static member runs 14kms in 45 mins and 30
Writing a class, Static secs and display average speed in miles per hr.(Note that one mile is 1.6
block, variables and kms)
methods 3.) Write a class Student with static members as sno, m1, m2, m3 and a static
method to calculate total and average of the m1, m2, m3.

1.) Suppose you save $100 each month into a saving account the annual
interest rate 5% .Thus ,the monthly interest rate is 0.05/12=0.00417.After
3 the first month the value in the account becomes
Modularization and
access specifiers 100*(1+0.00417) = 100.417

After the second month the value in the account becomes

(100+100.417) *(1+0.00417) = 201.252 and so on.

Write a program that prompts the user to enter a monthly saving


amount and display the account value after 6 months.

2.) Write a program that reads three edges for a triangle and computes the
perimeter if the input is valid otherwise display the input is invalid. The
input is valid if the sum of every pair of two edges greater than remaining
edge.

3.) Write a program to return TRUE if the year is leap year else return FALSE
using static method.

1.) Modularize sum of n numbers using static variable, static method and
static block and calling a method within the same class.
4 Modularization – 2.) Modularize the following problem to class level .Write a Java Code to
class and package
display the speed of bike if speed is greater than or equal to 60 then
level
indicate as over speed, if speed is in between 40 to 60 th6en indicate
average speed otherwise safe drive.
3.) Modularize the following problem to package level .Write a java code to
take an integer n( hard code) and check whether n is divisible by both 3
and 7or by neither of them or by just one of them.

1 Write a java program to will calculate the circumference, area of the circle
using the getter and setter method
5 Creating objects
and accessing www.w3schools.com
members
through object 2 Write a java program, by defining only the setter method to set the values
of the variable

www.w3schools.com

1 Write a java program, by defining only the setter method to implement


Command line Encapsulation
arguments, Console www.w3schools.com
Input through Scanner 2 Write a java program, to print the data using toString() method
class Output:101 Ram lucknow
6
102 Lakshman ghaziabad
https://www.javatpoint.com/understanding-toString()-method

1. toString():

7 Accessor and Mutator https://www.hackerrank.com/challenges/java-int-to-string/problem


methods and toString()
method 2. get() and set methods:

Create a class named Petrol Purchase to represent information about the petrol
you purchase. The class should have five instance variables-the station’s
location(type String),the type of petrol(type String), the quantity(type int), the
price per liter(double),the percentage discount(double). Provide a get() and
set() method for instance variables. In addition, provide a method named
getPurchase() that calculates the net purchase amount.(ref…How To
Program-Tenth Edition…………PAUL DEITEL)

3. Create a class named Date that includes three instance variables-a


model(type String), a year(type String), and a price(double).Provide a set()
and get() method for instance variables. Provide a method displayDate() that
displays the month, day and year forwarded by slashes. . (ref…How To
Program-Tenth Edition…………PAUL DEITEL)

4. Create a class named Mytriangle contains three instance variables-side1


(type int), side2(type int), side3(type int). Write getter() and setter() methods
for instance variables. Create two methods named isValid() and area() .First
one checks the input is valid or not. If the input is not valid display as invalid.
Second method computes area if the input is valid.(Intro to JAVA
programming…Y.DANIEL LIANG)
1. Crate a class MethodOverload which includes two overload versions of
method area() .one that calculates the area of circle by taking radius as an
8 Method overloading argument and another which computes the area of square.
and array of references
( ref…How To Program-Tenth Edition…………PAUL DEITEL)

2. Create a class named 'PrintNumber' to print various numbers of different


datatypes by creating different methods with the same name 'printn' having a
parameter for each datatype.

3. Create a class to print the area of a square and a rectangle. The class has
two methods with the same name but different number of parameters. The
method for printing area of rectangle has two parameters which are length and
breadth respectively while the other method for printing area of square has
one parameter which is side of square.(The Complete reference)

8. Create an array of object references to a class BankDetails. The class has


one method accDetails() which takes account number as input and prints all
details of a customers.

Java End-of-file

9
Handling I/O – Files,
1) In computing, End Of File (commonly abbreviated EOF) is a
GUI
condition in a computer operating system where no more data can be
read from a data source."
The challenge here is to read lines of input until you reach EOF, then
number and print all lines of content.
Hint: Java's Scanner.hasNext () method is helpful for this problem.

Input Format

Read some unknown n lines of input from stdin (System.in) until you
reach EOF; each line of input contains a non-empty String.

Output Format

For each line, print the line number, followed by a single space, and
then the line content received as input.

Sample Input
Hello world
I am a file
Read me until end-of-file.
Sample Output
1 Hello world
2 I am a file
3 Read me until end-of-file.
Reference link:
https://www.hackerrank.com/challenges/java-end-of-
file/problem?h_r=internal-search

3. Develop a JFrame that has text area field which accepts lines of text from
the user and button count words. Now write a java program to return number
of characters and words in the inputted text.

2. Develop a JFrame with title of frame as my login window and size of


frame as (400,600)to create a user login page which contains 2 inputs name
and password, along with submit and cancel button.

Reference Link: https://www.programming9.com/programs/java/43-java-


program-to-design-login-window-using-awt-controls-button-label-textfield

1. Write a program that creates an employee class with empid, name, salary as
its members. Create constructors to give initial values to class members and
Constructors- types and include garbage collectors to destroy the objects created.
10
this keyword
2. Develop a java program to create a Class Vehicle with wheels and color as
it member. Now create parameterized and no parameterized constructors that
assign values to Vehicle class members with appropriate display messages.
Also define corresponding destructors

Constructor 1. The Employee class contains


11
public String empName;
overloading and
public int empSalary;
Constructor chaining
public String address;
publicEmployee(){//Write the code}
publicEmployee(String name) (){//Write the code}
publicEmployee(String name,int sal) (){//Write the code}
publicEmployee(String name,int sal,String addr) (){//Write the
code}
void disp()(){//Write the code}
to create object of Employee class and display the details of employee.
Here use only default constructor of the class and use the this keyword
to call remaining all constructor.

https://beginnersbook.com/2013/12/java-constructor-chaining-with-
example/

2. Create a class named 'Rectangle' with two data members- length


and breadth and a method to claculate the area which is
'length*breadth'. The class has three constructors which are :

a - having no parameter - values of both length and breadth are


assigned zero.

b - having two numbers as parameters - the two numbers are


assigned as length and breadth respectively.
c - having one number as parameter - both length and breadth are
assigned that number.
Now, create objects of the 'Rectangle' class having none, one and
two parameters and print their areas.

3. Suppose you have a Piggie Bank with an initial amount of $50 and
you have to add some more amount to it. Create a class 'AddAmount'
with a data member named 'amount' with an initial value of $50. Now
make two constructors of this class as follows:
A- without any parameter - no amount will be added to the Piggie Bank
B- having a parameter which is the amount that will be added to Piggie
Bank
Create object of the 'AddAmount' class and display the final amount in
Piggie Bank.
12 Object as argument and 1. Create a class named 'Programming'. While creating an object of the
return value. Call by
value vs Call by class, if nothing is passed to it, then the message "I love programming
reference languages" should be printed. If some String is passed to it, then in
place of "programming languages" the name of that String variable
should be printed.For example, while creating object if we pass "Java",
then "I love Java" should be printed.

2. Create a class 'Student' with three data members which are name,
age and address. The constructor of the class assigns default values
name as "unknown", age as '0' and address as "not available". It has
two members with the same name 'setInfo'. First method has two
parameters for name and age and assigns the same whereas the second
method takes has three parameters which are assigned to name, age
and address respectively. Print the name, age and address of 10
students.

Usage of nested and inner classes. MCQ’s in

13 https://www.w3schools.com/java/java_inner_classes.asp
Nested and inner
classes

14 String Class and Practice all the methods in String class


methods
https://www.w3schools.com/java/java_strings.asp

15 String Buffer and doubleChar https://codingbat.com/prob/p165312


String Tokenizer . countHi https://codingbat.com/prob/p147448
catDog https://codingbat.com/prob/p111624
countCode https://codingbat.com/prob/p123614
endOther https://codingbat.com/prob/p126880
xyzThere https://codingbat.com/prob/p136594
bobThere https://codingbat.com/prob/p175762
xyBalance https://codingbat.com/prob/p134250
mixString https://codingbat.com/prob/p125185
repeatEnd https://codingbat.com/prob/p152339
repeatFront https://codingbat.com/prob/p128796
repeatSeparator https://codingbat.com/prob/p109637
prefixAgain https://codingbat.com/prob/p136417
xyzMiddle https://codingbat.com/prob/p159772
getSandwich https://codingbat.com/prob/p129952
sameStarChar https://codingbat.com/prob/p194491
oneTwo https://codingbat.com/prob/p122943
zipZap https://codingbat.com/prob/p180759
starOut https://codingbat.com/prob/p139564
plusOut https://codingbat.com/prob/p170829
wordEnds https://codingbat.com/prob/p147538
countYZ https://codingbat.com/prob/p199171
withoutString https://codingbat.com/prob/p192570
equalIsNot https://codingbat.com/prob/p141736
gHappy https://codingbat.com/prob/p198664
countTriple https://codingbat.com/prob/p195714
sumDigits https://codingbat.com/prob/p197890
sameEnds https://codingbat.com/prob/p131516
mirrorEnds https://codingbat.com/prob/p139411
maxBlock https://codingbat.com/prob/p179479
sumNumbers https://codingbat.com/prob/p121193
notReplace https://codingbat.com/prob/p154137
Java Date and Time https://www.hackerrank.com/challenges
/java-date-and-time/problem
16
References as members Write a Java program to https://www.w3resource.com/java-
create a Date object using exercises/datetime/index.php
the Calendar class.
Write a Java program to https://www.w3resource.com/java-
get and display exercises/datetime/index.php
information (year, month,
day, hour, minute) of a
default calendar.
Write a Java program to https://www.w3resource.com/java-
display the date time exercises/datetime/index.php
information before some
hours and minutes from
current date time.
Write a Java program to https://www.w3resource.com/java-
define a period of time exercises/datetime/index.php
using date-based values
(Period) and a duration of
time using time-based
values (Duration).
Write a Java program to https://www.w3resource.com/java-
define and extract zone exercises/datetime/index.php
offsets.
Write a Java program to https://www.w3resource.com/java-
display all the available exercises/datetime/index.php
time zones with UTC and
GMT.
17 Menu driven programs 1. Create an java program using switch-case that would let the users
for applications place their order. after order is placed, menu would re-appear to let
user place order again (if they want to) Also provide option to exit
from the menu application to user.
2. Write a java program to print series 0, 3, 8, 15, 24 and
s=1/2+3/4+5/6+..+19/20 with help of Menu using switch case
statement.

1 Create Vehicle Interface with name, maxPassanger, and maxSpeed


variables. Create Land Vehicle and Sea Vehicle Inteface from Vehicle
18 interface. Land Vehicle has numWheels variable and drive method. Sea
Inheritance – Types
Vehicle has displacement variable and launch method. Create Car class from
Land Vehicle, Hovercraft from Land Vehicle and Sea Vehicle interface. Also
create Ship from Sea Vehicle. Provide additional methods in Hovercraft as
enter Land and enter Sea. Similarly provide other methods for class Car and
Ship. Demonstrate all classes in a application.

2 Method Resolution order

https://www.codechef.com/problems/MRO

1 Protected specifier

19 REF: Java The Complete Reference, Seventh Edition162 pageno


Member access –
protected keyword
Write a java program student class where name,id,mail is protected specifier
in mypack1 package and create driver class which contains main()(ex
“demopro” class) in mypack2 package which extend the student class ,try to
access the member variables of student.

2 Protected method

https://www.geeksforgeeks.org/access-modifiers-java/

write a java program which Create two packages p1 and p2. Class A in p1 is
made public, to access it in p2. The method display in class A is protected
and class B is inherited from class A then access the method. protected void
display()

1 Java Method Overriding

20 Method overriding and https://www.hackerrank.com/challenges/java-method-overriding/problem


dynamic method
dispatch When a subclass inherits from a superclass, it also inherits its methods;
however, it can also override the superclass methods (as well as declare and
implement new ones). Consider the following Sports class:

class Sports{

String getName(){
return "Generic Sports";

void getNumberOfTeamMembers(){

System.out.println( "Each team has n players in " + getName() );

Next, we create a Soccer class that inherits from the Sports class. We can
override the getName method and return a different, subclass-specific string:

class Soccer extends Sports{

@Override

String getName(){

return "Soccer Class";

Note: When overriding a method, you should precede it with the @Override
annotation. The parameter(s) and return type of an overridden method must
be exactly the same as those of the method inherited from the supertype.

Task
Complete the code in your editor by writing an overridden
getNumberOfTeamMembers method that prints the same statement as the
superclass' getNumberOfTeamMembers method, except that it replaces with
(the number of players on a Soccer team).

Output Format

When executed, your completed code should print the following:

Generic Sports

Each team has n players in Generic Sports

Soccer Class

Each team has 11 players in Soccer Class

2 Java Method Overriding 2 (Super Keyword)

https://www.hackerrank.com/challenges/java-method-overriding-2-
super-keyword/problem
When a method in a subclass overrides a method in superclass, it is still
possible to call the overridden method using super keyword. If you write
super.func() to call the function func(), it will call the method that was
defined in the superclass.
You are given a partially completed code in the editor. Modify the code so
that the code prints the following text:
Hello I am a motorcycle, I am a cycle with an engine.

My ancestor is a cycle who is a vehicle with pedals.

3) Super keyword
Write an employee class Janitor to accompany the other employees. Janitors
work twice as many hours (80 hours/week), they make $30,000 ($10,000 less
than others), they get half as much vacation (only 5 days), and they have an
additional method named clean that prints "Workin' for the man."
Note: Use the super keyword to interact with the Employee superclass as
appropriate.
REF: https://courses.cs.washington.edu/courses/cse142/12su/labs/lab9-
inheritance.shtml#slide15

4 Bank Interest

https://www.javatpoint.com/method-overriding-in-java

Consider a scenario where Bank is a class that provides functionality


to get the rate of interest. However, the rate of interest varies
according to banks. For example, SBI, ICICI and AXIS banks could
provide 8%, 7%, and 9% rate of interest.

5 Dynamic Method Dispatch

https://www.geeksforgeeks.org/dynamic-method-dispatch-runtime-polymorphism-java/
A Java program to illustrate Dynamic Method
// Dispatch using hierarchical inheritance
Given class are A,B,C ,dispatch
Write the code for dispatch class show Dynamic Method Dispatch.
Class A
{
Void m1()
{
System.out.println("Inside A's m1 method");
}
}
classB extendsA
{
// overriding m1()
Void m1()
{
System.out.println("Inside B's m1 method");
}
}

classC extendsA
{
// overriding m1()
Void m1()
{
System.out.println("Inside C's m1 method");
}
}
// Driver class
Class Dispatch
{
publicstaticvoidmain(String args[])
{
…………
……
Write the code for Dynamic dispatch which access all M1()methods using
super class.

1 Super Keyword

21 Super class variable Demonstrate a java program where we want to call parent class method. So
whenever a parent and child class have same named methods then to
referring sub class
resolve ambiguity. use super keyword
object
https://www.geeksforgeeks.org/multithreading-in-java/

2 Write the necessary classes with given member data and appropriate
methods by identifying the inherited properties from person class to patient
class and display all the details of patient.

Hint: use super keyword

3 Write a java program to implement the below design?

Hint: use super keyword


1. Create a class named 'Shape' with a method to print "This is This is
final keyword – with
shape". Then create two other classes named 'Rectangle', 'Circle'
22 methods and classes, inheriting the Shape class, both having a method to print "This is
Object class rectangular shape" and "This is circular shape" respectively. Create a
subclass 'Square' of 'Rectangle' having a method to print "Square is a
usage of super
rectangle". Now call the method of 'Shape' and 'Rectangle' class by
the object of 'Square' class.
2. Write a program to calculate the average height of all the students of
a class. The number of students and their heights in a class are
entered by user.
3. Write a program to print the name, salary and date of joining of 10
employeesinacompany.Use array of objects.
4. Suppose you have a Piggie Bank with an initial amount of $50 and
you have to add some more amount to it. Create a class 'AddAmount'
with a data member named 'amount' with an initial value of $50.
Now make two constructors of this class as follows:
1 - without any parameter - no amount will be added to the Piggie
Bank
2 - having a parameter which is the amount that will be added to
Piggie Bank
Create object of the 'AddAmount' class and display the final amount
in Piggie Bank.
5. Create a class named 'Member' having the following members:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of
the members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class.
The 'Employee' and 'Manager' classes have data members
'specialization' and 'department' respectively. Now, assign name, age,
phone number, address and salary to an employee and a manager by
making an object of both of these classes and print the same.
6 Write a java program to implement below design
1.Create an abstract class 'Animals' with two abstract methods 'cats' and
'dogs'. Now create a class 'Cats' with a method 'cats' which prints "Cats
23 meow" and a class 'Dogs' with a method 'dogs' which prints "Dogs bark",
Abstract classes - 1
both inheriting the class 'Animals'. Now create an object for each of the
subclasses and call their respective methods.
Reference: https://www.codesdope.com/practice/java-abstract-class/

2. We have to calculate the percentage of marks obtained in three subjects


(each out of 100) by student A and in four subjects (each out of 100) by
student B. Create an abstract class 'Marks' with an abstract method
'getPercentage'. It is inherited by two other classes 'A' and 'B' each having a
method with the same name which returns the percentage of the students.
The constructor of student A takes the marks in three subjects as its
parameters and the marks in four subjects as its parameters for student B.
Create an object for each of the two classes and print the percentage of marks
for both the students. Reference: https://www.codesdope.com/practice/java-
abstract-class/

1.Write an abstract class Shape with the following


– Data members: numSides
24
Extending abstract – Constructor: initialize numSides
classes – Concrete method: get method for numSides
– Abstract methods: getArea(), getPerimeter()
Write a concrete subclass Rectangle with the following
– Data members: width, height
Write a concrete subclass RtTriangle with the following
– Data members: width, height
In another class, write a main method to define a Rectangle and a Triangle.
Reference: https://ocw.mit.edu/courses/civil-and-environmental-
engineering/1-00-introduction-to-computers-and-engineering-problem-
solving-spring-2012/recitations/MIT1_00S12_REC_6.pdf

2. Consider the following situation. A user would like to create a base class
that shouldn't be instantiated as a template for derived classes. S/he might
write something like
class Animal {
public age : number;
public yearsLeft() { return 20 - this.age; }
public makeSound() : string { return "???"; }
}
class Cow extends Animal {
makeSound() { return "Moo"; }
}
class Cat extends Animal {
makeSound() { return "Meow"; }
}
Today, the writer is forced to make a choice: either (i) Animal can be
declared an interface, but then yearsLeft cannot have an implementation, or
(ii) write the program as above, but then Animal can be instantiated and
makeSound has a bogus implementation! Neither of these options is
particularly attractive.
We propose abstract as a class declaration modifier to allow the programmer
control over whether a class can be instantiated, and as a member function
modifier to control whether said member function offers an implementation
(and whether the enclosing class is abstract).
Reference: https://github.com/microsoft/TypeScript/issues/3578

1) Access specifiers problem


25
Packages and Access
Control Create a 4 variables and access at different level

a) Same package sub class


b) Same package non sub class
c) Another package sub class
d) Another package non sub class.
https://www.javatpoint.com/access-modifiers

2) Private data and method access.

Write a java program which creates class A with private data members as
“data” . a private member function msg() and a public method hello().
Create a another class Simple which contains the main() and access the
private data “data”.
https://www.javatpoint.com/access-modifiers

26 Predefined and User 1) Static Import


defined Packages Write a java program which creates a class “StaticImportDemo” .here import
statically the predefined System class to in your class .

2) User-defined packages
Write a java program which creates a student class in “pack” package .here
you define id,name,section name,email as data members, have a display().
And create another package Mypack place” test” class using import
statement import the student class print the details of student.

https://www.javatpoint.com/package

3 Pre-defined -1 packages- Util package scanner class

Write a java program which try to read data from the keyboard
using the Scanner class of the java.util package (like int float
,double,Boolean,string data)
https://www.tutorialspoint.com/what-is-a-predefined-
package-in-java

4 Predefined class -2 calendar class

The Calendar class is an abstract class that provides methods for


converting between a specific instant in time and a set of calendar fields
such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for
manipulating the calendar fields, such as getting the date of the next
week.

You are given a date. You just need to write the method, , which returns
the day on that date. To simplify your task, we have provided a portion of
the code in the editor.
For example, if you are given the date , the method should return as the
day on that date
https://www.hackerrank.com/challenges/java-date-and-
time/problem?h_r=internal-search
27 Interfaces and
implementing
interfaces

28
Extending
Interfaces

.1. Java Exception Handling


Exceptional
29 https://www.hackerrank.com/challenges/java-exception-handling/problem
Handling –
Usage of try and
.2. Java Exception Handling (Try-catch)
catch
https://www.hackerrank.com/challenges/java-exception-handling-try-
catch/problem

.3. Day 3: Try, Catch, and Finally


https://www.hackerrank.com/challenges/js10-try-catch-and-finally/problem

1. Exception Handling

Multiple https://www.hackerearth.com/practice/basic-
30
catch blocks, programming/implementation/basics-of-implementation/practice-
Nested try problems/algorithm/exception-handling-2-46f67551/
blocks
2. Nested try catch block in Java – Exception handling

https://beginnersbook.com/2013/04/nested-try-catch/

Throw, Throws 1. Exception handling is the process of responding to the occurrence, during
and finally blocks computation, of exceptions – anomalous or exceptional conditions requiring
31 User defined special processing – often changing the normal flow of program execution.
Exceptions (Wikipedia)

Java has built-in mechanism to handle exceptions. Using the try statement we
can test a block of code for errors. The catch block contains the code that says
what to do if exception occurs.

You will be given two integers x and y as input, you have to compute x/y . If x
and y are not 32- bit signed integers or if y is zero, exception will occur and
you have to report it. Read sample Input/Output to know what to report in case
of exceptions.

Sample Input 0:
10
3
Sample Output 0:
3
Sample Input 1:
10
Hello
Sample Output 1:
java.util.InputMismatchException
Sample Input 2:
10
0
Sample Output 2:
java.lang.ArithmeticException: / by zero
Sample Input 3:
23.323
0
Sample Output 3:
java.util.InputMismatchException
https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem

2. Read two numbers num1 and num2. Your goal is to find integer division. . If
Num1 or Num2 were not an integer, the program would throw a Number
Format Exception. If Num2 were Zero, the program would throw an
Arithmetic Exception.

1 Write a program which create a new class which implements


java.lang.Runnable interface and override run() method. Then we instantiate a
32 Multithreading - 1 Thread object and call start() method on this object. Like below and calculate
Fibonacci series

Class MultithreadingDemo implements Runnable

{ public void run()

1) Sereja and Number Division 2

33 Multithreading - 2 Sereja has an integer number A that doesn't contain zeroes in its decimal
form.
Also he has N integers B[1], B[2], ..., B[N].

Let us first define function f for a number A as follows.

Now he has to reorder the digits of A such that f(A) is minimum.


Please help him in finding most optimal A.

URL : https://www.codechef.com/JAN15/problems/SEAND2

2) Multi Threads

Sheldon is addicted to Facebook , and keeps refreshing the main page


not to miss any changes in the "recent actions" list. He likes to read
thread conversations of where each thread consists of multiple
messages.
Recent actions shows a list of n different threads ordered by the time of
the latest message in the thread. When a new message is posted in a
thread that thread jumps on the top of the list. No two messages of
different threads are ever posted at the same time.

Sheldon has just finished reading all his opened threads and refreshes
the main page for some more messages to feed his addiction. He notices
that no new threads have appeared in the list and at the i-th place in the
list there is a thread that was at the ai-th place before the refresh. He
doesn't want to waste any time reading old messages so he wants to open
only threads with new messages.

Help Sheldon find out the number of threads that surely have new
messages. A thread x surely has a new message if there is no such
sequence of thread updates (posting messages) that both conditions hold:

thread x is not updated (it has no new messages);

The list order 1, 2, ..., n changes to a1, a2, ..., an.

URL : https://www.codechef.com/PROM2013/problems/PT2

1) Java Arraylist
Introduction to Sometimes it's better to use dynamic size arrays. Java's Arraylist can
34
Collection provide you this feature. Try to solve this problem using Arraylist. You
Framework – Lists are given n lines. In each line there are zero or more integers. You need
to answer a few queries where you need to tell the number located in yth
position of xth line.

Take your input from System.in.

URL:https://www.hackerrank.com/challenges/java-
arraylist/problem?h_r=internal-search

2) Java Visitor Pattern

Note: In this problem you must NOT generate any output on your own.
Any such solution will be considered as being against the rules and its
author will be disqualified. The output of your solution must be
generated by the uneditable code provided for you in the solution
template.

An important concept in Object-Oriented Programming is the


open/closed principle, which means writing code that is open to
extension but closed to modification. In other words, new functionality
should be added by writing an extension for the existing code rather than
modifying it and potentially breaking other code that uses it. This
challenge simulates a real-life problem where the open/closed principle
can and should be applied.

A Tree class implementing a rooted tree is provided in the editor. It has


the following publicly available methods:

getValue(): Returns the value stored in the node.

getColor(): Returns the color of the node.

getDepth(): Returns the depth of the node. Recall that the depth of a
node is the number of edges between the node and the tree's root, so the
tree's root has depth and each descendant node's depth is equal to the
depth of its parent node +1.

In this challenge, we treat the internal implementation of the tree as


being closed to modification, so we cannot directly modify it; however,
as with real-world situations, the implementation is written in such a
way that it allows external classes to extend and build upon its
functionality. More specifically, it allows objects of the TreeVis class (a
Visitor Design Pattern) to visit the tree and traverse the tree structure via
the accept method.

There are two parts to this challenge.

URL:https://www.hackerrank.com/challenges/java-vistor-
pattern/problem

1. The Owner of a Supermarket asks the Employe to maintain a


detailed record consisting Name, Id and Cost of the item available in
Introduction to
35 their supermarket. He also asks him to get the information of those
Collection
items in ascending order of the costs. He asks your help for writing a
Framework – Set
program which takes in the details through the Scanner class and add
them to the array list. Your program should also display the details
of the items compared in ascending order of the item cost. (Use list
and Comparable interface).
2. Mahesh babu was asked to develop a game based on stacks. There
will be two players in the game. Every player will get a turn to enter
a number and that number will be pushed into a stack if the given
number is divided by a number which is randomly generated by the
game otherwise the top element of the stack will be popped out. The
player whose is left with no numbers in the stack is the loser. Print
the Winner of the game

1. Madhuri wants to develop an app which sorts the Student Ids based
on marks (ascending). The User provides the marks of different
Introduction to
36 students along with student Ids and stores them in a HahMap. Help
Collection
him out writing the program to develop the app.
Framework – Map
2. Naresh wants you to develop a program which takes in words from
a list of movies names as dynamic user input and stores them in a
Hashset. It should then print them in lexicographical order after
converting Hashset into Treeset.

Potrebbero piacerti anche