You are on page 1of 2

"

Create class Document with below attributes

id - int
title - String
folderName - String
pages - int

Write getters, setters and parameterized constructor as required.��

Create class Solution with main method.�

Implement static method - combineDocs in Solution class.

This method will take array of Document objects and return another document object
which will be combinition of all objects in array.

The logic for combining each attribute will be as below:

id - this value will be 1 more than maximum value of id in object array.


title - this value will be concatanation of title values of all objects in the
array (separated by #).�
folderName - this value will be concatanation of folderName values of all objects
in the array (separated by @)
pages - this value will be total of page values in the object array. �

This method should be called from main method and display values of returned object
as shared in the sample.

Before calling this method, use Scanner object to read values for four Document
objects referring attributes in the above sequence.�

Next call the method and display the result.�

Consider below sample input and output:

Input:
1
resume
personal
50
2
question1
exams
55
3
question2
exams
45
4
India
misc
40

Output:
5
resume#question1#question2#India
personal@exams@exams@misc
190

Note on using Scanner object:


Sometimes scanner does not read the new line character while invoking methods like
nextInt(), nextDouble() etc.�
Usually, this is not an issue, but this may be visible while calling nextLine()
immediately after those methods.

Consider below input values:


22
hello

Referring below code:

Scanner sc = new Scanner(System.in);


int x = sc.nextInt();
String str = sc.nextLine(); -> here we expect str to have value hello. Instead it
may be """".

If above issue is observed, then it is suggested to add one more explicit call to
nextLine() after reading numeric value.

"

You might also like