· 8 years ago · Jun 02, 2018, 10:36 AM
1{
2 "resources": {
3 "array": [
4 {
5 "-name": "greetings",
6 "item": [
7 "GOOD FOR YOU !!",
8 "REGULAR FELLOW !!",
9 "BRAVE !!",
10 "FINE FELLOW !!",
11 "GENIUS !!",
12 "VERY GOOD !!",
13 "JOLLY FINE !!",
14 "FULL WELL !!",
15 "FINE !!",
16 "TIPTOP !!",
17 "IDEALLY !!",
18 "PRIMELLY !!",
19 "TOPPINGLY !!",
20 "SWIMMINGLY !!",
21 "WONDERFULLY !!",
22 "BRAIN !!",
23 "SUPER !!",
24 "MAGE !!",
25 "SAPIENT !!",
26 "JUST GOOD !!",
27 "TALENT !!",
28 "CLEVERLY !!",
29 "COOL !!",
30 "BOLD !!",
31 "BRILLIANT !!",
32 "BRIGHT !!",
33 "INTELLECTUAL !!",
34 "ABLE !!",
35 "GIFTED !!",
36 "ADEPT !!",
37 "SKILLFUL !!",
38 "WIZARD !!",
39 "TOP-NOTCH !!",
40 "BAND-UP !!",
41 "CLASSY !!",
42 "SUPER-DUPER !!",
43 "ZINGY !!",
44 "WISELY !!",
45 "YOU ARE BRILLIANT !!",
46 "YOU ARE SMART !!",
47 "YOU ARE TALENTED !!",
48 "YOU ARE WONDERFUL !!"
49 ]
50 },
51 {
52 "-name": "lessons",
53 "item": [
54 "1",
55 "\"Hello world 5 times\", String variables",
56 "String variables\\n\\nStrings, which are widely used in Java programming, are a sequence of characters.\\nThe most direct way to create a string is to write:\\n\\nString greeting = \"Hello world\";\\n\\nTo set up a string variable, you type the word String followed by a name for your variable. Note that there's an uppercase \"S\" for String. Again, a semicolon ends the line:\\n\\nString a;\\n\\nAssign a value to your new string variable by typing an equals sign. After the equals sign the text you want to store goes between two sets of double quotes:\\n\\na = \"Hello\";\\n\\nIf you prefer, you can have all that on one line:\\n\\nString a = \"Hello \";\\n\\nSet up a second string variable:\\n\\nString b = \"world\";\\n\\nTo print both worlds, add the following System.out.println( ):\\n\\nSystem.out.println(a + \" \" + b);\\n\\nIn between the round brackets of println, we have this:\\n\\na + \" \" + b\\n\\nYou should print out whatever is in the variable called a. We then have a plus symbol, followed by a space. The space is enclosed in double quotes. This is so that Java will recognise that we want to print out a space character. After the space, we have another plus symbol, followed by the b variable.\\n\\nEvery programming language has its own set of rules and conventions for the kinds of names that you are allowed to use, and the Java programming language is no different. The rules and conventions for naming your variables can be summarized as follows:\\n\\nVariable names are case-sensitive. A variable is a name that can be any legal identifier - an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign \"$\", or the underscore character \"_\". The convention, however, is to always begin your variable names with a letter, not \"$\" or \"_\". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it is technically legal to begin your variable with \"_\", this practice is discouraged. White space is not permitted. Subsequent characters may be letters, digits, dollar signs, or underscore characters. Conventions (and common sense) apply to this rule as well. When choosing a name for your variables, use full words instead of cryptic abbreviations. Doing so will make your code easier to read and understand. In many cases it will also make your code self-documenting; fields named cadence, speed, and gear, for example, are much more intuitive than abbreviated versions, such as c, s, and g. Also keep in mind that the name you choose must not be a keyword or reserved word. If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word. The names gearRatio and currentGear are prime examples of this convention.",
57 "2",
58 "\"Hello world 5 times\", int variables",
59 "int variables \\n\\nTo set up an int variable, you type the word int followed by a name for your variable. Again, a semicolon ends the line:\\n\\nint a;\\n\\nAssign a value to your new int variable by typing an equals sign. After the equals sign the number you want:\\n\\na = 2;\\n\\nIf you prefer, you can have all that on one line:\\n\\nint a = 2;\\n\\nSet up a second int variable:\\n\\nint b = 3.\\n\\nOperator + concatenates two strings, producing a String object as the result. For example, the following fragment concatenates two strings:\\n\\nString a = \"5\";\\nString b = a + \" times\";\\nSystem.out.println(b);\\n\\nYou can concatenate strings with other types of data. For example, consider this slightly different version of the earlier example:\\n\\nint a = 5;\\nString b = a + \" times\";\\nSystem.out.println(b);\\n\\nIn this case, a is an int rather than another String, but the output produced is the same as before. This is because the int value in a is automatically converted into its string representation within a String object. This string is then concatenated as before. The compiler will convert an operand to its string equivalent whenever the other operand of the + is an instance of String. Be careful when you mix other types of operations with string concatenation expressions, however. You might get surprising results. Consider the following:\\n\\nString s = \"four: \" + 2 + 2;\\nSystem.out.println(s);\\n\\nThis fragment displays\\nfour: 22\\n\\nrather than the \\n\\nfour: 4 \\n\\nthat you probably expected. Here's why. Operator precedence causes the concatenation of \"four\" with the string equivalent of 2 to take place first. This result is then concatenated with the string equivalent of 2 a second time. To complete the integer addition first, you must use parentheses, like this:\\n\\nString s = \"four: \" + (2 + 2);\\nNow s contains the string \"four: 4\".\\n",
60 "3",
61 "THE MATH, random()",
62 "Java provides us Math class, which includes methods with basic numeric operations such as logarithm, square root etc. One of these methods is random(), which give us a pseudorandom positive double number greater than or equal to 0.0 and less than 1.0 – [0.0, 1.0).\\n\\nIn this example we are going to show how to produce integer between a defined space, via random() method:\\n\\npublic class MathRandomClass {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// integer between [3,7]\\n\\t\\tint r1 = (int) (Math.random()*5)+3;\\n\\t\\tSystem.out.println(\"Integer between 3 and 7: r1 = \"+r1);\\n\\n\\t\\t// integer between [-10,10] \\n\\t\\tint r2 = (int) (Math.random()*21)-10;\\n\\t\\tSystem.out.println(\"Integer between -10 and 10: r2 = \"+r2);\\n \\t}\\n}\\n\\nNow lets explain the code above. Firstly, we use the random() method in order to take a positive signed double value, that belongs into the range [0.0, 0.1). For generating random integer numbers between a range, we should multiply and/or sum the appropriate positive and/or negative values in order to achieve the desirable result. For example, if we multiply the result with 5 and add number 3, the range has as minimum value number 3 and as maximum value their sum (5+3). Please notice that the random values are always less than this sum – in our example the range is [3,8). Also notice that for integer values we should cast the result. We can use the same way for negative random numbers etc.\\n\\nFor a better understanding, please look the output of the execution. As you can notice, all the parameters take a value that is into their respective range.\\n\\nOutput:\\n\\nInteger between 3 and 7: r1 = 7\\nInteger between -10 and 10: r2 = -9\\n",
63 "4",
64 "CONSOLE INPUT, System.in",
65 "Console input\\n\\nJava provides standard \"System.in\" to read input from the keyboard and write output to the display. System.in is a byte stream so you can't read from it directly if you want to read character strings, which is what you normally want to do. Hence you must wrap a Scanner object around System.in. The following statement accomplishes this task:\\n\\nScanner sc = new Scanner(System.in);\\n\\nIf not everything is clear not worry, everything will be much clearer later, while just remember \"Scanner sc = new Scanner (System.in)\". This code read a String and an Integer from the console and stores them in the variables.\\n//the Scanner class must be imported from java.util.\\n\\nimport java.util.Scanner;\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString name;\\n\\t\\tint age;\\n\\n\\t\\t// declares an Scanner object \\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\t// Reads a single line from the console \\n\\t\\t// and stores into name variable\\n\\t\\tname = sc.nextLine();\\n\\n\\t\\t// Reads a integer from the console\\n\\t\\t// and stores into age variable\\n\\t\\tage=sc.nextInt();\\n\\n\\t\\t// closes the Scanner object \\n\\t\\tsc.close();\\n \\n\\t\\t// Prints name and age to the console\\n\\t\\tSystem.out.println(\"Name :\" + name);\\n\\t\\tSystem.out.println(\"Age :\" + age);\\n\\t}\\n}\\n",
66 "5",
67 "THE DECISION-MAKING STATEMENTS, if-then",
68 "The if-then Statement\\n\\nThe if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. For example, the Bicycle class could allow the brakes to decrease the bicycle's speed only if the bicycle is already in motion. One possible implementation of the applyBrakes method could be as follows:\\n\\nvoid applyBrakes() {\\n\\t// the \"if\" clause: bicycle must be moving\\n\\tif (isMoving){ \\n\\t\\t// the \"then\" clause: decrease current speed\\n\\t\\tcurrentSpeed - -;\\n\\t}\\n}\\n\\nIf this test evaluates to false (meaning that the bicycle is not in motion), control jumps to the end of the if-then statement.\\n\\nIn addition, the opening and closing braces are optional, provided that the \"then\" clause contains only one statement:\\n\\nvoid applyBrakes() {\\n\\t// same as above, but without braces \\n\\tif (isMoving)\\n\\tcurrentSpeed - -;\\n}\\n\\nDeciding when to omit the braces is a matter of personal taste. Omitting them can make the code more brittle. If a second statement is later added to the \"then\" clause, a common mistake would be forgetting to add the newly required braces. The compiler cannot catch this sort of error; you'll just get the wrong results.\\n\\nThe if-then-else Statement\\n\\nThe if-then-else statement provides a secondary path of execution when an \"if\" clause evaluates to false. You could use an if-then-else statement in the applyBrakes method to take some action if the brakes are applied when the bicycle is not in motion. In this case, the action is to simply print an error message stating that the bicycle has already stopped.\\n\\nvoid applyBrakes() {\\n\\tif (isMoving) {\\n\\t\\tcurrentSpeed - -;\\n\\t} else {\\n\\t\\tSystem.err.println(\"The bicycle has already stopped!\");\\n\\t} \\n}\\n",
69 "6",
70 "THE DECISION-MAKING STATEMENTS, if-else-if",
71 "If-else-if\\n\\nFor more than two choices, the IF … ELSE IF statement can be used. The structure of an IF … ELSE IF is this:\\n\\nif ( condition_one ) {\\n\\n}\\nelse if ( condition_two ) {\\n\\n}\\nelse if ( condition_three ) {\\n\\n}\\nelse {\\n\\n}\\n\\nSo the first IF tests for condition number one. Next comes else if, followed by a pair of round brackets. The second condition goes between these round brackets. The third condition goes between next round brackets. Anything not caught by the first three conditions will be caught be the final else. Again, code is sectioned off using curly brackets, with each if, else if, or else having its own pair of curly brackets. Miss one out and you'll get error messages. the first IF tests for condition number one (18 or under, for example). Next comes else if, followed by a pair of round brackets. The second condition goes between these new round brackets. Anything not caught by the first two conditions will be caught be the final else. Again, code is sectioned off using curly brackets, with each if, else if, or else having its own pair of curly brackets. Miss one out and you'll get error messages.\\n",
72 "7",
73 "THE DECISION-MAKING STATEMENTS, switch",
74 "The switch Statement\\n\\nUnlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer (discussed in Numbers and Strings).\\n\\nThe following code example, SwitchDemo, declares an int named month whose value represents a month. The code displays the name of the month, based on the value of month, using the switch statement.\\n\\npublic class SwitchDemo {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint month = 8;\\n\\t\\tString monthString;\\n\\t\\tswitch (month) {\\n\\t\\t\\tcase 1: monthString = \"January\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2: monthString = \"February\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 3: monthString = \"March\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 4: monthString = \"April\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 5: monthString = \"May\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 6: monthString = \"June\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 7: monthString = \"July\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 8: monthString = \"August\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 9: monthString = \"September\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 10: monthString = \"October\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 11: monthString = \"November\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 12: monthString = \"December\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tdefault: monthString = \"Invalid month\";\\n\\t\\t\\t\\tbreak;\\n\\t\\t}\\n\\t\\tSystem.out.println(monthString);\\n\\t}\\n}\\n\\nIn this case, August is printed to standard output.\\n\\nThe body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluates its expression, then executes all statements that follow the matching case label.\\n\\nYou could also display the name of the month with if-then-else statements:\\n\\nint month = 8;\\nif (month == 1) {\\n\\tSystem.out.println(\"January\");\\n} else if (month == 2) {\\n\\tSystem.out.println(\"February\");\\n}\\n… // and so on\\n\\nDeciding whether to use if-then-else statements or a switch statement is based on readability and the expression that the statement is testing. An if-then-else statement can test expressions based on ranges of values or conditions, whereas a switch statement tests expressions based only on a single integer, enumerated value, or String object.\\n\\nAnother point of interest is the break statement. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered. The program displays the month corresponding to the integer month and the months that follow in the year:\\n\\npublic class SwitchDemoFallThrough {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint month = 8;\\n\\n\\t\\tswitch (month) {\\n\\t\\t\\tcase 1: System.out.println(\"January\");\\n\\t\\t\\tcase 2: System.out.println(\"February\");\\n\\t\\t\\tcase 3: System.out.println(\"March\");\\n\\t\\t\\tcase 4: System.out.println(\"April\");\\n\\t\\t\\tcase 5: System.out.println(\"May\");\\n\\t\\t\\tcase 6: System.out.println(\"June\");\\n\\t\\t\\tcase 7: System.out.println(\"July\");\\n\\t\\t\\tcase 8: System.out.println(\"August\");\\n\\t\\t\\tcase 9: System.out.println(\"September\");\\n\\t\\t\\tcase 10: System.out.println(\"October\");\\n\\t\\t\\tcase 11: System.out.println(\"November\");\\n\\t\\t\\tcase 12: System.out.println(\"December\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tdefault: break;\\n\\t\\t}\\n\\t}\\n}\\n\\nThis is the output from the code:\\n\\nAugust\\nSeptember\\nOctober\\nNovember\\nDecember\\n",
75 "8",
76 "THE DECISION-MAKING STATEMENTS, ?:",
77 "The Java ternary operator syntax\\n\\nAt its most basic, the ternary operator (also known as the conditional operator) can be used as an alternative to the Java if/then/else syntax.\\n\\nSimple ternary operator examples.\\nOne use of the Java ternary operator is to assign the minimum value of two variables to a third variable. Here's an example that assigns the minimum of two variables, a and b, to a third variable named minVal is:\\n\\nminVal = (a < b) ? a : b;\\n\\nIn this code, if the variable a is less than b, minVal is assigned the value of a; otherwise, minVal is assigned the value of b. Note that the parentheses in this example are optional, so you can write that same statement like this:\\n\\nminVal = a < b ? a : b;\\n\\nYou can take a similar approach to get the absolute value of a number, using code like this:\\n\\nint absValue = (a < 0) ? -a : a;\\n\\nGeneral ternary operator syntax.\\nGiven those examples, you can probably see that the general syntax of the ternary operator looks like this:\\n\\nresult = testCondition ? value1 : value2\\n\\nIf testCondition is true, assign the value of value1 to result; otherwise, assign the value of value2 to result.Here's an example using a String:\\n\\n// result is assigned the value \"Sorry Dude, it's false\"\\nString result = false ? \"Dude, that was true\" : \"Sorry Dude, it's false\";\\n",
78 "9",
79 "THE CONDITIONAL OPERATORS, ||, &&, !=",
80 "The Conditional Operators\\n\\nThe && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operators exhibit \"short-circuiting\" behavior, which means that the second operand is evaluated only if needed.\\n\\n&& Conditional-AND\\n|| Conditional-OR\\n\\nThe following program, ConditionalDemo1, tests these operators:\\n\\nclass ConditionalDemo1 {\\n\\n\\tpublic static void main(String[] args){\\n\\t\\tint value1 = 1;\\n\\t\\tint value2 = 2;\\n\\t\\tif((value1 == 1) && (value2 == 2)){\\n\\t\\t\\tSystem.out.println(\"value1 is 1 AND value2 is 2\");\\n\\t\\t}\\n\\t\\tif((value1 == 1) || (value2 == 1)){\\n\\t\\t\\tSystem.out.println(\"value1 is 1 OR value2 is 1\");\\n\\t\\t}\\n\\t}\\n}\\n",
81 "10",
82 "THE LOOP, do-while",
83 "The while and do-while Statements\\n\\nThe while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:\\n\\nwhile (expression) {\\n\\tstatement(s)\\n}\\n\\nThe while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false. Using the while statement to print the values from 1 through 10 can be accomplished as in the following WhileDemo program:\\n\\nclass WhileDemo {\\n\\tpublic static void main(String[] args){\\n\\t\\tint count = 1;\\n\\t\\twhile (count < 11) {\\n\\t\\t\\tSystem.out.println(\"Count is: \" + count);\\n\\t\\t\\tcount++;\\n\\t\\t}\\n\\t}\\n}\\n\\nYou can implement an infinite loop using the while statement as follows:\\n\\nwhile (true){\\n\\t// your code goes here\\n}\\n\\nThe Java programming language also provides a do-while statement, which can be expressed as follows:\\n\\ndo {\\n\\t statement(s)\\n} while (expression);\\n\\nThe difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within the do block are always executed at least once, as shown in the following DoWhileDemo program:\\n\\nclass DoWhileDemo {\\n\\tpublic static void main(String[] args){\\n\\t\\tint count = 1;\\n\\t\\tdo {\\n\\t\\t\\tSystem.out.println(\"Count is: \" + count);\\n\\t\\t\\tcount++;\\n\\t\\t} while (count < 11);\\n\\t}\\n}\\n",
84 "11",
85 "THE LOOP, for",
86 "The for Statement\\n\\nThe for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the \"for loop\" because of the way in which it repeatedly loops until a particular condition is satisfied. The general form of the for statement can be expressed as follows:\\n\\nfor (initialization; termination; increment) {\\n\\tstatement(s)\\n}\\n\\nWhen using this version of the for statement, keep in mind that:\\n\\n 1. The initialization expression initializes the loop; it's executed once, as the loop begins.\\n 2. When the termination expression evaluates to false, the loop terminates.\\n 3. The increment expression is invoked after each iteration through the loop; it is perfectly acceptable for this expression to increment or decrement a value.\\n\\nThe following program, ForDemo, uses the general form of the for statement to print the numbers 1 through 10 to standard output:\\n\\nclass ForDemo {\\n\\tpublic static void main(String[] args){\\n\\t\\tfor(int i=1; i<11; i++){\\n\\t\\t\\tSystem.out.println(\"Count is: \" + i);\\n\\t\\t}\\n\\t}\\n}\\n\\nThe output of this program is:\\n\\nCount is: 1\\nCount is: 2\\nCount is: 3\\nCount is: 4\\nCount is: 5\\nCount is: 6\\nCount is: 7\\nCount is: 8\\nCount is: 9\\nCount is: 10\\n\\nNotice how the code declares a variable within the initialization expression. The scope of this variable extends from its declaration to the end of the block governed by the for statement, so it can be used in the termination and increment expressions as well. If the variable that controls a for statement is not needed outside of the loop, it's best to declare the variable in the initialization expression. The names i, j, and k are often used to control for loops; declaring them within the initialization expression limits their life span and reduces errors.\\n\\nThe three expressions of the for loop are optional; an infinite loop can be created as follows:\\n\\n// infinite loop\\nfor ( ; ; ) { \\n\\t// your code goes here\\n}\\n",
87 "12",
88 "ARRAYS, int",
89 "Arrays\\n\\nAn array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. \\n\\nEach item in an array is called an element, and each element is accessed by its numerical index. Numbering begins with 0. The 5th element, for example, would therefore be accessed at index 4.\\n\\nThe following program, ArrayDemo, creates an array of integers, puts some values in the array, and prints each value to standard output.\\n\\nclass ArrayDemo {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// declares an array of integers\\n\\t\\tint[] anArray;\\n\\n\\t\\t// allocates memory for 5 integers\\n\\t\\tanArray = new int[5];\\n\\n \\t\\t// initialize first element\\n\\t\\tanArray[0] = 100;\\n\\t\\t// initialize second element\\n\\t\\tanArray[1] = 200;\\n\\t\\t// and so forth\\n\\t\\tanArray[2] = 300;\\n\\t\\tanArray[3] = 400;\\n\\t\\tanArray[4] = 500;\\n\\n\\t\\tSystem.out.println(\"Element at index 0: \" + anArray[0]);\\n\\t\\tSystem.out.println(\"Element at index 1: \" + anArray[1]);\\n\\t\\tSystem.out.println(\"Element at index 2: \" + anArray[2]);\\n\\t\\tSystem.out.println(\"Element at index 3: \" + anArray[3]);\\n\\t\\tSystem.out.println(\"Element at index 4: \" + anArray[4]); \\n \\t}\\n} \\n\\nThe output from this program is:\\n\\nElement at index 0: 100\\nElement at index 1: 200\\nElement at index 2: 300\\nElement at index 3: 400\\nElement at index 4: 500\\n\\nIn a real-world programming situation, you would probably use one of the supported looping constructs to iterate through each element of the array, rather than write each line individually as in the preceding example. However, the example clearly illustrates the array syntax.\\n\\nDeclaring a Variable to Refer to an Array\\n\\nThe preceding program declares an array (named anArray) with the following line of code:\\n\\n// declares an array of integers\\nint[] anArray;\\n\\nLike declarations for variables of other types, an array declaration has two components: the array's type and the array's name. An array's type is written as type[], where type is the data type of the contained elements; the brackets are special symbols indicating that this variable holds an array. The size of the array is not part of its type (which is why the brackets are empty). An array's name can be anything you want, as with variables of other types, the declaration does not actually create an array; it simply tells the compiler that this variable will hold an array of the specified type.\\n\\nSimilarly, you can declare arrays of other types:\\n\\nbyte[] anArrayOfBytes;\\nshort[] anArrayOfShorts;\\nlong[] anArrayOfLongs;\\nfloat[] anArrayOfFloats;\\ndouble[] anArrayOfDoubles;\\nboolean[] anArrayOfBooleans;\\nchar[] anArrayOfChars;\\nString[] anArrayOfStrings;\\n\\nYou can also place the brackets after the array's name:\\n\\n// this form is discouraged\\nfloat anArrayOfFloats[];\\n\\nHowever, convention discourages this form; the brackets identify the array type and should appear with the type designation.\\n\\nCreating, Initializing, and Accessing an Array\\n\\nOne way to create an array is with the new operator. The next statement in the ArrayDemo program allocates an array with enough memory for 10 integer elements and assigns the array to the anArray variable.\\n\\n// create an array of integers\\nanArray = new int[10];\\n\\nIf this statement is missing, then the compiler prints an error like the following, and compilation fails:\\n\\nArrayDemo.java:4: Variable anArray may not have been initialized.\\n\\nThe next few lines assign values to each element of the array:\\n\\nanArray[0] = 100; // initialize first element\\nanArray[1] = 200; // initialize second element\\nanArray[2] = 300; // and so forth\\n\\nEach array element is accessed by its numerical index:\\n\\nSystem.out.println(\"Element 1 at index 0: \" + anArray[0]);\\nSystem.out.println(\"Element 2 at index 1: \" + anArray[1]);\\nSystem.out.println(\"Element 3 at index 2: \" + anArray[2]);\\n\\nAlternatively, you can use the shortcut syntax to create and initialize an array:\\n\\nint[] anArray = { 100, 200, 300,400, 500, 600, 700, 800, 900, 1000 };\\n\\nHere the length of the array is determined by the number of values provided between braces and separated by commas.\\n",
90 "13",
91 "ARRAYS, String",
92 "Arrays of Strings\\n\\nYou can declare arrays of other types:\\n\\nbyte[] anArrayOfBytes;\\nshort[] anArrayOfShorts;\\nlong[] anArrayOfLongs;\\nfloat[] anArrayOfFloats;\\ndouble[] anArrayOfDoubles;\\nboolean[] anArrayOfBooleans;\\nchar[] anArrayOfChars;\\nString[] anArrayOfStrings;\\n\\nThe following program, ArrayDemo, creates an array of Strings, puts some values in the array, and prints each value to standard output.\\n\\nclass ArrayDemo {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\t// create and initialize an array\\n\\t\\tString[] arrayName = { \"Jone\", \"Mik\", \"Nic\", \"Jane\"};\\n\\t\\tint[] arrayAssessments = { 8, 7, 6, 5 };\\n\\n\\t\\tint lengthArray = arrayName.length;\\n\\t\\tSystem.out.println(\"Assessments of pupils\");\\n\\t\\tfor (int i = 0; i < l; i++) {\\n\\t\\t\\tSystem.out.print(arrayName[i] + \" \" + arrayAssessments[i]);\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n}\\n\\nThe output from this program is:\\n\\nAssessments of pupils\\nJone 8\\nMik 7\\nNic 6\\nJane 5\\n",
93 "14",
94 "THE LOOP, for-each",
95 "For each\\n\\nThe for statement also has another form designed for iteration through Collections and arrays This form is sometimes referred to as the enhanced for statement, and can be used to make your loops more compact and easy to read. To demonstrate, consider the following array, which holds the numbers 1 through 10:\\n\\nint[] numbers = {1,2,3,4,5,6,7,8,9,10};\\n\\nThe following program, EnhancedForDemo, uses the enhanced for to loop through the array:\\n\\nclass EnhancedForDemo {\\n\\tpublic static void main(String[] args){\\n\\t\\tint[] numbers = {1,2,3,4,5,6,7,8,9,10};\\n\\t\\tfor (int item : numbers) {\\n\\t\\t\\tSystem.out.println(\"Count is: \" + item);\\n\\t\\t}\\n\\t}\\n}\\n\\nIn this example, the variable item holds the current value from the numbers array. The output from this program is the same as before:\\n\\nCount is: 1\\nCount is: 2\\nCount is: 3\\nCount is: 4\\nCount is: 5\\nCount is: 6\\nCount is: 7\\nCount is: 8\\nCount is: 9\\nCount is: 10\\n\\nWe recommend using this form of the for statement instead of the general form whenever possible.\\n",
96 "15",
97 "ARRAYS, multidimensional arrays",
98 "You can also declare an array of arrays (also known as a multidimensional array) by using two or more sets of brackets, such as String[][] names. Each element, therefore, must be accessed by a corresponding number of index values.\\n\\nIn the Java programming language, a multidimensional array is an array whose components are themselves arrays. This is unlike arrays in C or Fortran. A consequence of this is that the rows are allowed to vary in length, as shown in the following MultiDimArrayDemo program:\\n\\nclass MultiDimArrayDemo {\\n\\tpublic static void main(String[] args) {\\n\\t\\tString[][] names = {{\"Mr. \",\"Mrs., \"Ms.},\\n\\t\\t{\"Smith\", \"Jones\"}};\\n\\t\\t// Mr. Smith\\n\\t\\tSystem.out.println(names[0][0] + names[1][0]);\\n\\t\\t// Ms. Jones\\n\\t\\tSystem.out.println(names[0][2] + names[1][1]);\\n\\t}\\n}\\n\\nThe output from this program is:\\n\\nMr. Smith\\nMs. Jones\\n",
99 "16",
100 "CONVERTING",
101 "Converting \\n\\n1.Converting Strings to Numbers\\n\\nFrequently, a program ends up with numeric data in a string object — a value entered by the user, for example.\\n\\nThe Number subclasses that wrap primitive numeric types ( Byte, Integer, Double, Float, Long, and Short) each provide a class method named valueOf that converts a string to an object of that type. Here is an example, Task , that gets two strings from the command line, converts them to numbers, and performs arithmetic operations on the values:\\n\\npublic class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString stroki[] = { \"5\", \"2\" };\\n\\t\\tSystem.out.println(stroki[0] + \" -\" + stroki[1]);\\n\\t\\tint j = Integer.valueOf(stroki[0]);\\n\\t\\tj++;\\n\\t\\tstroki[0] = Integer.toString(j);\\n\\t\\tint g = Integer.valueOf(stroki[1]);\\n\\t\\tg = g + 5;\\n\\t\\tstroki[1] = Integer.toString(g);\\n\\t\\tSystem.out.println(stroki[0] + \" -\" + stroki[1]);\\n\\t}\\n}\\n\\nOutput:\\n\\n5 -2\\n6 -7\\n\\nNote: Each of the Number subclasses that wrap primitive numeric types also provides a parseXXXX() method (for example, parseFloat()) that can be used to convert strings to primitive numbers. Since a primitive type is returned instead of an object, the parseFloat() method is more direct than the valueOf() method. For example, in the ValueOfDemo program, we could use:\\n\\nint j = Integer.parseInt(stroki[0]);\\nint g = Integer.parseInt(stroki[1]);\\n\\n2.Converting Numbers to Strings\\n\\nSometimes you need to convert a number to a string because you need to operate on the value in its string form. There are several easy ways to convert a number to a string:\\n\\nint i;\\n// Concatenate \"i\" with an empty string; conversion is handled for you.\\nString s1 = \"\" + i;\\n\\nor\\n\\n// The valueOf class method.\\nString s2 = String.valueOf(i);\\n\\nEach of the Number subclasses includes a class method, toString(), that will convert its primitive type to a string. For example:\\n\\nint i;\\ndouble d;\\nString s3 = Integer.toString(i); \\nString s4 = Double.toString(d); \\n\\nThe ToStringDemo example uses the toString method to convert a number to a string. The program then uses some string methods to compute the number of digits before and after the decimal point:\\n\\npublic class ToStringDemo {\\n\\n \\tpublic static void main(String[] args) {\\n \\t\\tdouble d = 858.48;\\n\\t\\tString s = Double.toString(d);\\n\\n\\t\\tint dot = s.indexOf('.');\\n\\n\\t\\tSystem.out.println(dot + \" digits \" +\\n\\t\\t\"before decimal point.\");\\n\\t\\tSystem.out.println( (s.length() - dot - 1) +\\n\\t\\t\" digits after decimal point.\");\\n\\t}\\n}\\n\\nThe output of this program is:\\n\\n3 digits before decimal point.\\n2 digits after decimal point.\\n\\n3.Widening Primitive Conversion\\n\\n19 specific conversions on primitive types are called the widening primitive conversions:\\n\\n\\tbyte to short, int, long, float, or double\\n\\tshort to int, long, float, or double\\n\\tchar to int, long, float, or double\\n\\tint to long, float, or double\\n\\tlong to float or double\\n\\tfloat to double\\n\\nA widening primitive conversion does not lose information about the overall magnitude of a numeric value.\\n\\nA widening primitive conversion from an integral type to another integral type, or from float to double, does not lose any information at all; the numeric value is preserved exactly.\\n\\nA widening primitive conversion from float to double that is not strictfp may lose information about the overall magnitude of the converted value.\\n\\nA widening conversion of an int or a long value to float, or of a long value to double, may result in loss of precision - that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value.\\n\\nDespite the fact that loss of precision may occur, a widening primitive conversion never results in a run-time exception. Example:\\n\\nclass Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tint big = 1234567890;\\n\\t\\tfloat approx = big;\\n\\t\\tSystem.out.println(big - (int)approx);\\n\\t}\\n}\\n\\nThis program prints:\\n\\n-46\\n\\nthus indicating that information was lost during the conversion from type int to type float because values of type float are not precise to nine significant digits.\\n\\n4.Narrowing Primitive Conversion\\n\\n22 specific conversions on primitive types are called the narrowing primitive conversions:\\n\\n\\tshort to byte or char\\n\\tchar to byte or short\\n\\tint to byte, short, or char\\n\\tlong to byte, short, char, or int\\n\\tfloat to byte, short, char, int, or long\\n\\tdouble to byte, short, char, int, long, or float\\n\\nA narrowing primitive conversion may lose information about the overall magnitude of a numeric value and may also lose precision and range.\\n",
102 "17",
103 "CLASS MATH, sqrt(), cbrt(), etc.",
104 "Math.sqrt()\\n\\nReturns the correctly rounded positive square root of a double value. Special cases:\\nIf the argument is NaN or less than zero, then the result is NaN.\\nIf the argument is positive infinity, then the result is positive infinity.\\nIf the argument is positive zero or negative zero, then the result is the same as the argument.\\nOtherwise, the result is the double value closest to the true mathematical square root of the argument value.\\n\\nMath.cbrt()\\n\\nReturns the cube root of a double value. Special cases:\\nIf the argument is NaN, then the result is NaN.\\nIf the argument is infinite, then the result is an infinity with the same sign as the argument.\\nIf the argument is zero, then the result is a zero with the same sign as the argument. \\n\\nMath.ceil() \\n\\nReturns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases:\\nIf the argument value is already equal to a mathematical integer, then the result is the same as the argument.\\nIf the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.\\nIf the argument value is less than zero but greater than -1.0, then the result is negative zero.\\n\\nMath.floor()\\n\\nReturns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:\\nIf the argument value is already equal to a mathematical integer, then the result is the same as the argument.\\nIf the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.\\n\\nMath.sin()\\n\\nReturns the trigonometric sine of an angle. Special cases:\\nIf the argument is NaN or an infinity, then the result is NaN.\\nIf the argument is zero, then the result is a zero with the same sign as the argument.\\n \\nMath.cos()\\n\\nReturns the trigonometric cosine of an angle. Special cases:\\nIf the argument is NaN or an infinity, then the result is NaN. \\n\\nMath.tan()\\n\\nReturns the trigonometric tangent of an angle. Special cases:\\nIf the argument is NaN or an infinity, then the result is NaN.\\nIf the argument is zero, then the result is a zero with the same sign as the argument.\\n\\nMath.asin()\\n\\nReturns the arc sine of a value. Special cases:\\nIf the argument is NaN or its absolute value is greater than 1, then the result is NaN.\\nIf the argument is zero, then the result is a zero with the same sign as the argument.\\n\\nMath.acos()\\n\\nReturns the arc cosine of a value. Special case:\\nIf the argument is NaN or its absolute value is greater than 1, then the result is NaN.\\n\\nMath.atan()\\n\\nReturns the arc tangent of a value. Special cases:\\nIf the argument is NaN, then the result is NaN.\\nIf the argument is zero, then the result is a zero with the same sign as the argument.\\n\\nMath.toRadians()\\n\\nConverts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.\\n\\nMath.toDegrees()\\n\\nConverts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.\\n",
105 "18",
106 "CLASS MATH, min(), max(), etc.",
107 "Math.abs(a,b)\\n\\nReturns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.\\n\\nMath.max(a,b)\\n\\nReturns the greater of two int values. That is, the result is the argument closer to the value of Integer.MAX_VALUE. If the arguments have the same value, the result is that same value.\\n\\nMath.min(a,b)\\n\\nReturns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE. If the arguments have the same value, the result is that same value.\\n\\nMath.hypot(double x, double y)\\n\\nReturns sqrt(x2 +y2) without intermediate overflow or underflow. Special cases:\\nIf either argument is infinite, then the result is positive infinity.\\nIf either argument is NaN and neither argument is infinite, then the result is NaN. \\n\\nMath.PI\\n\\nThe double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.\\n",
108 "19",
109 "STRINGS, length(), charAt(), equals(), compareTo(), valueOf()",
110 "The String class represents character strings. All string literals in Java programs, such as \"abc\", are implemented as instances of this class.\\nStrings are constant; their values cannot be changed after they are created. The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. \\nThe Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. \\n\\npublic int length()\\n\\nReturns the length of this string. The length is equal to the number of Unicode code units in the string.\\nSpecified by:\\nlength in interface CharSequence\\nReturns:\\nthe length of the sequence of characters represented by this object.\\n\\npublic char charAt(int index)\\n\\nReturns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.\\nIf the char value specified by the index is a surrogate, the surrogate value is returned.\\nSpecified by:\\ncharAt in interface CharSequence\\nParameters:\\nindex - the index of the char value.\\nReturns:\\nthe char value at the specified index of this string. The first char value is at index 0.\\n\\npublic boolean equals(Object anObject)\\n\\nCompares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.\\nParameters:\\nanObject - The object to compare this String against\\nReturns:\\ntrue if the given object represents a String equivalent to this string, false otherwise.\\n\\npublic int compareTo(String anotherString)\\n\\nCompares two strings lexicographically. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true.\\nParameters:\\nanotherString - the String to be compared.\\nReturns:\\nthe value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument.\\n\\npublic static String valueOf(Object obj)\\n\\nReturns the string representation of the Object argument.\\nParameters:\\nobj - an Object.\\nReturns:\\nif the argument is null, then a string equal to \"null\"; otherwise, the value of obj.toString() is returned.\\n",
111 "20",
112 "STRINGS, substring(), indexOf(), replace(), isEmpty(), split()",
113 "public String substring(int beginIndex, int endIndex)\\n\\nReturns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.\\n\\nExamples:\\n\\n\"hamburger\".substring(4, 8) returns \"urge\"\\n\"smiles\".substring(1, 5) returns \"mile\"\\n\\nParameters:\\nbeginIndex - the beginning index, inclusive.\\nendIndex - the ending index, exclusive.\\nReturns:\\nthe specified substring.\\n\\npublic String substring(int beginIndex)\\n\\nReturns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.\\n\\nExamples:\\n\\n\"unhappy\".substring(2) returns \"happy\"\\n\"Harbison\".substring(3) returns \"bison\"\\n\"emptiness\".substring(9) returns \"\" (an empty string)\\n \\nParameters:\\nbeginIndex - the beginning index, inclusive.\\nReturns:\\nthe specified substring.\\n\\npublic int indexOf(String str)\\n\\nReturns the index within this string of the first occurrence of the specified substring.\\n\\npublic String replace(char oldChar, char newChar)\\n\\nReturns a new string resulting from replacing all occurrences of oldChar in this string with newChar.\\nIf the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.\\n\\nExamples:\\n\\n\"mesquite in your cellar\".replace('e', 'o') returns \"mosquito in your collar\"\\n\"the war of baronets\".replace('r', 'y') returns \"the way of bayonets\"\\n\"sparring with a purple porpoise\".replace('p', 't') returns \"starring with a turtle tortoise\"\\n\"JonL\".replace('q', 'x') returns \"JonL\" (no change)\\n\\nParameters:\\noldChar - the old character.\\nnewChar - the new character.\\nReturns:\\nstring derived from this string by replacing every occurrence of oldChar with newChar.\\n\\npublic boolean isEmpty()\\n\\nReturns true if, and only if, length() is 0.\\nReturns:\\ntrue if length() is 0, otherwise false.\\n\\npublic String[] split(String regex)\\n\\nSplits this string around matches of the given regular expression.\\nThis method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.\\n\\nThe string \"boo:and:foo\", for example, yields the following results with these expressions:\\n\\nRegex Result\\n: { \"boo\", \"and\", \"foo\" } \\n Parameters:\\nregex - the delimiting regular expression\\nReturns:\\nthe array of strings computed by splitting this string around matches of the given regular expression\\n",
114 "21",
115 "CLASSES, declaring objects",
116 "The class is at the core of Java.\\n\\nIt is the logical construct upon which the entire Java language is built because it defines the shape and nature of an object. As such, the class forms the basis for object-oriented programming in Java. Any concept you wish to implement in a Java program must be encapsulated within a class. \\n\\nClass Fundamentals \\n\\nPerhaps the most important thing to understand about a class is that it defines a new data type. Once defined, this new type can be used to create objects of that type. Thus, a class is a template for an object, and an object is an instance of a class. Because an object is an instance of a class, you will often see the two words object and instance used interchangeably. \\nThe General Form of a Class \\n\\nWhen you define a class, you declare its exact form and nature. You do this by specifying the data that it contains and the code that operates on that data. While very simple classes may contain only code or only data, most real-world classes contain both. \\n\\nA class is declared by use of the class keyword. The classes that have been used up to this point are actually very limited examples of its complete form. Classes can (and usually do) get much more complex. A simplified general form of a class definition is shown here: \\nclass classname { \\n\\ttype instance-variable1; \\n\\ttype instance-variable2;\\n\\t// …\\n\\ttype instance-variableN;\\n\\ttype methodname1(parameter-list) {\\n\\t\\t// body of method\\n\\t}\\n\\ttype methodname2(parameter-list) {\\n\\t\\t// body of method\\n\\t}\\n\\t// …\\n\\ttype methodnameN(parameter-list) {\\n\\t\\t// body of method \\n\\t} \\n} \\n\\nThe data, or variables, defined within a class are called instance variables. The code is contained within methods. Collectively, the methods and variables defined within a class are called members of the class. In most classes, the instance variables are acted upon and accessed by the methods defined for that class. Thus, as a general rule, it is the methods that determine how a class data can be used. \\n\\nVariables defined within a class are called instance variables because each instance of the class (that is, each object of the class) contains its own copy of these variables. \\n \\nAll methods have the same general form as main( ), which we have been using thus far. However, most methods will not be specified as static or public. Notice that the general form of a class does not specify a main( ) method. Java classes do not need to have a main( ) method. You only specify one if that class is the starting point for your program. Further, some kinds of Java applications, such as applets, dont require a main( ) method at all. \\n\\nA Simple Class \\n\\nLet’s begin our study of the class with a simple example. Here is a class called Box that defines three instance variables: width, height, and depth. Currently, Box does not contain any methods. \\n\\nclass Box {\\n\\tdouble width;\\n\\tdouble height;\\n\\tdouble depth; \\n} \\n\\nAs stated, a class defines a new type of data. In this case, the new data type is called Box. You will use this name to declare objects of type Box. It is important to remember that a class declaration only creates a template; it does not create an actual object. Thus, the preceding code does not cause any objects of type Box to come into existence. \\n\\nTo actually create a Box object, you will use a statement like the following: \\n\\nBox mybox = new Box(); // create a Box object called mybox \\n\\nAfter this statement executes, mybox will be an instance of Box. Thus, it will have physical reality. \\n\\nDeclaring Objects \\n\\nAs just explained, when you create a class, you are creating a new data type. You can use this type to declare objects of that type. However, obtaining objects of a class is a two-step process. First, you must declare a variable of the class type. This variable does not define an object. Instead, it is simply a variable that can refer to an object. Second, you must acquire an actual, physical copy of the object and assign it to that variable. You can do this using the new operator. The new operator dynamically allocates (that is, allocates at run time) memory for an object and returns a reference to it. This reference is, more or less, the address in memory of the object allocated by new. This reference is then stored in the variable. Thus, in Java, all class objects must be dynamically allocated. Lets look at the details of this procedure. \\n\\nBox mybox = new Box(); \\n\\nThis statement combines the two steps just described. It can be rewritten like this to show each step more clearly: \\n\\nBox mybox; // declare reference to object \\nmybox = new Box(); // allocate a Box object \\n\\nThe first line declares mybox as a reference to an object of type Box. At this point, mybox does not yet refer to an actual object. The next line allocates an object and assigns a reference to it to mybox. After the second line executes, you can use mybox as if it were a Box object. But in reality, mybox simply holds, in essence, the memory address of the actual Box object. \\n\\nA Closer Look at new \\n\\nAs just explained, the new operator dynamically allocates memory for an object. It has this general form: \\n\\nclass-var = new classname ( ); \\n\\nHere, class-var is a variable of the class type being created. The classname is the name of the class that is being instantiated. The class name followed by parentheses specifies the constructor for the class. A constructor defines what occurs when an object of a class is created. Constructors are an important part of all classes and have many significant attributes. Most real-world classes explicitly define their own constructors within their class definition. However, if no explicit constructor is specified, then Java will automatically supply a default constructor. This is the case with Box. For now, we will use the default constructor. \\n\\nLets once again review the distinction between a class and an object. A class creates a new data type that can be used to create objects. That is, a class creates a logical framework that defines the relationship between its members. When you declare an object of a class, you are creating an instance of that class. Thus, a class is a logical construct. An object has physical reality. (That is, an object occupies space in memory.) It is important to keep this distinction clearly in mind. \\n",
117 "22",
118 "CLASSES, declaring member variables",
119 "As mentioned earlier, each time you create an instance of a class, you are creating an object that contains its own copy of each instance variable defined by the class. Thus, every Box object will contain its own copies of the instance variables width, height, and depth. To access these variables, you will use the dot (.) operator. The dot operator links the name of the object with the name of an instance variable. For example, to assign the width variable of mybox the value 100, you would use the following statement: \\n\\nmybox.width = 100; \\n\\nThis statement tells the compiler to assign the copy of width that is contained within the mybox object the value of 100. In general, you use the dot operator to access both the instance variables and the methods within an object. \\n\\nHere is a complete program that uses the Box class: \\n\\nclass Box {\\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n} \\n\\n// This class declares an object of type Box. \\nclass BoxDemo {\\n\\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox = new Box(); \\n\\t\\tdouble vol;\\n\\t\\t// assign values to mybox's instance variables \\n\\t\\tmybox.width = 10; \\n\\t\\tmybox.height = 20; \\n\\t\\tmybox.depth = 15;\\n\\t\\t// compute volume of box \\n\\t\\tvol = mybox.width * mybox.height * mybox.depth;\\n \\t\\tSystem.out.println(\"Volume is \" + vol);\\n \\t} \\n} \\n\\nYou should call the file that contains this program BoxDemo.java, because the main( ) method is in the class called BoxDemo, not the class called Box. When you compile this program, you will find that two .class files have been created, one for Box and one for BoxDemo. The Java compiler automatically puts each class into its own .class file. It is not necessary for both the Box and the BoxDemo class to actually be in the same source file. You could put each class in its own file, called Box.java and BoxDemo.java, respectively. \\n\\nTo run this program, you must execute BoxDemo.class. When you do, you will see the following output:\\n\\nVolume is 3000.0 \\n\\nAs stated earlier, each object has its own copies of the instance variables. This means that if you have two Box objects, each has its own copy of depth, width, and height. It is important to understand that changes to the instance variables of one object have no effect on the instance variables of another. For example, the following program declares two Box objects: \\n\\n// This program declares two Box objects. \\n\\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n} \\n\\nclass BoxDemo2 {\\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box(); \\n\\t\\tdouble vol;\\n\\t\\t// assign values to mybox1's instance variables\\n\\t\\tmybox1.width = 10; \\n\\t\\tmybox1.height = 20; \\n\\t\\tmybox1.depth = 15;\\n\\t\\t/* assign different values to mybox2's\\n\\t\\tinstance variables */ \\n\\t\\tmybox2.width = 3; \\n\\t\\tmybox2.height = 6; \\n\\t\\tmybox2.depth = 9;\\n\\t\\t// compute volume of first box \\n\\t\\tvol = mybox1.width * mybox1.height * mybox1.depth; \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\t\\t// compute volume of second box \\n\\t\\tvol = mybox2.width * mybox2.height * mybox2.depth; \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\t} \\n} \\n\\nThe output produced by this program is shown here:\\n\\nVolume is 3000.0\\nVolume is 162.0 \\n\\nAs you can see, mybox1s data is completely separate from the data contained in mybox2.\\n",
120 "23",
121 "CLASSES, defining methods",
122 "Introducing Methods \\n\\nClasses usually consist of two things: instance variables and methods.There are some fundamentals that you need to learn now so that you can begin to add methods to your classes. \\n\\nThis is the general form of a method: \\n\\ntype name(parameter-list) { \\n\\t// body of method \\n} \\n\\nHere, type specifies the type of data returned by the method. This can be any valid type, including class types that you create. If the method does not return a value, its return type must be void. The name of the method is specified by name. This can be any legal identifier other than those already used by other items within the current scope. The parameter-list is a sequence of type and identifier pairs separated by commas. Parameters are essentially variables that receive the value of the arguments passed to the method when it is called. If the method has no parameters, then the parameter list will be empty. \\n\\nAlthough it is perfectly fine to create a class that contains only data, it rarely happens. Most of the time, you will use methods to access the instance variables defined by the class. In fact, methods define the interface to most classes.\\n\\nLets begin by adding a method to the Box class. So, since the volume of a box is dependent upon the size of the box, it makes sense to have the Box class compute it. To do this, you must add a method to Box, as shown here:\\n\\n// This program includes a method inside the box class. \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth;\\n\\t// display volume of a box\\n\\n\\tvoid volume() { \\n\\t\\tSystem.out.print(\"Volume is \"); \\n\\t\\tSystem.out.println(width * height * depth);\\n\\t} \\n} \\n\\nclass BoxDemo3 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box();\\n\\n\\t\\t// assign values to mybox1's instance variables \\n\\t\\tmybox1.width = 10; \\n\\t\\tmybox1.height = 20; \\n\\t\\tmybox1.depth = 15;\\n\\n\\t\\t/* assign different values to mybox2's\\n\\t\\tinstance variables */ \\n\\t\\tmybox2.width = 3; \\n\\t\\tmybox2.height = 6; \\n\\t\\tmybox2.depth = 9;\\n\\n\\t\\t// display volume of first box \\n\\t\\tmybox1.volume();\\n\\n\\t\\t// display volume of second box \\n\\t\\tmybox2.volume(); \\n\\t} \\n} \\n\\nThis program generates the following output:\\n\\nVolume is 3000.0 \\nVolume is 162.0\\n\\nLook closely at the following two lines of code: \\n\\nmybox1.volume(); \\nmybox2.volume(); \\n\\nThe first line here invokes the volume( ) method on mybox1. That is, it calls volume( ) relative to the mybox1 object, using the objects name followed by the dot operator. Thus, the call to mybox1.volume( ) displays the volume of the box defined by mybox1, and the call to mybox2.volume( ) displays the volume of the box defined by mybox2. Each time volume( ) is invoked, it displays the volume for the specified box. \\n\\nIf you are unfamiliar with the concept of calling a method, the following discussion will help clear things up. When mybox1.volume( ) is executed, the Java run-time system transfers control to the code defined inside volume( ). After the statements inside volume( ) have executed, control is returned to the calling routine, and execution resumes with the line of code following the call. In the most general sense, a method is Java’s way of implementing subroutines.\\n\\nThere is something very important to notice inside the volume( ) method: the instance variables width, height, and depth are referred to directly, without preceding them with an object name or the dot operator. When a method uses an instance variable that is defined by its class, it does so directly, without explicit reference to an object and without use of the dot operator. This is easy to understand if you think about it. A method is always invoked relative to some object of its class. Once this invocation has occurred, the object is known. Thus, within a method, there is no need to specify the object a second time. This means that width, height, and depth inside volume( ) implicitly refer to the copies of those variables found in the object that invokes volume( ). \\n\\nLets review: When an instance variable is accessed by code that is not part of the class in which that instance variable is defined, it must be done through an object, by use of the dot operator. However, when an instance variable is accessed by code that is part of the same class as the instance variable, that variable can be referred to directly. The same thing applies to methods.\\n",
123 "24",
124 "CLASSES, returning a value",
125 "Returning a Value \\n\\nExample:\\n\\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth;\\n\\t// display volume of a box\\n\\n\\tvoid volume() { \\n\\t\\tSystem.out.print(\"Volume is \"); \\n\\t\\tSystem.out.println(width * height * depth);\\n\\t} \\n} \\n\\nclass BoxDemo3 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box();\\n\\n\\t\\t// assign values to mybox1's instance variables\\n \\t\\tmybox1.width = 10; \\n\\t\\tmybox1.height = 20; \\n\\t\\tmybox1.depth = 15;\\n\\n\\t\\t/* assign different values to mybox2's\\n\\t\\tinstance variables */ \\n\\t\\tmybox2.width = 3; \\n\\t\\tmybox2.height = 6; \\n\\t\\tmybox2.depth = 9;\\n\\n\\t\\t// display volume of first box \\n\\t\\tmybox1.volume();\\n\\n\\t\\t// display volume of second box \\n\\t\\tmybox2.volume(); \\n\\t} \\n} \\n\\nWhile the implementation of volume( ) does move the computation of a boxs volume inside the Box class where it belongs, it is not the best way to do it. For example, what if another part of your program wanted to know the volume of a box, but not display its value? A better way to implement volume( ) is to have it compute the volume of the box and return the result to the caller. The following example, an improved version of the preceding program, does just that: \\n\\n// Now, volume() returns the volume of a box. \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth;\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n} \\n\\nclass BoxDemo4 {\\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box(); \\n\\t\\tdouble vol;\\n\\n\\t\\t// assign values to mybox1's instance variables \\n\\t\\tmybox1.width = 10; \\n\\t\\tmybox1.height = 20; \\n\\t\\tmybox1.depth = 15;\\n\\n\\t\\t/* assign different values to mybox2's\\n\\t\\tinstance variables */ \\n\\t\\tmybox2.width = 3; \\n\\t\\tmybox2.height = 6; \\n\\t\\tmybox2.depth = 9;\\n\\n\\t\\t// get volume of first box \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\n\\t\\t// get volume of second box \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\t} \\n}\\n\\nAs you can see, when volume( ) is called, it is put on the right side of an assignment statement. On the left is a variable, in this case vol, that will receive the value returned by volume( ). Thus, after \\n\\nvol = mybox1.volume(); \\n\\nexecutes, the value of mybox1.volume( ) is 3,000 and this value then is stored in vol. There are two important things to understand about returning values: \\n\\n\\t1.The type of data returned by a method must be compatible with the return type specified by the method. For example, if the return type of some method is boolean, you could not return an integer. \\n\\n\\t2.The variable receiving the value returned by a method (such as vol, in this case) must also be compatible with the return type specified for the method. \\n\\nOne more point: The preceding program can be written a bit more efficiently because there is actually no need for the vol variable. The call to volume( ) could have been used in the println( ) statement directly, as shown here: \\n\\nSystem.out.println(\"Volume is\" + mybox1.volume()); \\n\\nIn this case, when println( ) is executed, mybox1.volume( ) will be called automatically and its value will be passed to println( ).\\n",
126 "25",
127 "CLASSES, adding a method that takes a parameter",
128 "Adding a Method That Takes Parameters \\n\\nWhile some methods dont need parameters, most do. Parameters allow a method to be generalized. That is, a parameterized method can operate on a variety of data and/or be used in a number of slightly different situations. To illustrate this point, lets use a very simple example. Here is a method that returns the square of the number 10: \\n\\nint square() \\n{\\n\\treturn 10 * 10; \\n} \\n\\nWhile this method does, indeed, return the value of 10 squared, its use is very limited. However, if you modify the method so that it takes a parameter, as shown next, then you can make square( ) much more useful. \\n\\nint square(int i) \\n{\\n\\teturn i * i; \\n} \\n\\nNow, square( ) will return the square of whatever value it is called with. That is, square( ) is now a general-purpose method that can compute the square of any integer value, rather than just 10. \\n\\nHere is an example: \\n\\nint x, y; \\nx = square(5); // x equals 25 \\nx = square(9); // x equals 81 \\ny = 2; \\nx = square(y); // x equals 4 \\n\\nIn the first call to square( ), the value 5 will be passed into parameter i. In the second call, i will receive the value 9. The third invocation passes the value of y, which is 2 in this example. As these examples show, square( ) is able to return the square of whatever data it is passed. \\n\\nIt is important to keep the two terms parameter and argument straight. A parameter is a variable defined by a method that receives a value when the method is called. For example, in square( ), i is a parameter. An argument is a value that is passed to a method when it is invoked. For example, square(100) passes 100 as an argument. Inside square( ), the parameter i receives that value. \\n",
129 "26",
130 "CLASSES, adding a method that takes parameters",
131 "You can use a parameterized method to improve the Box class. \\nExamples: \\nclass Box {\\n\\tdouble width;\\n\\tdouble height;\\n\\tdouble depth;\\n\\n\\tdouble volume() {\\n\\t\\treturn width * height * depth;\\n\\t}\\n}\\n\\nclass BoxDemo5 {\\n\\tpublic static void main(String args[]) {\\n\\t\\tBox myboxl = new Box();\\n\\t\\tmyboxl.width = 10;\\n\\t\\tmyboxl.height = 20;\\n\\t\\tmyboxl.depth = 15;\\n\\n\\t\\tBox mybox2 = new Box();\\n\\t\\tmybox2.width = 3;\\n\\t\\tmybox2.height = 6;\\n\\t\\tmybox2.depth = 9;\\n\\t\\tdouble vol;\\n\\t\\tvol = myboxl.volume();\\n\\t\\tSystem.out.println(\"Volume = \" + vol);\\n\\n\\t\\tvol = mybox2.volume();\\n\\t\\tSystem.out.println(\"Volume = \" + vol);\\n\\t}\\n}\\n\\nWhile this code works, it is troubling for two reasons. First, it is clumsy and error prone. For example, it would be easy to forget to set a dimension. Second, in well-designed Java programs, instance variables should be accessed only through methods defined by their class. In the future, you can change the behavior of a method, but you cant change the behavior of an exposed instance variable. \\n\\nThus, a better approach to setting the dimensions of a box is to create a method that takes the dimensions of a box in its parameters and sets each instance variable appropriately. This concept is implemented by the following program: \\n\\n// This program uses a parameterized method. \\nclass Box {\\n\\tdouble width;\\n\\tdouble height;\\n\\tdouble depth;\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t}\\n\\n\\t// sets dimensions of box\\n\\tvoid setDim(double w, double h, double d) {\\n\\t\\twidth = w;\\n\\t\\theight = h;\\n\\t\\tdepth = d;\\n\\t} \\n} \\n\\nclass BoxDemo5 { \\n\\n\\tpublic static void main(String args[]) { \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box(); \\n\\t\\tdouble vol;\\n\\n\\t\\t// initialize each box \\n\\t\\tmybox1.setDim(10, 20, 15); \\n\\t\\tmybox2.setDim(3, 6, 9);\\n\\n\\t\\t// get volume of first box \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\n\\t\\t// get volume of second box \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\t} \\n} \\n\\nAs you can see, the setDim( ) method is used to set the dimensions of each box. For example, when \\n\\nmybox1.setDim(10, 20, 15); \\n\\nis executed, 10 is copied into parameter w, 20 is copied into h, and 15 is copied into d. Inside setDim( ) the values of w, h, and d are then assigned to width, height, and depth, respectively. \\n",
132 "27",
133 "CLASSES, static variables",
134 "Understanding static variables\\n\\nThere will be times when you will want to define a class member that will be used independently of any object of that class. Normally, a class member must be accessed only in conjunction with an object of its class. However, it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object.\\n\\nInstance variables declared as static are, essentially, global variables. When objects of its class are declared, no copy of a static variable is made. Instead, all instances of the class share the same static variable.\\n \\nIf you need to do computation in order to initialize your static variables, you can declare a static block that gets executed exactly once, when the class is first loaded. The following example shows a class that has a static method, some static variables, and a static initialization block: \\n\\n// Demonstrate static variables, and blocks. \\nclass UseStatic { \\n\\tstatic int a = 3;\\n \\tstatic int b; \\n\\tstatic { \\n\\t\\tSystem.out.println(\"Static block initialized.\"); \\n\\t\\tb = a * 4; \\n\\t}\\n} \\n\\nAs soon as the UseStatic class is loaded, all of the static statements are run. First, a is set to 3, then the static block executes, which prints a message and then initializes b to a * 4 or 12. Outside of the class in which they are defined, variables can be used independently of any object. To do so, you need only specify the name of their class followed by the dot operator. For example, if you wish to call a static variable from outside its class, you can do so using the following general form:\\n \\nclassname.a\\n\\nHere, classname is the name of the class in which the static variable is declared.\\nThis is how Java implements a controlled version of global variables. \\n\\nHere is an example. Inside main( ) the static variable b are accessed through their class name StaticDemo. \\n\\nclass StaticDemo { \\n\\tstatic int b = 99; \\n}\\n\\nclass StaticByName { \\n\\tpublic static void main(String args[]) {\\n \\t\\tSystem.out.println(\"b = \" + StaticDemo.b); \\n\\t} \\n}\\n\\nHere is the output of this program:\\n\\nb = 99 \\n\\nIntroducing final \\nA variable can be declared as final. Doing so prevents its contents from being modified. \\nThis means that you must initialize a final variable when it is declared. For example:\\n \\nfinal int FILE_NEW = 1; \\nfinal int FILE_OPEN = 2; \\nfinal int FILE_SAVE = 3; \\nfinal int FILE_SAVEAS = 4; \\nfinal int FILE_QUIT = 5;\\n \\nSubsequent parts of your program can now use FILE_OPEN, etc., as if they were constants, without fear that a value has been changed. \\nIt is a common coding convention to choose all uppercase identifiers for final variables. Variables declared as final do not occupy memory on a per-instance basis. Thus, a final variable is essentially a constant. \\n",
135 "28",
136 "CLASSES, static methods",
137 "Understanding static methods\\n\\nYou can declare both methods and variables to be static. The most common example of a static member is main( ). main( ) is declared as static because it must be called before any objects exist. \\n\\nMethods declared as static have several restrictions: \\n• They can only call other static methods. \\n• They must only access static data. \\n• They cannot refer to this or super in any way. \\n\\nThe following example shows a class that has a static method, some static variables, and a static initialization block: \\n\\n// Demonstrate static variables, and blocks. \\nclass UseStatic { \\n\\tstatic int a = 3; \\n\\tstatic int b; \\n\\tstatic void meth(int x) {\\n\\t\\tSystem.out.println(\"meth\");\\n\\t\\tSystem.out.println(\"x = \" + x);\\n\\t\\tSystem.out.println(\"a = \" + a);\\n \\t\\tSystem.out.println(\"b = \" + b);\\n\\t}\\n\\tstatic { \\n\\t\\tSystem.out.println(\"static\");\\n\\t\\tSystem.out.println(\"Static block initialized.\"); \\n\\t\\tb = a * 4; \\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tSystem.out.println(\"main\");\\n\\t\\tmeth(42);\\n\\t}\\n} \\n\\nAs soon as the UseStatic class is loaded, all of the static statements are run. First, a is set to 3, then the static block executes, which prints a message and then initializes b to a * 4 or 12. Then main( ) is called, which calls meth( ), passing 42 to x. The three println( ) statements refer to the two static variables a and b, as well as to the local variable x. \\n\\nHere is the output of the program: \\n\\nStatic block initialized. \\nx = 42 \\na = 3 \\nb = 12 \\n\\nOutside of the class in which they are defined, static methods and variables can be used independently of any object. To do so, you need only specify the name of their class followed by the dot operator. For example, if you wish to call a static method from outside its class, you can do so using the following general form:\\n \\nclassname.method( ) \\n\\nHere, classname is the name of the class in which the static method is declared. As you can see, this format is similar to that used to call non-static methods through object-reference variables.\\n\\nHere is an example. Inside main( ), the static method callme( ) and the static variable b are accessed through their class name StaticDemo. \\n\\nclass StaticDemo { \\n\\tstatic int a = 42; \\n\\tstatic int b = 99; \\n\\tstatic void callme() { \\n\\t\\tSystem.out.println(\"a = \" + a); \\n\\t}\\n}\\n\\nclass StaticByName { \\n\\tpublic static void main(String args[]) { \\n\\t\\tStaticDemo.callme(); \\n\\t\\tSystem.out.println(\"b = \" + StaticDemo.b); \\n\\t} \\n}\\n\\nHere is the output of this program: \\n\\na = 42 \\nb = 99 \\n",
138 "29",
139 "CLASSES, overloading methods",
140 "Overloading Methods\\n\\nIn Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java supports polymorphism. If you have never used a language that allows the overloading of methods, then the concept may seem strange at first. But as you will see, method overloading is one of Javas most exciting and useful features. When an overloaded method is invoked, Java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to actually call. Thus, overloaded methods must differ in the type and/or number of their parameters. While overloaded methods may have different return types, the return type alone is insufficient to distinguish two versions of a method. When Java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call. \\n\\nHere is a simple example that illustrates method overloading: \\n\\n// Demonstrate method overloading. \\nclass OverloadDemo { \\n\\tvoid test() { \\n\\t\\tSystem.out.println(\"No parameters\"); \\n\\t}\\n\\t// Overload test for one integer parameter. \\n\\tvoid test(int a) { \\n\\t\\tSystem.out.println(\"a: \" + a); \\n\\t} \\n\\t// Overload test for two integer parameters. \\n\\tvoid test(int a, int b) { \\n\\t\\tSystem.out.println(\"a and b: \" + a + \" \" + b); \\n\\t}\\n\\t// overload test for a double parameter \\n\\tdouble test(double a) { \\n\\t\\tSystem.out.println(\"double a: \" + a); \\n\\t\\treturn a*a; \\n\\t} \\n}\\n\\nclass Overload { \\n\\tpublic static void main(String args[]) { \\n\\t\\tOverloadDemo ob = new OverloadDemo(); \\n\\t\\tdouble result; \\n\\t\\t// call all versions of test() \\n\\t\\tob.test(); \\n\\t\\tob.test(10); \\n\\t\\tob.test(10, 20); \\n\\t\\tresult = ob.test(123.25); \\n\\t\\tSystem.out.println(\"Result of ob.test(123.25): \" + result); \\n\\t} \\n} \\n\\nThis program generates the following output: \\nNo parameters \\na: 10 \\na and b: 10 20 \\ndouble a: 123.25 \\nResult of ob.test(123.25): 15190.5625\\n\\nAs you can see, test( ) is overloaded four times. The first version takes no parameters, the second takes one integer parameter, the third takes two integer parameters, and the fourth takes one double parameter. The fact that the fourth version of test( ) also returns a value is of no consequence relative to overloading, since return types do not play a role in overload resolution. \\n\\nWhen an overloaded method is called, Java looks for a match between the arguments used to call the method and the methods parameters. However, this match need not always be exact. In some cases, Javas automatic type conversions can play a role in overload resolution. For example, consider the following program: \\n\\n// Automatic type conversions apply to overloading. \\nclass OverloadDemo { \\n\\tvoid test() { \\n\\t\\tSystem.out.println(\"No parameters\"); \\n\\t}\\n\\n\\t// Overload test for two integer parameters. \\n\\tvoid test(int a, int b) { \\n\\t\\tSystem.out.println(\"a and b: \" + a + \" \" + b); \\n\\t}\\n\\t// overload test for a double parameter \\n\\tvoid test(double a) { \\n\\t\\tSystem.out.println(\"Inside test(double) a: \" + a); \\n\\t} \\n}\\n\\nclass Overload { \\n\\tpublic static void main(String args[]) { \\n\\t\\tOverloadDemo ob = new OverloadDemo(); \\n\\t\\tint i = 88; \\n\\t\\tob.test(); \\n\\t\\tob.test(10, 20); \\n\\t\\tob.test(i); // this will invoke test(double) \\n\\t\\tob.test(123.2); // this will invoke test(double) \\n\\t} \\n} \\n\\nThis program generates the following output: \\n\\nNo parameters \\na and b: 10 20 \\nInside test(double) a: 88 \\nInside test(double) a: 123.2 \\n\\nAs you can see, this version of OverloadDemo does not define test(int). Therefore, when test( ) is called with an integer argument inside Overload, no matching method is found. However, Java can automatically convert an integer into a double, and this conversion can be used to resolve the call. Therefore, after test(int) is not found, Java elevates i to double and then calls test(double). Of course, if test(int) had been defined, it would have been called instead. Java will employ its automatic type conversions only if no exact match is found. Method overloading supports polymorphism because it is one way that Java implements the one interface, multiple methods paradigm. To understand how, consider the following. In languages that do not support method overloading, each method must be given a unique name. However, frequently you will want to implement essentially the same method for different types of data. Consider the absolute value function. In languages that do not support overloading, there are usually three or more versions of this function, each with a slightly different name. For instance, in C, the function abs( ) returns the absolute value of an integer, labs( ) returns the absolute value of a long integer, and fabs( ) returns the absolute value of a floating-point value. Since C does not support overloading, each function has to have its own name, even though all three functions do essentially the same thing. This makes the situation more complex, conceptually, than it actually is. Although the underlying concept of each function is the same, you still have three names to remember. This situation does not occur in Java, because each absolute value method can use the same name. Indeed, Javas standard class library includes an absolute value method, called abs( ). This method is overloaded by Javas Math class to handle all numeric types. Java determines which version of abs( ) to call based upon the type of argument. \\n\\nThe value of overloading is that it allows related methods to be accessed by use of a common name. Thus, the name abs represents the general action that is being performed. It is left to the compiler to choose the right specific version for a particular circumstance. You, the programmer, need only remember the general operation being performed. Through the application of polymorphism, several names have been reduced to one. Although this example is fairly simple, if you expand the concept, you can see how overloading can help you manage greater complexity. \\n\\nWhen you overload a method, each version of that method can perform any activity you desire. There is no rule stating that overloaded methods must relate to one another. However, from a stylistic point of view, method overloading implies a relationship. Thus, while you can use the same name to overload unrelated methods, you should not. For example, you could use the name sqr to create methods that return the square of an integer and the square root of a floating-point value. But these two operations are fundamentally different. Applying method overloading in this manner defeats its original purpose. In practice, you should only overload closely related operations. \\n",
141 "30",
142 "CLASSES, the variables in the class can be used by other classes of objects",
143 "The variables in the class can be used by other classes of objects.\\nHere is an example: \\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Nik\";\\n\\t\\tman1.surname = \"Jackson\";\\n\\t\\tPass passport1 = new Pass();\\n\\t\\tpassport1.nom = 254878;\\n\\t\\tman1.pass = passport1;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Jane\";\\n\\t\\tman2.surname = \"Williams\";\\n\\t\\tPass passport2 = new Pass();\\n\\t\\tpassport2.nom = 654856;\\n\\t\\tman2.pass = passport2;\\n\\n\\t\\tSystem.out.println(man1.name + \" \" + man1.surname);\\n\\t\\tSystem.out.println(\" passport â„– \" + man1.pass.nom + \".\");\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(man2.name + \" \" + man2.surname);\\n\\t\\tSystem.out.println(\" passport â„– \" + man2.pass.nom + \".\");\\n\\t}\\n}\\npublic class Man {\\n\\tString name;\\n\\tString surname;\\n\\tPass pass;\\n}\\n\\npublic class Pass { \\n\\tint nom;\\n}\\n\\nOutput:\\n\\nNik Jackson\\npassport â„– 254878.\\n\\nJane Williams\\npassport â„– 654856.\\n\\nTo access Pass variable nom, you will use the dot (.) operator. \\n\\nSystem.out.println(\" passport â„– \" + man1.pass.nom + \".\");\\n",
144 "31",
145 "CLASSES, using objects as parameters",
146 "Using Objects as Parameters \\n\\nSo far, we have only been using simple types as parameters to methods. However, it is both correct and common to pass objects to methods. For example, consider the following short program: \\n\\n// Objects may be passed to methods. \\nclass Test { \\n\\tint a, b; \\n\\tTest(int i, int j) { \\n\\t\\ta = i; \\n\\t\\tb = j; \\n\\t}\\n\\t// return true if o is equal to the invoking object \\n\\tboolean equals(Test o) { \\n\\t\\tif(o.a == a && o.b == b) return true; \\n\\t\\telse return false; \\n\\t} \\n}\\n\\nclass PassOb { \\n\\tpublic static void main(String args[]) { \\n\\t\\tTest ob1 = new Test(100, 22); \\n\\t\\tTest ob2 = new Test(100, 22); \\n\\t\\tTest ob3 = new Test(-1, -1); \\n\\t\\tSystem.out.println(\"ob1 == ob2: \" + ob1.equals(ob2)); \\n\\t\\tSystem.out.println(\"ob1 == ob3: \" + ob1.equals(ob3)); \\n\\t} \\n}\\n\\nThis program generates the following output: \\nob1 == ob2: true \\nob1 == ob3: false \\n\\nAs you can see, the equals( ) method inside Test compares two objects for equality and returns the result. That is, it compares the invoking object with the one that it is passed. If they contain the same values, then the method returns true. Otherwise, it returns false. Notice that the parameter o in equals( ) specifies Test as its type. Although Test is a class type created by the program, it is used in just the same way as Javas built-in types. \\n",
147 "32",
148 "CLASSES, constructors",
149 "Constructors \\n\\nIt can be tedious to initialize all of the variables in a class each time an instance is created. Even when you add convenience functions, it would be simpler and more concise to have all of the setup done at the time the object is first created. Because the requirement for initialization is so common, Java allows objects to initialize themselves when they are created. This automatic initialization is performed through the use of a constructor. A constructor initializes an object immediately upon creation. It has the same name as the class in which it resides and is syntactically similar to a method. Once defined, the constructor is automatically called immediately after the object is created, before the new operator completes. Constructors look a little strange because they have no return type, not even void. This is because the implicit return type of a class constructor is the class type itself. It is the constructors job to initialize the internal state of an object so that the code creating an instance will have a fully initialized, usable object immediately.\\n\\n/* Here, Box uses a constructor to initialize the \\ndimensions of a box. \\n*/ \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n\\t// This is the constructor for Box. \\n\\tBox() { \\n\\t\\tSystem.out.println(\"Constructing Box\"); \\n\\t\\twidth = 10; \\n\\t\\theight = 10; \\n\\t\\tdepth = 10; \\n\\t}\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\nclass BoxDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// declare, allocate, and initialize Box objects \\n\\t\\tBox mybox1 = new Box(); \\n\\t\\tBox mybox2 = new Box(); \\n\\t\\tdouble vol; \\n\\t\\t// get volume of first box \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol); \\n\\t\\t// get volume of second box \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol); \\n\\t\\t} \\n}\\n\\nWhen this program is run, it generates the following results: \\n\\nConstructing Box \\nConstructing Box \\nVolume is 1000.0 \\nVolume is 1000.0 \\n\\nAs you can see, both mybox1 and mybox2 were initialized by the Box( ) constructor when they were created. Since the constructor gives all boxes the same dimensions, 10 by 10 by 10, both mybox1 and mybox2 will have the same volume. The println( ) statement inside Box( ) is for the sake of illustration only. Most constructors will not display anything. They will simply initialize an object. \\n\\nBefore moving on, lets reexamine the new operator. As you know, when you allocate an object, you use the following general form: \\n\\nclass-var = new classname( ); \\n\\nNow you can understand why the parentheses are needed after the class name. What is actually happening is that the constructor for the class is being called. Thus, in the line\\n \\nBox mybox1 = new Box(); \\n\\nnew Box( ) is calling the Box( ) constructor. When you do not explicitly define a constructor for a class, then Java creates a default constructor for the class. This is why the preceding line of code worked in earlier versions of Box that did not define a constructor. The default constructor automatically initializes all instance variables to zero. The default constructor is often sufficient for simple classes, but it usually wont do for more sophisticated ones. Once you define your own constructor, the default constructor is no longer used. \\n",
150 "33",
151 "CLASSES, parameterized constructors, using 'this'",
152 "Parameterized Constructors \\n\\nWhile the Box( ) constructor in the preceding example does initialize a Box object, it is not very useful—all boxes have the same dimensions. What is needed is a way to construct Box objects of various dimensions. The easy solution is to add parameters to the constructor. As you can probably guess, this makes them much more useful. For example, the following version of Box defines a parameterized constructor that sets the dimensions of a box as specified by those parameters. Pay special attention to how Box objects are created.\\n \\n/* Here, Box uses a parameterized constructor to \\ninitialize the dimensions of a box. \\n*/ \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n\\t// This is the constructor for Box. \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t}\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\nclass BoxDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// declare, allocate, and initialize Box objects \\n\\t\\tBox mybox1 = new Box(10, 20, 15); \\n\\t\\tBox mybox2 = new Box(3, 6, 9); \\n\\t\\tdouble vol; \\n\\t\\t// get volume of first box \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol); \\n\\t\\t// get volume of second box \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume is \" + vol);\\n\\t} \\n}\\n\\nThe output from this program is shown here: \\nVolume is 3000.0 \\nVolume is 162.0\\n \\nAs you can see, each object is initialized as specified in the parameters to its constructor. \\nFor example, in the following line, \\n\\nBox mybox1 = new Box(10, 20, 15); \\n\\nthe values 10, 20, and 15 are passed to the Box( ) constructor when new creates the object. Thus, mybox1s copy of width, height, and depth will contain the values 10, 20, and 15, respectively. \\n\\nThe this Keyword \\n\\nSometimes a method will need to refer to the object that invoked it. To allow this, Java defines the this keyword. this can be used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked. You can use this anywhere a reference to an object of the current class type is permitted. To better understand what this refers to, consider the following example: \\n\\n// A redundant use of this. \\nBox(double w, double h, double d) { \\n\\tthis.width = w; \\n\\tthis.height = h; \\n\\tthis.depth = d; \\n}\\n\\nThis version of Box( ) operates exactly like the earlier version. The use of this is redundant, but perfectly correct. Inside Box( ), this will always refer to the invoking object. While it is redundant in this case, this is useful in other contexts. \\n",
153 "34",
154 "CLASSES, overloading constructors",
155 "Overloading Constructors \\n\\nIn addition to overloading normal methods, you can also overload constructor methods. In fact, for most real-world classes that you create, overloaded constructors will be the norm, not the exception. \\nFor example, consider the following program:\\n \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n\\t// This is the constructor for Box. \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t}\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n} \\n\\nAs you can see, the Box( ) constructor requires three parameters. This means that all declarations of Box objects must pass three arguments to the Box( ) constructor. For example, the following statement is currently invalid: \\n\\nBox ob = new Box(); \\n\\nSince Box( ) requires three arguments, its an error to call it without them. This raises some important questions. What if you simply wanted a box and did not care (or know) what its initial dimensions were? Or, what if you want to be able to initialize a cube by specifying only one value that would be used for all three dimensions? As the Box class is currently written, these other options are not available to you. Fortunately, the solution to these problems is quite easy: simply overload the Box constructor so that it handles the situations just described. Here is a program that contains an improved version of Box that does just that: \\n\\n/* Here, Box defines three constructors to initialize \\nthe dimensions of a box various ways. \\n*/ \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n\\t// constructor used when all dimensions specified \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\t}\\n\\n\\t// constructor used when no dimensions specified\\n \\tBox() { \\n\\t\\twidth = -1; // use -1 to indicate \\n\\t\\theight = -1; // an uninitialized \\n\\t\\tdepth = -1; // box \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBox(double len) { \\n\\t\\twidth = height = depth = len; \\n\\t}\\n\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\nclass OverloadCons { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// create boxes using the various constructors \\n\\t\\tBox mybox1 = new Box(10, 20, 15); \\n\\t\\tBox mybox2 = new Box(); \\n\\t\\tBox mycube = new Box(7); \\n\\t\\tdouble vol;\\n\\t\\t// get volume of first box \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox1 is \" + vol); \\n\\t\\t// get volume of second box \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox2 is \" + vol); \\n\\t\\t// get volume of cube \\n\\t\\tvol = mycube.volume(); \\n\\t\\tSystem.out.println(\"Volume of mycube is \" + vol); \\n\\t} \\n} \\n\\nThe output produced by this program is shown here: \\n\\nVolume of mybox1 is 3000.0 \\nVolume of mybox2 is -1.0 \\nVolume of mycube is 343.0 \\n\\nAs you can see, the proper overloaded constructor is called based upon the parameters \\nspecified when new is executed.\\n",
156 "35",
157 "CLASSES, a closer look at argument passing",
158 "A Closer Look at Argument Passing \\n\\nIn general, there are two ways that a computer language can pass an argument to a subroutine. The first way is call-by-value. This approach copies the value of an argument into the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect on the argument. The second way an argument can be passed is call-by-reference. In this approach, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine. As you will see, Java uses both approaches, depending upon what is passed. In Java, when you pass a primitive type to a method, it is passed by value. Thus, what occurs to the parameter that receives the argument has no effect outside the method. For example, consider the following program: \\n\\n// Primitive types are passed by value. \\nclass Test { \\n\\tvoid meth(int i, int j) { \\n\\t\\ti *= 2; \\n\\t\\tj /= 2; \\n\\t} \\n}\\n\\nclass CallByValue { \\n\\tpublic static void main(String args[]) { \\n\\t\\tTest ob = new Test(); \\n\\t\\tint a = 15, b = 20; \\n\\t\\tSystem.out.println(\"a and b before call: \" + \\n\\t\\ta + \" \" + b); \\n\\t\\tob.meth(a, b); \\n\\t\\tSystem.out.println(\"a and b after call: \" + \\n\\t\\ta + \" \" + b); \\n\\t} \\n} \\n\\nThe output from this program is shown here: \\na and b before call: 15 20 \\na and b after call: 15 20 \\n\\nAs you can see, the operations that occur inside meth( ) have no effect on the values of a and b used in the call; their values here did not change to 30 and 10. \\n\\nWhen you pass an object to a method, the situation changes dramatically, because objects are passed by what is effectively call-by-reference. Keep in mind that when you create a variable of a class type, you are only creating a reference to an object. Thus, when you pass this reference to a method, the parameter that receives it will refer to the same object as that referred to by the argument. This effectively means that objects are passed to methods by use of call-by-reference. Changes to the object inside the method do affect the object used as an argument. For example, consider the following program: \\n\\n// Objects are passed by reference. \\nclass Test { \\n\\tint a, b; \\n\\tTest(int i, int j) { \\n\\t\\ta = i; \\n\\t\\tb = j; \\n\\t}\\n\\n\\t// pass an object \\n\\tvoid meth(Test o) { \\n\\t\\to.a *= 2;\\n\\t\\to.b /= 2; \\n\\t} \\n}\\n\\nclass CallByRef { \\n\\tpublic static void main(String args[]) { \\n\\t\\tTest ob = new Test(15, 20); \\n\\t\\tSystem.out.println(\"ob.a and ob.b before call: \" + \\n\\t\\tob.a + \" \" + ob.b); \\n\\t\\tob.meth(ob); \\n\\t\\tSystem.out.println(\"ob.a and ob.b after call: \" + \\n\\t\\tob.a + \" \" + ob.b); \\n\\t} \\n} \\n\\nThis program generates the following output: \\nob.a and ob.b before call: 15 20 \\nob.a and ob.b after call: 30 10 \\n \\nAs you can see, in this case, the actions inside meth( ) have affected the object used as an argument.\\n",
159 "36",
160 "CLASSES, getters and setters",
161 "Fields should be declared private unless there is a good reason for not doing so.\\nWhen a field is private, the caller cannot usually get inappropriate direct access to the field.\\nGetter() - special method to get the data, accessed directly limited.\\nSetter() - special method to change the data, accessed directly limited.\\n\\nFor example, consider the following program: \\n\\npublic class Home {\\n\\n\\tprivate String street;\\n\\tprivate int korpus;\\n\\tprivate int flat;\\n\\n\\tpublic void setstreet(String s) {\\n\\t\\tthis.street = s;\\n\\t}\\n\\n\\tpublic String getstreet() {\\n\\t\\treturn street;\\n\\t}\\n\\n\\tpublic void setkorpus(int k) {\\n\\t\\tthis.korpus = k;\\n\\t}\\n\\n\\tpublic int getkorpus() {\\n\\t\\treturn korpus;\\n\\t}\\n\\n\\tpublic void setflat(int f) {\\n\\t\\tthis.flat = f;\\n\\t}\\n\\n\\tpublic int getflat() {\\n\\t\\treturn flat;\\n\\t}\\n}\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHome home1 = new Home();\\n\\t\\thome1.setstreet(\"7 avenue\");\\n\\t\\thome1.setkorpus(2);\\n\\t\\thome1.setflat(23);\\n\\n\\t\\tSystem.out.println(\"street: \" + home1.getstreet());\\n\\t\\tSystem.out.println(\"house: \" + home1.getkorpus());\\n\\t\\tSystem.out.println(\"flat: \" + home1.getflat());\\n\\t}\\n}\\n\\n\\nThis program generates the following output:\\n\\nstreet: 7 avenue\\nhouse: 2\\nflat: 23\\n",
162 "37",
163 "CLASSES, variable-length arguments",
164 "Varargs: Variable-Length Arguments\\n\\nA method that takes a variable number of arguments is called a variable-arity method, or simply a varargs method. Situations that require that a variable number of arguments be passed to a method are not unusual. For example, a method that opens an Internet connection might take a user name, password, filename, protocol, and so on, but supply defaults if some of this information is not provided. In this situation, it would be convenient to pass only the arguments to which the defaults did not apply. \\n\\nPrior to JDK 5, variable-length arguments could be handled two ways, neither of which was particularly pleasing. First, if the maximum number of arguments was small and known, then you could create overloaded versions of the method, one for each way the method could be called. Although this works and is suitable for some cases, it applies to only a narrow class of situations. \\n\\nIn cases where the maximum number of potential arguments was larger, or unknowable, a second approach was used in which the arguments were put into an array, and then the array was passed to the method. This approach is illustrated by the following program:\\n \\n// Use an array to pass a variable number of \\n// arguments to a method. This is the old-style \\n// approach to variable-length arguments. \\nclass PassArray { \\n\\tstatic void vaTest(int v[]) { \\n\\t\\tSystem.out.print(Number of args: + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(int x : v) \\n\\t\\tSystem.out.print(x + \" \");\\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tpublic static void main(String args[]) { \\n\\t\\t// Notice how an array must be created to \\n\\t\\t// hold the arguments. \\n\\t\\tint n1[] = { 10 }; \\n\\t\\tint n2[] = { 1, 2, 3 }; \\n\\t\\tint n3[] = { }; \\n\\t\\tvaTest(n1); // 1 arg \\n\\t\\tvaTest(n2); // 3 args \\n\\t\\tvaTest(n3); // no args \\n\\t} \\n}\\n\\nThe output from the program is shown here: \\nNumber of args: 1 Contents: 10 \\nNumber of args: 3 Contents: 1 2 3 \\nNumber of args: 0 Contents: \\n\\nIn the program, the method vaTest( ) is passed its arguments through the array v. This old-style approach to variable-length arguments does enable vaTest( ) to take an arbitrary number of arguments. However, it requires that these arguments be manually packaged into an array prior to calling vaTest( ). Not only is it tedious to construct an array each time vaTest( ) is called, it is potentially error-prone. The varargs feature offers a simpler, better option. \\n\\nAvariable-length argument is specified by three periods (…). For example, here is how vaTest( ) is written using a vararg: \\n\\nstatic void vaTest(int … v) { \\n\\nThis syntax tells the compiler that vaTest( ) can be called with zero or more arguments. As a result, v is implicitly declared as an array of type int[ ]. Thus, inside vaTest( ), v is accessed using the normal array syntax. Here is the preceding program rewritten using a vararg:\\n \\n// Demonstrate variable-length arguments. \\nclass VarArgs { \\n\\t// vaTest() now uses a vararg. \\n\\tstatic void vaTest(int … v) { \\n\\t\\tSystem.out.print(\"Number of args: \" + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(int x : v) \\n\\t\\t\\tSystem.out.print(x + \" \"); \\n\\t\\tSystem.out.println(); \\n\\t}\\n\\tpublic static void main(String args[]){\\n\\t\\t// Notice how vaTest() can be called with a\\n \\t\\t// variable number of arguments. \\n\\t\\tvaTest(10); // 1 arg \\n\\t\\tvaTest(1, 2, 3); // 3 args \\n\\t\\tvaTest(); // no args \\n\\t} \\n}\\n\\nThe output from the program is the same as the original version.\\n \\nThere are two important things to notice about this program. First, as explained, inside vaTest( ), v is operated on as an array. This is because v is an array. The … syntax simply tells the compiler that a variable number of arguments will be used, and that these arguments will be stored in the array referred to by v. Second, in main( ), vaTest( ) is called with different numbers of arguments, including no arguments at all. The arguments are automatically put in an array and passed to v. In the case of no arguments, the length of the array is zero. Amethod can have normal parameters along with a variable-length parameter. However, the variable-length parameter must be the last parameter declared by the method. For example, this method declaration is perfectly acceptable: \\n\\nint doIt(int a, int b, double c, int … vals) { \\n\\nIn this case, the first three arguments used in a call to doIt( ) are matched to the first three parameters. Then, any remaining arguments are assumed to belong to vals. Remember, the varargs parameter must be last. For example, the following declaration is incorrect: \\n\\nint doIt(int a, int b, double c, int … vals, boolean stopFlag) { // Error! \\n\\nHere, there is an attempt to declare a regular parameter after the varargs parameter, which is illegal. There is one more restriction to be aware of: there must be only one varargs parameter. For example, this declaration is also invalid: \\n\\nint doIt(int a, int b, double c, int … vals, double … morevals) { // Error!\\n \\nThe attempt to declare the second varargs parameter is illegal. Here is a reworked version of the vaTest( ) method that takes a regular argument and a variable-length argument: \\n\\n// Use varargs with standard arguments. \\nclass VarArgs2 { \\n\\t// Here, msg is a normal parameter and v is a \\n\\t// varargs parameter. \\n\\tstatic void vaTest(String msg, int … v) { \\n\\t\\tSystem.out.print(msg + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(int x : v) \\n\\t\\t\\tSystem.out.print(x + \" \"); \\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tpublic static void main(String args[]){ \\n\\t\\tvaTest(\"One vararg: \", 10); \\n\\t\\tvaTest(\"Three varargs: \", 1, 2, 3); \\n\\t\\tvaTest(\"No varargs: \"); \\n\\t} \\n}\\n\\nThe output from this program is shown here: \\n\\nOne vararg: 1 Contents: 10 \\nThree varargs: 3 Contents: 1 2 3 \\nNo varargs: 0 Contents: \\n",
165 "38",
166 "CLASSES, overloading vararg methods",
167 "Overloading Vararg Methods \\n\\nYou can overload a method that takes a variable-length argument. For example, the following program overloads vaTest( ) three times: \\n\\n// Varargs and overloading. \\nclass VarArgs3 { \\n\\tstatic void vaTest(int … v) { \\n\\t\\tSystem.out.print(\"vaTest(int …): \" + \\n\\t\\t\"Number of args: \" + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(int x : v) \\n\\t\\t\\tSystem.out.print(x + \" \"); \\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tvoid vaTest(boolean … v) { \\n\\t\\tSystem.out.print(\"vaTest(boolean …) \" + \\n\\t\\t\"Number of args: \" + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(boolean x : v) \\n\\t\\t\\tSystem.out.print(x + \" \"); \\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tstatic void vaTest(String msg, int … v) { \\n\\t\\tSystem.out.print(\"vaTest(String, int …): \" + \\n\\t\\tmsg + v.length + \\n\\t\\t\" Contents: \"); \\n\\t\\tfor(int x : v) \\n\\t\\t\\tSystem.out.print(x + \" \"); \\n\\t\\tSystem.out.println(); \\t}\\n \\n\\tpublic static void main(String args[]){ \\n\\t\\tvaTest(1, 2, 3); \\n\\t\\tvaTest(\"Testing: \", 10, 20); \\n\\t\\tvaTest(true, false, false); \\n\\t} \\n}\\n\\nThe output produced by this program is shown here: \\nvaTest(int …): Number of args: 3 Contents: 1 2 3 \\nvaTest(String, int …): Testing: 2 Contents: 10 20 \\nvaTest(boolean …) Number of args: 3 Contents: true false false \\n\\nThis program illustrates both ways that a varargs method can be overloaded. First, the types of its vararg parameter can differ. This is the case for vaTest(int …) and vaTest(boolean …). Remember, the … causes the parameter to be treated as an array of the specified type. Therefore, just as you can overload methods by using different types of array parameters, you can overload vararg methods by using different types of varargs. In this case, Java uses the type difference to determine which overloaded method to call.\\n \\nThe second way to overload a varargs method is to add a normal parameter. This is what was done with vaTest(String, int …). In this case, Java uses both the number of arguments and the type of the arguments to determine which method to call. \\n\\nA varargs method can also be overloaded by a non-varargs method. For example, vaTest(int x) is a valid overload of vaTest( ) in the foregoing program. This version is invoked only when one int argument is present. When two or more int arguments are passed, the varargs version vaTest(int…v) is used.\\n",
168 "39",
169 "CLASSES, nested and inner classes",
170 "Introducing Nested and Inner Classes\\n \\nIt is possible to define a class within another class; such classes are known as nested classes. The scope of a nested class is bounded by the scope of its enclosing class. Thus, if class B is defined within class A, then B does not exist independently of A. A nested class has access to the members, including private members, of the class in which it is nested. However, the enclosing class does not have access to the members of the nested class. A nested class that is declared directly within its enclosing class scope is a member of its enclosing class. It is also possible to declare a nested class that is local to a block.\\n \\nThere are two types of nested classes: static and non-static. A static nested class is one that has the static modifier applied. Because it is static, it must access the members of its enclosing class through an object. That is, it cannot refer to members of its enclosing class directly. Because of this restriction, static nested classes are seldom used. The most important type of nested class is the inner class. An inner class is a non-static nested class. It has access to all of the variables and methods of its outer class and may refer to them directly in the same way that other non-static members of the outer class do. The following program illustrates how to define and use an inner class. The class named Outer has one instance variable named outer_x, one instance method named test( ), and defines one inner class called Inner. \\n\\n// Demonstrate an inner class. \\nclass Outer { \\n\\tint outer_x = 100; \\n\\tvoid test() { \\n\\t\\tInner inner = new Inner(); \\n\\t\\tinner.display(); \\n\\t}\\n\\t// this is an inner class \\n\\tclass Inner { \\n\\t\\tvoid display() { \\n\\t\\t\\tSystem.out.println(\"display: outer_x = \" + outer_x); \\n\\t\\t} \\n\\t} \\n}\\n\\nclass InnerClassDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tOuter outer = new Outer(); \\n\\t\\touter.test(); \\n\\t} \\n} \\n\\nOutput from this application is shown here: \\ndisplay: outer_x = 100 \\n\\nIn the program, an inner class named Inner is defined within the scope of class Outer. Therefore, any code in class Inner can directly access the variable outer_x. An instance method named display( ) is defined inside Inner. This method displays outer_x on the standard output stream. The main( ) method of InnerClassDemo creates an instance of class Outer and invokes its test( ) method. That method creates an instance of class Inner and the display( ) method is called. \\nIt is important to realize that an instance of Inner can be created only within the scope of class Outer. The Java compiler generates an error message if any code outside of class Outer attempts to instantiate class Inner. (In general, an inner class instance must be created by an enclosing scope.) You can, however, create an instance of Inner outside of Outer by qualifying its name with Outer, as in Outer.Inner. \\nAs explained, an inner class has access to all of the members of its enclosing class, but the reverse is not true. Members of the inner class are known only within the scope of the inner class and may not be used by the outer class. For example, \\n\\n// This program will not compile. \\nclass Outer { \\n\\tint outer_x = 100; \\n\\tvoid test() { \\n\\t\\tInner inner = new Inner(); \\n\\t\\tinner.display(); \\n\\t}\\n\\t// this is an inner class\\n \\n\\tclass Inner { \\n\\t\\tint y = 10; // y is local to Inner \\n\\t\\tvoid display() { \\n\\t\\t\\tSystem.out.println(\"display: outer_x = \" + outer_x); \\n\\t\\t} \\n\\t}\\n\\tvoid showy() { \\n\\t\\tSystem.out.println(y); // error, y not known here!\\n\\t} \\n}\\n\\nclass InnerClassDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tOuter outer = new Outer(); \\n\\t\\touter.test(); \\n\\t} \\n}\\n \\nHere, y is declared as an instance variable of Inner. Thus, it is not known outside of that class and it cannot be used by showy( ). \\nAlthough we have been focusing on inner classes declared as members within an outer class scope, it is possible to define inner classes within any block scope. For example, you can define a nested class within the block defined by a method or even within the body of a for loop, as this next program shows.\\n \\n// Define an inner class within a for loop. \\nclass Outer { \\n\\tint outer_x = 100; \\n\\tvoid test() { \\n\\t\\tfor(int i=0; i<10; i++) { \\n\\t\\t\\tclass Inner { \\n\\t\\t\\t\\tvoid display() { \\n\\t\\t\\t\\t\\tSystem.out.print(\"display: outer_x = \");\\n\\t\\t\\t\\t\\tSystem.out.println(outer_x); \\n\\t\\t\\t\\t} \\n\\t\\t\\t}\\n\\t\\t\\tInner inner = new Inner(); \\n\\t\\t\\tinner.display(); \\n\\t\\t} \\n\\t} \\n}\\n\\nclass InnerClassDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tOuter outer = new Outer(); \\n\\t\\touter.test(); \\n\\t} \\n} \\n\\nThe output from this version of the program is shown here. \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\ndisplay: outer_x = 100 \\n",
171 "40",
172 "INHERITANCE, some examples",
173 "Inheritance\\n \\nInheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications. Using inheritance, you can create a general class that defines traits common to a set of related items. This class can then be inherited by other, more specific classes, each adding those things that are unique to it. In the terminology of Java, a class that is inherited is called a superclass. The class that does the inheriting is called a subclass. Therefore, a subclass is a specialized version of a superclass. It inherits all of the instance variables and methods defined by the superclass and adds its own, unique elements. \\n\\nInheritance Basics \\n\\nTo inherit a class, you simply incorporate the definition of one class into another by using the extends keyword. To see how, lets begin with a short example. The following program creates a superclass called A and a subclass called B. Notice how the keyword extends is used to create a subclass of A. \\n\\n// A simple example of inheritance. \\n// Create a superclass. \\nclass A { \\n\\tint i, j; \\n\\tvoid showij() { \\n\\t\\tSystem.out.println(\"i and j: \" + i + \" \" + j); \\n\\t} \\n}\\n\\n// Create a subclass by extending class A. \\nclass B extends A { \\n\\tint k; \\n\\tvoid showk() { \\n\\t\\tSystem.out.println(\"k: \" + k); \\n\\t}\\n\\tvoid sum() { \\n\\t\\tSystem.out.println(\"i+j+k: \" + (i+j+k)); \\n\\t} \\n} \\n\\nclass SimpleInheritance { \\n\\tpublic static void main(String args[]) { \\n\\t\\tA superOb = new A(); \\n\\t\\tB subOb = new B(); \\n\\t\\t// The superclass may be used by itself. \\n\\t\\tsuperOb.i = 10; \\n\\t\\tsuperOb.j = 20; \\n\\t\\tSystem.out.println(\"Contents of superOb: \"); \\n\\t\\tsuperOb.showij(); \\n\\t\\tSystem.out.println(); \\n\\t\\t/* The subclass has access to all public members of \\n\\t\\tits superclass. */ \\n\\t\\tsubOb.i = 7; \\n\\t\\tsubOb.j = 8; \\n\\t\\tsubOb.k = 9; \\n\\t\\tSystem.out.println(\"Contents of subOb: \"); \\n\\t\\tsubOb.showij(); \\n\\t\\tsubOb.showk(); \\n\\t\\tSystem.out.println(); \\n\\t\\tSystem.out.println(\"Sum of i, j and k in subOb:\"); \\n\\t\\tsubOb.sum(); \\n\\t} \\n}\\n The output from this program is shown here: \\nContents of superOb: \\ni and j: 10 20 \\nContents of subOb: \\ni and j: 7 8 \\nk: 9 \\nSum of i, j and k in subOb: \\ni+j+k: 24 \\n\\nAs you can see, the subclass B includes all of the members of its superclass, A. This is why subOb can access i and j and call showij( ). Also, inside sum( ), i and j can be referred to directly, as if they were part of B. \\n\\nEven though A is a superclass for B, it is also a completely independent, stand-alone class. Being a superclass for a subclass does not mean that the superclass cannot be used by itself. Further, a subclass can be a superclass for another subclass. \\n\\nThe general form of a class declaration that inherits a superclass is shown here:\\n \\nclass subclass-name extends superclass-name { \\n\\t// body of class \\n} \\n\\nYou can only specify one superclass for any subclass that you create. Java does not support the inheritance of multiple superclasses into a single subclass. You can, as stated, create a hierarchy of inheritance in which a subclass becomes a superclass of another subclass. However, no class can be a superclass of itself. \\n\\nAlthough a subclass includes all of the members of its superclass, it cannot access those members of the superclass that have been declared as private. For example, consider the following simple class hierarchy:\\n \\n/* In a class hierarchy, private members remain \\nprivate to their class. \\nThis program contains an error and will not \\ncompile. \\n*/ \\n// Create a superclass. \\nclass A { \\n\\tint i; // public by default \\n\\tprivate int j; // private to A \\n\\tvoid setij(int x, int y) { \\n\\t\\ti = x; \\n\\t\\tj = y; \\n\\t} \\n}\\n\\n// A's j is not accessible here. \\nclass B extends A { \\n\\tint total; \\n\\tvoid sum() { \\n\\t\\ttotal = i + j; // ERROR, j is not accessible here \\n\\t} \\n}\\n\\nclass Access { \\n\\tpublic static void main(String args[]) { \\n\\t\\tB subOb = new B(); \\n\\t\\tsubOb.setij(10, 12); \\n\\t\\tsubOb.sum(); \\n\\t\\tSystem.out.println(\"Total is \" + subOb.total); \\n\\t} \\n}\\n \\nThis program will not compile because the reference to j inside the sum( ) method of B causes an access violation. Since j is declared as private, it is only accessible by other members of its own class. Subclasses have no access to it. \\n\\nLets look at a more practical example that will help illustrate the power of inheritance. Here, the final version of the Box class developed in the preceding chapter will be extended to include a fourth component called weight. Thus, the new class will contain a boxs width, height, depth, and weight. \\n\\n// This program uses inheritance to extend Box. \\nclass Box { \\n\\tdouble width; \\n\\tdouble height; \\n\\tdouble depth; \\n\\n\\t// construct clone of an object \\n\\tBox(Box ob) { // pass object to constructor \\n\\t\\twidth = ob.width;\\n \\t\\theight = ob.height; \\n\\t\\tdepth = ob.depth; \\n\\t}\\n\\n\\t// constructor used when all dimensions specified \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t}\\n\\n\\t// constructor used when no dimensions specified \\n\\tBox() { \\n\\t\\twidth = -1; // use -1 to indicate \\n\\t\\theight = -1; // an uninitialized \\n\\t\\tdepth = -1; // box \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBox(double len) { \\n\\t\\twidth = height = depth = len; \\n\\t}\\n\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\n// Here, Box is extended to include weight. \\nclass BoxWeight extends Box { \\n\\tdouble weight; // weight of box \\n\\t// constructor for BoxWeight \\n\\tBoxWeight(double w, double h, double d, double m) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t\\tweight = m; \\n\\t} \\n}\\n\\nclass DemoBoxWeight { \\n\\tpublic static void main(String args[]) { \\n\\t\\tBoxWeight mybox1 = new BoxWeight(10, 20, 15, 34.3); \\n\\t\\tBoxWeight mybox2 = new BoxWeight(2, 3, 4, 0.076); \\n\\t\\tdouble vol; \\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox1 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mybox1 is \" + mybox1.weight); \\n\\t\\tSystem.out.println(); \\n\\t\\tvol = mybox2.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox2 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mybox2 is \" + mybox2.weight); \\n\\t} \\n}\\n \\nThe output from this program is shown here: \\nVolume of mybox1 is 3000.0 \\nWeight of mybox1 is 34.3 \\nVolume of mybox2 is 24.0 \\nWeight of mybox2 is 0.076\\n \\nBoxWeight inherits all of the characteristics of Box and adds to them the weight component. It is not necessary for BoxWeight to re-create all of the features found in Box. It can simply extend Box to meet its own purposes. Amajor advantage of inheritance is that once you have created a superclass that defines the attributes common to a set of objects, it can be used to create any number of more specific subclasses. Each subclass can precisely tailor its own classification. For example, the following class inherits Box and adds a color attribute:\\n \\n// Here, Box is extended to include color. \\nclass ColorBox extends Box { \\n\\tint color; // color of box \\n\\tColorBox(double w, double h, double d, int c) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t\\tcolor = c; \\n\\t} \\n}\\n\\nRemember, once you have created a superclass that defines the general aspects of an object, that superclass can be inherited to form specialized classes. Each subclass simply adds its own unique attributes. This is the essence of inheritance. \\n",
174 "41",
175 "INHERITANCE, a superclass variable can reference a subclass object",
176 "A Superclass Variable Can Reference a Subclass Object \\n\\nAreference variable of a superclass can be assigned a reference to any subclass derived from that superclass. You will find this aspect of inheritance quite useful in a variety of situations. For example, consider the following: \\n\\nclass Box{\\n\\tdouble width;\\n\\tdouble height;\\n\\tdouble depth;\\n\\tdouble volume(){\\n\\t\\treturn width * height * depth;\\n\\t}\\n}\\n\\nclass BoxWeight extends Box {\\n\\tdouble weight; \\n\\tBoxWeight(double w, double h, double d, double m) {\\n\\t\\twidth = w;\\n\\t\\theight = h;\\n\\t\\tdepth = d;\\n\\t\\tweight = m;\\n\\t}\\n}\\n\\nclass RefDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tBoxWeight weightbox = new BoxWeight(3, 5, 7, 8.37);\\n \\t\\tBox plainbox = new Box(); \\n\\t\\tdouble vol; \\n\\t\\tvol = weightbox.volume(); \\n\\t\\tSystem.out.println(\"Volume of weightbox is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of weightbox is \" + \\n\\t\\tweightbox.weight); \\n\\t\\tSystem.out.println(); \\n\\t\\t// assign BoxWeight reference to Box reference \\n\\t\\tplainbox = weightbox; \\n\\t\\tvol = plainbox.volume(); // OK, volume() defined in Box \\n\\t\\tSystem.out.println(\"Volume of plainbox is \" + vol); \\n\\t\\t/* The following statement is invalid because plainbox \\n\\t\\tdoes not define a weight member. */ \\n\\t\\t// System.out.println(\"Weight of plainbox is \" + plainbox.weight); \\n\\t} \\n}\\n\\nHere, weightbox is a reference to BoxWeight objects, and plainbox is a reference to Box objects. Since BoxWeight is a subclass of Box, it is permissible to assign plainbox a reference to the weightbox object. \\n\\nIt is important to understand that it is the type of the reference variable—not the type of the object that it refers to—that determines what members can be accessed. That is, when a reference to a subclass object is assigned to a superclass reference variable, you will have access only to those parts of the object defined by the superclass. This is why plainbox cant access weight even when it refers to a BoxWeight object. If you think about it, this makes sense, because the superclass has no knowledge of what a subclass adds to it. This is why the last line of code in the preceding fragment is commented out. It is not possible for a Box reference to access the weight field, because Box does not define one.\\n",
177 "42",
178 "INHERITANCE, using 'super'",
179 "Using super \\n\\nIn the preceding examples, classes derived from Box were not implemented as efficiently or as robustly as they could have been. For example, the constructor for BoxWeight explicitly initializes the width, height, and depth fields of Box( ). Not only does this duplicate code found in its superclass, which is inefficient, but it implies that a subclass must be granted access to these members. However, there will be times when you will want to create a superclass that keeps the details of its implementation to itself (that is, that keeps its data members private). In this case, there would be no way for a subclass to directly access or initialize these variables on its own. Since encapsulation is a primary attribute of OOP, it is not surprising that Java provides a solution to this problem. Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.\\n \\nsuper has two general forms. The first calls the superclass constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass. Each use is examined here. \\n\\nUsing super to Call Superclass Constructors \\n\\nA subclass can call a constructor defined by its superclass by use of the following form of super: \\n\\nsuper(arg-list); \\n\\nHere, arg-list specifies any arguments needed by the constructor in the superclass. super( ) must always be the first statement executed inside a subclass constructor. \\n\\nTo see how super( ) is used, consider this improved version of the BoxWeight( ) class: \\n\\n// BoxWeight now uses super to initialize its Box attributes. \\nclass BoxWeight extends Box { \\n\\tdouble weight; // weight of box \\n\\t// initialize width, height, and depth using super() \\n\\tBoxWeight(double w, double h, double d, double m) { \\n\\t\\tsuper(w, h, d); // call superclass constructor \\n\\t\\tweight = m; \\n\\t} \\n}\\n \\nHere, BoxWeight( ) calls super( ) with the arguments w, h, and d. This causes the Box( ) constructor to be called, which initializes width, height, and depth using these values. BoxWeight no longer initializes these values itself. It only needs to initialize the value unique to it: weight. This leaves Box free to make these values private if desired. \\n\\nIn the preceding example, super( ) was called with three arguments. Since constructors can be overloaded, super( ) can be called using any form defined by the superclass. The constructor executed will be the one that matches the arguments. For example, here is a complete implementation of BoxWeight that provides constructors for the various ways that a box can be constructed. In each case, super( ) is called using the appropriate arguments. Notice that width, height, and depth have been made private within Box. \\n\\n// A complete implementation of BoxWeight. \\nclass Box { \\n\\tprivate double width; \\n\\tprivate double height; \\n\\tprivate double depth;\\n \\n\\t// construct clone of an object \\n\\tBox(Box ob) { // pass object to constructor \\n\\t\\twidth = ob.width; \\n\\t\\theight = ob.height; \\n\\t\\tdepth = ob.depth; \\n\\t}\\n\\n\\t// constructor used when all dimensions specified \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t}\\n\\t// constructor used when no dimensions specified \\n\\tBox() { \\n\\t\\twidth = -1; // use -1 to indicate \\n\\t\\theight = -1; // an uninitialized \\n\\t\\tdepth = -1; // box \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBox(double len) { \\n\\t\\twidth = height = depth = len; \\n\\t}\\n\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\n// BoxWeight now fully implements all constructors. \\nclass BoxWeight extends Box { \\n\\tdouble weight; // weight of box\\n \\n\\t// construct clone of an object \\n\\tBoxWeight(BoxWeight ob) { // pass object to constructor \\n\\t\\tsuper(ob); \\n\\t\\tweight = ob.weight; \\n\\t}\\n\\n\\t// constructor when all parameters are specified \\n\\tBoxWeight(double w, double h, double d, double m) { \\n\\t\\tsuper(w, h, d); // call superclass constructor \\n\\t\\tweight = m; \\n\\t}\\n\\n\\t// default constructor \\n\\tBoxWeight() { \\n\\t\\tsuper(); \\n\\t\\tweight = -1; \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBoxWeight(double len, double m) { \\n\\t\\tsuper(len); \\n\\t\\tweight = m; \\n\\t} \\n}\\n\\nclass DemoSuper { \\n\\tpublic static void main(String args[]) { \\n\\t\\tBoxWeight mybox1 = new BoxWeight(10, 20, 15, 34.3); \\n\\t\\tBoxWeight mybox2 = new BoxWeight(2, 3, 4, 0.076); \\n\\t\\tBoxWeight mybox3 = new BoxWeight(); // default\\n \\t\\tBoxWeight mycube = new BoxWeight(3, 2); \\n\\t\\tBoxWeight myclone = new BoxWeight(mybox1); \\n\\t\\tdouble vol; \\n\\n\\t\\tvol = mybox1.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox1 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mybox1 is \" + mybox1.weight); \\n\\t\\tSystem.out.println(); \\n\\n\\t\\tvol = mybox2.volume();\\n\\t\\tSystem.out.println(\"Volume of mybox2 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mybox2 is \" + mybox2.weight); \\n\\t\\tSystem.out.println(); \\n\\n\\t\\tvol = mybox3.volume(); \\n\\t\\tSystem.out.println(\"Volume of mybox3 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mybox3 is \" + mybox3.weight); \\n\\t\\tSystem.out.println();\\n \\n\\t\\tvol = myclone.volume(); \\n\\t\\tSystem.out.println(\"Volume of myclone is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of myclone is \" + myclone.weight); \\n\\t\\tSystem.out.println(); \\n\\n\\t\\tvol = mycube.volume(); \\n\\t\\tSystem.out.println(\"Volume of mycube is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of mycube is \" + mycube.weight); \\n\\t\\tSystem.out.println(); \\n\\t} \\n}\\n\\nThis program generates the following output: \\n\\nVolume of mybox1 is 3000.0 \\nWeight of mybox1 is 34.3 \\nVolume of mybox2 is 24.0 \\nWeight of mybox2 is 0.076 \\nVolume of mybox3 is -1.0 \\nWeight of mybox3 is -1.0 \\nVolume of myclone is 3000.0 \\nWeight of myclone is 34.3 \\nVolume of mycube is 27.0 \\nWeight of mycube is 2.0 \\n\\nPay special attention to this constructor in BoxWeight( ): \\n\\n// construct clone of an object \\nBoxWeight(BoxWeight ob) { // pass object to constructor \\n\\tsuper(ob); \\n\\tweight = ob.weight; \\n} \\n\\nNotice that super( ) is passed an object of type BoxWeight—not of type Box. This still invokes the constructor Box(Box ob). As mentioned earlier, a superclass variable can be used to reference any object derived from that class. Thus, we are able to pass a BoxWeight object to the Box constructor. Of course, Box only has knowledge of its own members. Lets review the key concepts behind super( ). When a subclass calls super( ), it is calling the constructor of its immediate superclass. Thus, super( ) always refers to the superclass immediately above the calling class. This is true even in a multileveled hierarchy. Also, super( ) must always be the first statement executed inside a subclass constructor. \\n\\nA Second Use for super \\n\\nThe second form of super acts somewhat like this, except that it always refers to the superclass of the subclass in which it is used. This usage has the following general form: \\n\\nsuper.member \\n\\nHere, member can be either a method or an instance variable. \\n\\nThis second form of super is most applicable to situations in which member names of a subclass hide members by the same name in the superclass. Consider this simple class hierarchy:\\n \\n// Using super to overcome name hiding. \\nclass A { \\n\\tint i; \\n}\\n\\n// Create a subclass by extending class A. \\nclass B extends A { \\n\\tint i; // this i hides the i in A \\n\\tB(int a, int b) { \\n\\t\\tsuper.i = a; // i in A \\n\\t\\ti = b; // i in B \\n\\t}\\n\\tvoid show() { \\n\\t\\tSystem.out.println(\"i in superclass: \" + super.i); \\n\\t\\tSystem.out.println(\"i in subclass: \" + i); \\n\\t} \\n}\\n\\nclass UseSuper { \\n\\tpublic static void main(String args[]) { \\n\\t\\tB subOb = new B(1, 2); \\n\\t\\tsubOb.show(); \\n\\t} \\n} \\n\\nThis program displays the following:\\n \\ni in superclass: 1 \\ni in subclass: 2 \\n\\nAlthough the instance variable i in B hides the i in A, super allows access to the i defined in the superclass. As you will see, super can also be used to call methods that are hidden by a subclass.\\n",
180 "43",
181 "INHERITANCE, a multilevel hierarchy",
182 "Creating a Multilevel Hierarchy \\n\\nUp to this point, we have been using simple class hierarchies that consist of only a superclass and a subclass. However, you can build hierarchies that contain as many layers of inheritance as you like. As mentioned, it is perfectly acceptable to use a subclass as a superclass of another. For example, given three classes called A, B, and C, C can be a subclass of B, which is a subclass of A. When this type of situation occurs, each subclass inherits all of the traits found in all of its superclasses. In this case, C inherits all aspects of B and A. To see how a multilevel hierarchy can be useful, consider the following program. In it, the subclass BoxWeight is used as a superclass to create the subclass called Shipment. Shipment inherits all of the traits of BoxWeight and Box, and adds a field called cost, which holds the cost of shipping such a parcel. \\n\\n// Extend BoxWeight to include shipping costs. \\n// Start with Box. \\nclass Box { \\n\\tprivate double width;\\n\\tprivate double height; \\n\\tprivate double depth; \\n\\n\\t// construct clone of an object\\n\\tBox(Box ob) { // pass object to constructor \\n\\t\\twidth = ob.width; \\n\\t\\theight = ob.height; \\n\\t\\tdepth = ob.depth; \\n\\t}\\n\\n\\t// constructor used when all dimensions specified \\n\\tBox(double w, double h, double d) { \\n\\t\\twidth = w; \\n\\t\\theight = h; \\n\\t\\tdepth = d; \\n\\t}\\n\\n\\t// constructor used when no dimensions specified \\n\\tBox() { \\n\\t\\twidth = -1; // use -1 to indicate \\n\\t\\theight = -1; // an uninitialized \\n\\t\\tdepth = -1; // box \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBox(double len) { \\n\\t\\twidth = height = depth = len; \\n\\t}\\n\\n\\t// compute and return volume \\n\\tdouble volume() { \\n\\t\\treturn width * height * depth; \\n\\t} \\n}\\n\\n// Add weight. \\nclass BoxWeight extends Box { \\n\\tdouble weight; // weight of box \\n\\n\\t// construct clone of an object \\n\\tBoxWeight(BoxWeight ob) { // pass object to constructor \\n\\t\\tsuper(ob); \\n\\t\\tweight = ob.weight; \\n\\t}\\n\\n\\t// constructor when all parameters are specified \\n\\tBoxWeight(double w, double h, double d, double m) { \\n\\t\\tsuper(w, h, d); // call superclass constructor \\n\\t\\tweight = m; \\n\\t}\\n\\n\\t// default constructor \\n\\tBoxWeight() { \\n\\t\\tsuper(); \\n\\t\\tweight = -1; \\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tBoxWeight(double len, double m) { \\n\\t\\tsuper(len); \\n\\t\\tweight = m; \\n\\t} \\n}\\n\\n// Add shipping costs.\\nclass Shipment extends BoxWeight { \\n\\tdouble cost; \\n\\t// construct clone of an object \\n\\tShipment(Shipment ob) { // pass object to constructor \\n\\t\\tsuper(ob); \\n\\t\\tcost = ob.cost; \\n\\t}\\n\\n\\t// constructor when all parameters are specified \\n\\tShipment(double w, double h, double d, double m, double c) { \\n\\t\\tsuper(w, h, d, m); // call superclass constructor\\n \\t\\tcost = c; \\n\\t}\\n\\n\\t// default constructor \\n\\tShipment() { \\n\\t\\tsuper(); \\n\\t\\tcost = -1;\\n\\t}\\n\\n\\t// constructor used when cube is created \\n\\tShipment(double len, double m, double c) { \\n\\t\\tsuper(len, m); \\n\\t\\tcost = c; \\n\\t} \\n}\\n\\nclass DemoShipment { \\n\\tpublic static void main(String args[]) {\\n\\t\\tShipment shipment1 = new Shipment(10, 20, 15, 10, 3.41); \\n\\t\\tShipment shipment2 = new Shipment(2, 3, 4, 0.76, 1.28); \\n\\t\\tdouble vol; \\n\\t\\tvol = shipment1.volume(); \\n\\t\\tSystem.out.println(\"Volume of shipment1 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of shipment1 is \" \\n\\t\\t+ shipment1.weight); \\n\\t\\tSystem.out.println(\"Shipping cost: $\" + shipment1.cost); \\n\\t\\tSystem.out.println(); \\n\\t\\tvol = shipment2.volume(); \\n\\t\\tSystem.out.println(\"Volume of shipment2 is \" + vol); \\n\\t\\tSystem.out.println(\"Weight of shipment2 is \" \\n\\t\\t+ shipment2.weight); \\n\\t\\tSystem.out.println(\"Shipping cost: $\" + shipment2.cost); \\n\\t} \\n}\\n\\nThe output of this program is shown here:\\n\\nVolume of shipment1 is 3000.0 \\nWeight of shipment1 is 10.0 \\nShipping cost: $3.41 \\n\\nVolume of shipment2 is 24.0 \\nWeight of shipment2 is 0.76 \\nShipping cost: $1.28 \\n\\nBecause of inheritance, Shipment can make use of the previously defined classes of Box and BoxWeight, adding only the extra information it needs for its own, specific application. This is part of the value of inheritance; it allows the reuse of code. \\n\\nThis example illustrates one other important point: super( ) always refers to the constructor in the closest superclass. The super( ) in Shipment calls the constructor in BoxWeight. The super( ) in BoxWeight calls the constructor in Box. In a class hierarchy, if a superclass constructor requires parameters, then all subclasses must pass those parameters up the line. This is true whether or not a subclass needs parameters of its own.\\n",
183 "44",
184 "INHERITANCE, method overriding",
185 "Method Overriding \\n\\nIn a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version of the method defined by the superclass will be hidden. Consider the following: \\n\\n// Method overriding. \\nclass A { \\n\\tint i, j; \\n\\tA(int a, int b) { \\n\\t\\ti = a; \\n\\t\\tj = b; \\n\\t}\\n\\n\\t// display i and j \\n\\tvoid show() { \\n\\t\\tSystem.out.println(\"i and j: \" + i + \" \" + j); \\n\\t} \\n}\\n\\nclass B extends A { \\n\\tint k; \\n\\tB(int a, int b, int c) { \\n\\t\\tsuper(a, b); \\n\\t\\tk = c; \\n\\t}\\n\\n\\t// display k – this overrides show() in A \\n\\tvoid show() { \\n\\t\\tSystem.out.println(\"k: \" + k); \\n\\t} \\n}\\n\\nclass Override { \\n\\tpublic static void main(String args[]) { \\n\\t\\tB subOb = new B(1, 2, 3); \\n\\t\\tsubOb.show(); // this calls show() in B \\n\\t} \\n} \\n\\nThe output produced by this program is shown here: \\nk: 3 \\n\\nWhen show( ) is invoked on an object of type B, the version of show( ) defined within B is used. That is, the version of show( ) inside B overrides the version declared in A. \\n\\nIf you wish to access the superclass version of an overridden method, you can do so by using super. For example, in this version of B, the superclass version of show( ) is invoked within the subclass version. This allows all instance variables to be displayed. \\n\\nclass B extends A { \\n\\tint k; \\n\\tB(int a, int b, int c) { \\n\\t\\tsuper(a, b); \\n\\t\\tk = c; \\n\\t}\\n\\tvoid show() { \\n\\t\\tsuper.show(); // this calls A's show() \\n\\t\\tSystem.out.println(\"k: \" + k); \\n\\t} \\n} \\n\\nIf you substitute this version of A into the previous program, you will see the following output: \\n\\ni and j: 1 2 \\nk: 3 \\n\\nHere, super.show( ) calls the superclass version of show( ). Method overriding occurs only when the names and the type signatures of the two methods are identical. If they are not, then the two methods are simply overloaded. For example, consider this modified version of the preceding example: \\n\\n// Methods with differing type signatures are overloaded – not \\n// overridden. \\nclass A { \\n\\tint i, j; \\n\\tA(int a, int b) { \\n\\t\\ti = a; \\n\\t\\tj = b; \\n\\t} \\n \\n\\t// display i and j \\n\\tvoid show() { \\n\\t\\tSystem.out.println(\"i and j: \" + i + \" \" + j); \\n\\t} \\n} \\n \\n// Create a subclass by extending class A. \\nclass B extends A { \\n\\tint k; \\n\\tB(int a, int b, int c) { \\n\\t\\tsuper(a, b); \\n\\t\\tk = c; \\n\\t} \\n\\t// overload show() \\n\\tvoid show(String msg) { \\n\\t\\tSystem.out.println(msg + k); \\n\\t} \\n} \\n \\nclass Override { \\n\\tpublic static void main(String args[]) { \\n\\t\\tB subOb = new B(1, 2, 3); \\n\\t\\tsubOb.show(\"This is k: \"); // this calls show() in B \\n\\t\\tsubOb.show(); // this calls show() in A \\n\\t} \\n} \\n \\nThe output produced by this program is shown here: \\n \\nThis is k: 3 \\ni and j: 1 2 \\n \\nThe version of show( ) in B takes a string parameter. This makes its type signature different from the one in A, which takes no parameters. Therefore, no overriding (or name hiding) takes place. Instead, the version of show( ) in B simply overloads the version of show( ) in A. \\n",
186 "45",
187 "INHERITANCE, interfaces",
188 "Interfaces \\n\\nUsing the keyword interface, you can fully abstract a class interface from its implementation. That is, using interface, you can specify what a class must do, but not how it does it. Interfaces are syntactically similar to classes, but they lack instance variables, and their methods are declared without any body. In practice, this means that you can define interfaces that dont make assumptions about how they are implemented. Once it is defined, any number of classes can implement an interface. Also, one class can implement any number of interfaces. To implement an interface, a class must create the complete set of methods defined by the interface. However, each class is free to determine the details of its own implementation. By providing the interface keyword, Java allows you to fully utilize the one interface, multiple methods aspect of polymorphism.\\n\\nInterfaces are designed to support dynamic method resolution at run time. Normally, in order for a method to be called from one class to another, both classes need to be present at compile time so the Java compiler can check to ensure that the method signatures are compatible. This requirement by itself makes for a static and nonextensible classing environment. Inevitably in a system like this, functionality gets pushed up higher and higher in the class hierarchy so that the mechanisms will be available to more and more subclasses. Interfaces are designed to avoid this problem. They disconnect the definition of a method or set of methods from the inheritance hierarchy. Since interfaces are in a different hierarchy from classes, it is possible for classes that are unrelated in terms of the class hierarchy to implement the same interface. This is where the real power of interfaces is realized. \\n\\nDefining an Interface \\n\\nAn interface is defined much like a class. This is the general form of an interface:\\n \\naccess interface name { \\n\\treturn-type method-name1(parameter-list); \\n\\treturn-type method-name2(parameter-list); \\n\\ttype final-varname1 = value; \\n\\ttype final-varname2 = value; \\n\\t// … \\n\\treturn-type method-nameN(parameter-list); \\n\\ttype final-varnameN = value; \\n} \\n\\nWhen no access specifier is included, then default access results, and the interface is only available to other members of the package in which it is declared. When it is declared as public, the interface can be used by any other code. In this case, the interface must be the only public interface declared in the file, and the file must have the same name as the interface. name is the name of the interface, and can be any valid identifier. Notice that the methods that are declared have no bodies. They end with a semicolon after the parameter list. They are, essentially, abstract methods; there can be no default implementation of any method specified within an interface. Each class that includes an interface must implement all of the methods. Variables can be declared inside of interface declarations. They are implicitly final and static, meaning they cannot be changed by the implementing class. They must also be initialized. All methods and variables are implicitly public. \\n\\nHere is an example of an interface definition. It declares a simple interface that contains one method called callback( ) that takes a single integer parameter. \\n\\ninterface Callback { \\n\\tvoid callback(int param); \\n}\\n\\nImplementing Interfaces \\n\\nOnce an interface has been defined, one or more classes can implement that interface. To implement an interface, include the implements clause in a class definition, and then create the methods defined by the interface. The general form of a class that includes the implements clause looks like this: \\n\\nclass classname [extends superclass] [implements interface [,interface…]] { \\n\\t// class-body \\n}\\n \\nIf a class implements more than one interface, the interfaces are separated with a comma. If a class implements two interfaces that declare the same method, then the same method will be used by clients of either interface. The methods that implement an interface must be declared public. Also, the type signature of the implementing method must match exactly the type signature specified in the interface definition.\\n \\nHere is a small example class that implements the Callback interface shown earlier. \\n\\nclass Client implements Callback { \\n\\t// Implement Callback's interface \\n\\tpublic void callback(int p) { \\n\\t\\tSystem.out.println(\"callback called with \" + p); \\n\\t} \\n}\\n\\nNotice that callback( ) is declared using the public access specifier. \\n\\nREMEMBER When you implement an interface method, it must be declared as public. It is both permissible and common for classes that implement interfaces to define additional members of their own. For example, the following version of Client implements callback( ) and adds the method nonIfaceMeth( ): \\n\\nclass Client implements Callback { \\n\\t// Implement Callback's interface \\n\\tpublic void callback(int p) { \\n\\t\\tSystem.out.println(\"callback called with \" + p); \\n\\t}\\n\\tvoid nonIfaceMeth() { \\n\\t\\tSystem.out.println(\"Classes that implement interfaces \" + \\n\\t\\t\"may also define other members, too.\"); \\n\\t} \\n}\\n",
189 "46",
190 "INHERITANCE, accessing implementations through interface references",
191 "Accessing Implementations Through Interface References \\n\\nYou can declare variables as object references that use an interface rather than a class type. Any instance of any class that implements the declared interface can be referred to by such a variable. When you call a method through one of these references, the correct version will be called based on the actual instance of the interface being referred to. This is one of the key features of interfaces. The method to be executed is looked up dynamically at run time, allowing classes to be created later than the code which calls methods on them. The calling code can dispatch through an interface without having to know anything about the callee. This process is similar to using a superclass reference to access a subclass object. \\n \\nThe following example calls the callback( ) method via an interface reference variable: \\n\\ninterface Callback {\\n\\tvoid callback(int param);\\n}\\n\\nclass Client implements Callback {\\n\\tpublic void callback(int p) {\\n\\t\\tSystem.out.println(\"callback called with \" + p) ;\\n\\t}\\n\\tvoid nonIfaceMeth() {\\n\\t\\tSystem.out.println(\"Classes that implement interfaces \" +\\n\\t\\t\"may also define other members, too.\");\\n\\t}\\n}\\n\\nclass TestIface { \\n\\tpublic static void main(String args[]) { \\n\\t\\tCallback c = new Client(); \\n\\t\\tc.callback(42); \\n\\t} \\n}\\nThe output of this program is shown here: \\ncallback called with 42 \\n\\nNotice that variable c is declared to be of the interface type Callback, yet it was assigned an instance of Client. Although c can be used to access the callback( ) method, it cannot access any other members of the Client class. An interface reference variable only has knowledge of the methods declared by its interface declaration. Thus, c could not be used to access nonIfaceMeth( ) since it is defined by Client but not Callback. \\nWhile the preceding example shows, mechanically, how an interface reference variable can access an implementation object, it does not demonstrate the polymorphic power of such a reference. To sample this usage, first create the second implementation of Callback, shown here: \\n\\n// Another implementation of Callback. \\nclass AnotherClient implements Callback { \\n\\t// Implement Callback's interface \\n\\tpublic void callback(int p) { \\n\\t\\tSystem.out.println(\"Another version of callback\"); \\n\\t\\tSystem.out.println(\"p squared is \" + (p*p)); \\n\\t} \\n}\\n\\nNow, try the following class: \\n\\nclass TestIface2 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tCallback c = new Client(); \\n\\t\\tAnotherClient ob = new AnotherClient(); \\n\\t\\tc.callback(42); \\n\\t\\tc = ob; // c now refers to AnotherClient object \\n\\t\\tc.callback(42); \\n\\t} \\n}\\n\\nThe output from this program is shown here: \\ncallback called with 42 \\nAnother version of callback \\np squared is 1764 \\n\\nAs you can see, the version of callback( ) that is called is determined by the type of object that c refers to at run time. While this is a very simple example, you will see another, more practical one shortly. \\n\\nPartial Implementations \\n\\nIf a class includes an interface but does not fully implement the methods defined by that interface, then that class must be declared as abstract. For example: \\n\\nabstract class Incomplete implements Callback { \\n\\tint a, b; \\n\\tvoid show() { \\n\\t\\tSystem.out.println(a + \" \" + b); \\n\\t}\\n\\t// … \\n}\\n\\nHere, the class Incomplete does not implement callback( ) and must be declared as abstract. Any class that inherits Incomplete must implement callback( ) or be declared abstract itself.\\n \\nApplying Interfaces \\n\\nTo understand the power of interfaces, lets look at a more practical example. In earlier chapters, you developed a class called Stack that implemented a simple fixed-size stack. However, there are many ways to implement a stack. For example, the stack can be of a fixed size or it can be growable. The stack can also be held in an array, a linked list, a binary tree, and so on. No matter how the stack is implemented, the interface to the stack remains the same. That is, the methods push( ) and pop( ) define the interface to the stack independently of the details of the implementation. Because the interface to a stack is separate from its implementation, it is easy to define a stack interface, leaving it to each implementation to define the specifics. Lets look at two examples. \\n\\nFirst, here is the interface that defines an integer stack. Put this in a file called IntStack.java. This interface will be used by both stack implementations.\\n \\n// Define an integer stack interface. \\ninterface IntStack { \\n\\tvoid push(int item); // store an item \\n\\tint pop(); // retrieve an item \\n}\\n \\nThe following program creates a class called FixedStack that implements a fixed-length version of an integer stack: \\n\\n// An implementation of IntStack that uses fixed storage. \\nclass FixedStack implements IntStack { \\n\\tprivate int stck[]; \\n\\tprivate int tos; \\n\\t// allocate and initialize stack \\n\\tFixedStack(int size) { \\n\\t\\tstck = new int[size]; \\n\\t\\ttos = -1; \\n\\t}\\n\\t// Push an item onto the stack \\n\\tpublic void push(int item) { \\n\\t\\tif(tos==stck.length-1){ // use length member \\n\\t\\t\\tSystem.out.println(\"Stack is full.\"); \\n\\t\\t}\\n\\t\\telse {\\n\\t\\t\\tstck[++tos] = item; \\n\\t\\t}\\n\\t}\\n\\t// Pop an item from the stack \\n\\tpublic int pop() { \\n\\t\\tif(tos <0) { \\n\\t\\t\\tSystem.out.println(\"Stack underflow.\"); \\n\\t\\t\\treturn 0; \\n\\t\\t}\\n\\t\\telse { \\n\\t\\t\\treturn stck[tos - -]; \\n\\t\\t}\\n\\t} \\n}\\n\\nclass IFTest { \\n\\tpublic static void main(String args[]) { \\n\\t\\tFixedStack mystack1 = new FixedStack(5); \\n\\t\\tFixedStack mystack2 = new FixedStack(8);\\n \\n\\t\\t// push some numbers onto the stack \\n\\t\\tfor(int i=0; i<5; i++) {\\n\\t\\t\\tmystack1.push(i);\\n\\t\\t} \\n\\t\\tfor(int i=0; i<8; i++) {\\n\\t\\t\\tmystack2.push(i); \\n\\t\\t}\\n\\t\\t// pop those numbers off the stack \\n\\t\\tSystem.out.println(\"Stack in mystack1:\"); \\n\\t\\tfor(int i=0; i<5; i++) {\\n\\t\\t\\tSystem.out.println(mystack1.pop()); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"Stack in mystack2:\"); \\n\\t\\tfor(int i=0; i<8; i++) {\\n\\t\\t\\tSystem.out.println(mystack2.pop()); \\n\\t\\t}\\n\\t} \\n} \\n \\nFollowing is another implementation of IntStack that creates a dynamic stack by use of the same interface definition. In this implementation, each stack is constructed with an initial length. If this initial length is exceeded, then the stack is increased in size. Each time more room is needed, the size of the stack is doubled. \\n\\n// Implement a \"growable\" stack. \\nclass DynStack implements IntStack { \\n\\tprivate int stck[]; \\n\\tprivate int tos; \\n\\t// allocate and initialize stack \\n\\tDynStack(int size) { \\n\\t\\tstck = new int[size]; \\n\\t\\ttos = -1; \\n\\t}\\n\\t// Push an item onto the stack \\n\\tpublic void push(int item) { \\n\\t\\t// if stack is full, allocate a larger stack \\n\\t\\tif(tos==stck.length-1) { \\n\\t\\t\\tint temp[] = new int[stck.length * 2]; // double size \\n\\t\\t\\tfor(int i=0; i<stck.length; i++) {\\n\\t\\t\\t\\ttemp[i] = stck[i]; \\n\\t\\t\\t}\\n\\t\\t\\tstck = temp; \\n\\t\\t\\tstck[++tos] = item; \\n\\t\\t}\\n\\t\\telse { \\n\\t\\t\\tstck[++tos] = item; \\n\\t\\t}\\n\\t}\\n\\t// Pop an item from the stack \\n\\tpublic int pop() { \\n\\t\\tif(tos < 0) { \\n\\t\\t\\tSystem.out.println(\"Stack underflow.\"); \\n\\t\\t\\treturn 0; \\n\\t\\t}\\n\\t\\telse { \\n\\t\\t\\treturn stck[tos - -]; \\n\\t\\t}\\n\\t} \\n}\\n\\nclass IFTest2 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tDynStack mystack1 = new DynStack(5); \\n\\t\\tDynStack mystack2 = new DynStack(8); \\n\\t\\t// these loops cause each stack to grow \\n\\t\\tfor(int i=0; i<12; i++) {\\n\\t\\t\\tmystack1.push(i);\\n\\t\\t} \\n\\t\\tfor(int i=0; i<20; i++) {\\n\\t\\t\\tmystack2.push(i);\\n\\t\\t} \\n\\t\\tSystem.out.println(\"Stack in mystack1:\"); \\n\\t\\tfor(int i=0; i<12; i++) {\\n\\t\\t\\tSystem.out.println(mystack1.pop());\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Stack in mystack2:\");\\n\\t\\tfor(int i=0; i<20; i++) {\\n\\t\\t\\tSystem.out.println(mystack2.pop());\\n\\t\\t} \\n\\t} \\n} \\n\\nThe following class uses both the FixedStack and DynStack implementations. It does so through an interface reference. This means that calls to push( ) and pop( ) are resolved at run time rather than at compile time. \\n\\n/* Create an interface variable and \\naccess stacks through it. \\n*/ \\nclass IFTest3 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tIntStack mystack; // create an interface reference variable \\n\\t\\tDynStack ds = new DynStack(5); \\n\\t\\tFixedStack fs = new FixedStack(8); \\n\\t\\tmystack = ds; // load dynamic stack \\n\\t\\t// push some numbers onto the stack \\n\\t\\tfor(int i=0; i<12; i++) {\\n\\t\\t\\tmystack.push(i);\\n\\t\\t} \\n\\t\\tmystack = fs; // load fixed stack \\n\\t\\tfor(int i=0; i<8; i++) {\\n\\t\\t\\tmystack.push(i);\\n\\t\\t}\\n\\t\\tmystack = ds; \\n\\t\\tSystem.out.println(\"Values in dynamic stack:\"); \\n\\t\\tfor(int i=0; i<12; i++) {\\n\\t\\t\\tSystem.out.println(mystack.pop()); \\n\\t\\t}\\n\\t\\tmystack = fs; \\n\\t\\tSystem.out.println(\"Values in fixed stack:\"); \\n\\t\\tfor(int i=0; i<8; i++) {\\n\\t\\t\\tSystem.out.println(mystack.pop()); \\n\\t\\t}\\n\\t} \\n}\\n\\nIn this program, mystack is a reference to the IntStack interface. Thus, when it refers to ds, it uses the versions of push( ) and pop( ) defined by the DynStack implementation. When it refers to fs, it uses the versions of push( ) and pop( ) defined by FixedStack. As explained, these determinations are made at run time. Accessing multiple implementations of an interface through an interface reference variable is the most powerful way that Java achieves run-time polymorphism.\\n",
192 "47",
193 "THE OBJECT CLASS, methods",
194 "The Object Class \\n\\nThere is one special class, Object, defined by Java. All other classes are subclasses of Object. That is, Object is a superclass of all other classes. This means that a reference variable of type Object can refer to an object of any other class. Also, since arrays are implemented as classes, a variable of type Object can also refer to any array. \\n\\nObject defines the following methods, which means that they are available in every object:\\n\\n1.Object clone( ) Creates a new object that is the same as the object being cloned. \\n\\n2.boolean equals(Object object) Determines whether one object is equal to another. \\n\\n3.void finalize( ) Called before an unused object is recycled. \\n\\n4.Class getClass( ) Obtains the class of an object at run time. \\n\\n5.int hashCode( ) Returns the hash code associated with the invoking object. \\n\\n6.void notify( ) Resumes execution of a thread waiting on the invoking object. \\n\\n7.void notifyAll( ) Resumes execution of all threads waiting on the invoking object. \\n\\n8.String toString( ) Returns a string that describes the object. \\n\\n9.void wait( ) Waits on another thread of execution. \\n\\n10.void wait(long milliseconds) \\n\\n11.void wait(long milliseconds,int nanoseconds) \\n\\nThe methods getClass( ), notify( ), notifyAll( ), and wait( ) are declared as final. You may override the others. \\n\\nHowever, notice two methods now: equals( ) and toString( ). The equals( ) method compares the contents of two objects. It returns true if the objects are equivalent, and false otherwise.The precise definition of equality can vary, depending on the type of objects being compared. The toString( ) method returns a string that contains a description of the object on which it is called. Also, this method is automatically called when an object is output using println( ). Many classes override this method. Doing so allows them to tailor a description specifically for the types of objects that they create. \\n",
195 "48",
196 "EXCEPTION HANDLING, try, catch, finally",
197 "Exception Handling\\n\\nAn exception is an abnormal condition that arises in a code sequence at run time. In other words, an exception is a run-time error. In computer languages that do not support exception handling, errors must be checked and handled manually—typically through the use of error codes, and so on. This approach is as cumbersome as it is troublesome. Javas exception handling avoids these problems and, in the process, brings run-time error management into the objectoriented world.\\n\\nException-Handling Fundamentals\\n\\nA Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of code. When an exceptional condition arises, an object representing that exception is created and thrown in the method that caused the error. That method may choose to handle the exception itself, or pass it on. Either way, at some point, the exception is caught and processed. Exceptions can be generated by the Java run-time system, or they can be manually generated by your code. Exceptions thrown by Java relate to fundamental errors that violate the rules of the Java language or the constraints of the Java execution environment. Manually generated exceptions are typically used to report some error condition to the caller of a method.\\nJava exception handling is managed via five keywords: try, catch, throw, throws, and finally. Briefly, here is how they work. Program statements that you want to monitor for exceptions are contained within a try block. If an exception occurs within the try block, it is thrown. Your code can catch this exception (using catch) and handle it in some rational manner. System-generated exceptions are automatically thrown by the Java run-time system. To manually throw an exception, use the keyword throw. Any exception that is thrown out of a method must be specified as such by a throws clause. Any code that absolutely must be executed after a try block completes is put in a finally block. This is the general form of an exception-handling block:\\n\\ntry {\\n\\t// block of code to monitor for errors\\n} \\n\\ncatch (ExceptionType1 exOb) {\\n\\t// exception handler for ExceptionType1\\n}\\n\\ncatch (ExceptionType2 exOb) {\\n\\t// exception handler for ExceptionType2 \\n}\\n// …\\n\\nfinally {\\n\\t// block of code to be executed after try block ends\\n}\\n\\nHere, ExceptionType is the type of exception that has occurred.\\n\\nUsing try and catch\\n\\nAlthough the default exception handler provided by the Java run-time system is useful for debugging, you will usually want to handle an exception yourself. Doing so provides two benefits. First, it allows you to fix the error. Second, it prevents the program from automatically terminating. Most users would be confused (to say the least) if your program stopped running and printed a stack trace whenever an error occurred! Fortunately, it is quite easy to prevent this.\\n\\nTo guard against and handle a run-time error, simply enclose the code that you want to monitor inside a try block. Immediately following the try block, include a catch clause that specifies the exception type that you wish to catch. To illustrate how easily this can be done, the following program includes a try block and a catch clause that processes the ArithmeticException generated by the division-by-zero error:\\n\\nclass Exc2 {\\n\\tpublic static void main(String args[]) {\\n\\t\\tint d, a;\\n\\t\\ttry { // monitor a block of code.\\n\\t\\t\\td = 0;\\n\\t\\t\\tSystem.out.println(\"This will not be printed.\");\\n\\t\\t} catch (ArithmeticException e) { // catch divide-by-zero error\\n\\t\\t\\tSystem.out.println(\"Division by zero.\");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"After catch statement.\");\\n\\t}\\n}\\n\\nThis program generates the following output:\\nDivision by zero.\\nAfter catch statement.\\n\\nNotice that the call to println( ) inside the try block is never executed. Once an exception is thrown, program control transfers out of the try block into the catch block. Put differently, catch is not called, so execution never returns to the try block from a catch. Thus, the line This will not be printed. is not displayed. Once the catch statement has executed, program control continues with the next line in the program following the entire try/catch mechanism.\\n\\nA try and its catch statement form a unit. The scope of the catch clause is restricted to those statements specified by the immediately preceding try statement. A catch statement cannot catch an exception thrown by another try statemen. The statements that are protected by try must be surrounded by curly braces. (That is, they must be within a block.) You cannot use try on a single statement. The goal of most well-constructed catch clauses should be to resolve the exceptional condition and then continue on as if the error had never happened. For example, in the next program each iteration of the for loop obtains two random integers. Those two integers are divided by each other, and the result is used to divide the value 12345. The final result is put into a. If either division operation causes a divide-by-zero error, it is caught, the value of a is set to zero, and the program continues.\\n\\n// Handle an exception and move on.\\nimport java.util.Random;\\nclass HandleError {\\n\\tpublic static void main(String args[]) {\\n\\t\\tint a=0, b=0, c=0;\\n\\t\\tRandom r = new Random();\\n\\t\\tfor(int i=0; i<32000; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tb = r.nextInt();\\n\\t\\t\\t\\tc = r.nextInt();\\n\\t\\t\\t\\ta = 12345 / (b/c);\\n\\t\\t\\t} catch (ArithmeticException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Division by zero.\");\\n\\t\\t\\t\\ta = 0; // set a to zero and continue\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"a: \" + a);\\n\\t\\t}\\n\\t}\\n}\\n\\nDisplaying a Description of an Exception\\n\\nThrowable overrides the toString( ) method (defined by Object) so that it returns a string containing a description of the exception. You can display this description in a println( ) statement by simply passing the exception as an argument. For example, the catch block in the preceding program can be rewritten like this:\\n\\ncatch (ArithmeticException e) {\\n\\tSystem.out.println(\"Exception: \" + e);\\n\\ta = 0; // set a to zero and continue\\n}\\n\\nWhen this version is substituted in the program, and the program is run, each divide-byzero error displays the following message:\\n\\nException: java.lang.ArithmeticException: / by zero\\n\\nWhile it is of no particular value in this context, the ability to display a description of an exception is valuable in other circumstances—particularly when you are experimenting with exceptions or when you are debugging.\\n\\nFinally\\n\\nWhen exceptions are thrown, execution in a method takes a rather abrupt, nonlinear path that alters the normal flow through the method. Depending upon how the method is coded, it is even possible for an exception to cause the method to return prematurely. This could be a problem in some methods. For example, if a method opens a file upon entry and closes it upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. The finally keyword is designed to address this contingency.\\n\\nFinally creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement matches the exception. Any time a method is about to return to the caller from inside a try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also executed just before the method returns. This can be useful for closing file handles and freeing up any other resources that might have been allocated at the beginning of a method with the intent of disposing of them before returning. The finally clause is optional. However, each try statement requires at least one catch or a finally clause.\\n\\nHere is an example program that shows three methods that exit in various ways, none without executing their finally clauses:\\n\\n// Demonstrate finally.\\nclass FinallyDemo {\\n\\t// Through an exception out of the method.\\n\\tstatic void procA() {\\n\\t\\ttry {\\n\\t\\t\\tSystem.out.println(\"inside procA\");\\n\\t\\t\\tthrow new RuntimeException(\"demo\");\\n\\t\\t} finally {\\n\\t\\t\\tSystem.out.println(\"procA's finally\");\\n\\t\\t}\\n\\t}\\n\\n\\t// Return from within a try block.\\n\\tstatic void procB() {\\n\\t\\ttry {\\n\\t\\t\\tSystem.out.println(\"inside procB\");\\n\\t\\t\\treturn;\\n\\t\\t} finally {\\n\\t\\t\\tSystem.out.println(\"procB's finally\");\\n\\t\\t}\\n\\t}\\n\\n\\t// Execute a try block normally.\\n\\tstatic void procC() {\\n\\t\\ttry {\\n\\t\\t\\tSystem.out.println(\"inside procC\");\\n\\t\\t} finally {\\n\\t\\t\\tSystem.out.println(\"procC's finally\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String args[]) {\\n\\t\\ttry {\\n\\t\\t\\tprocA();\\n\\t\\t} catch (Exception e) {\\n\\t\\t\\tSystem.out.println(\"Exception caught\");\\n\\t\\t}\\n\\t\\tprocB(); \\n\\t\\tprocC();\\n\\t} \\n}\\n\\nHere is the output generated by the preceding program: \\n \\ninside procA \\nprocAs finally \\nException caught \\ninside procB \\nprocBs finally \\ninside procC \\nprocCs finally \\n\\nIn this example, procA( ) prematurely breaks out of the try by throwing an exception. The finally clause is executed on the way out. procB( )s try statement is exited via a return statement. The finally clause is executed before procB( ) returns. In procC( ), the try statement executes normally, without error. However, the finally block is still executed.\\n",
198 "49",
199 "EXCEPTION HANDLING, throws, throw",
200 "Throw\\n\\nSo far, you have only been catching exceptions that are thrown by the Java run-time system. However, it is possible for your program to throw an exception explicitly, using the throw statement. The general form of throw is shown here: \\n\\nthrow ThrowableInstance; \\n\\nHere, Throwable Instance must be an object of type Throwable or a subclass of Throwable.\\n \\nThere are two ways you can obtain a Throwable object:\\n \\nusing a parameter in a catch clause, or creating one with the new operator. The flow of execution stops immediately after the throw statement; any subsequent statements are not executed. The nearest enclosing try block is inspected to see if it has a catch statement that matches the type of exception. If it does find a match, control is transferred to that statement. If not, then the next enclosing try statement is inspected, and so on. If no matching catch is found, then the default exception handler halts the program and prints the stack trace.\\n\\nHere is a sample program that creates and throws an exception. The handler that catches the exception rethrows it to the outer handler. \\n\\n// Demonstrate throw. \\nclass ThrowDemo { \\n\\tstatic void demoproc() { \\n\\t\\ttry { \\n\\t\\t\\tthrow new NullPointerException(\"demo\"); \\n\\t\\t} catch(NullPointerException e) { \\n\\t\\t\\tSystem.out.println(\"Caught inside demoproc.\"); \\n\\t\\t\\tthrow e; // rethrow the exception \\t\\t} \\n\\t}\\n\\tpublic static void main(String args[]) { \\n\\t\\ttry { \\n\\t\\t\\tdemoproc(); \\n\\t\\t} catch(NullPointerException e) { \\n\\t\\t\\tSystem.out.println(\"Recaught: \" + e); \\n\\t\\t} \\n\\t} \\n}\\n\\nHere is the resulting output: \\n\\nCaught inside demoproc. \\nRecaught: java.lang.NullPointerException: demo \\n\\nThis program gets two chances to deal with the same error. First, main( ) sets up an exception context and then calls demoproc( ). The demoproc( ) method then sets up another exceptionhandling context and immediately throws a new instance of NullPointerException, which is caught on the next line. The exception is then rethrown.\\n \\nThe program also illustrates how to create one of Javas standard exception objects. Pay close attention to this line: \\n\\nthrow new NullPointerException(\"demo\"); \\n\\nHere, new is used to construct an instance of NullPointerException. Many of Javas builtin run-time exceptions have at least two constructors: one with no parameter and one that takes a string parameter. When the second form is used, the argument specifies a string that describes the exception. This string is displayed when the object is used as an argument to print( ) or println( ). It can also be obtained by a call to getMessage( ), which is defined by Throwable.\\n \\nThrows\\n\\nIf a method is capable of causing an exception that it does not handle, it must specify this behavior so that callers of the method can guard themselves against that exception. You do this by including a throws clause in the method’s declaration. Athrows clause lists the types of exceptions that a method might throw. This is necessary for all exceptions, except those of type Error or RuntimeException, or any of their subclasses. All other exceptions that a method can throw must be declared in the throws clause. If they are not, a compile-time error will result. \\nThis is the general form of a method declaration that includes a throws clause:\\n\\ntype method-name(parameter-list) throws exception-list\\n\\n{\\n\\t// body of method \\n}\\n\\nHere, exception-list is a comma-separated list of the exceptions that a method can throw. Following is an example of an incorrect program that tries to throw an exception that it does not catch. Because the program does not specify a throws clause to declare this fact, the program will not compile.\\n \\n// This program contains an error and will not compile. class ThrowsDemo { \\n\\tstatic void throwOne() {\\n\\t\\tSystem.out.println(\"Inside throwOne.\");\\n\\t\\tthrow new IllegalAccessException(\"demo\"); \\n\\t}\\n\\tpublic static void main(String args[]) { \\n\\t\\tthrowOne(); \\n\\t} \\n}\\n \\nTo make this example compile, you need to make two changes. First, you need to declare that throwOne( ) throws IllegalAccessException. Second, main( ) must define a try/catch statement that catches this exception. \\n\\nThe corrected example is shown here: \\n\\n// This is now correct. \\nclass ThrowsDemo { \\n\\tstatic void throwOne() throws IllegalAccessException { \\n\\t\\tSystem.out.println(\"Inside throwOne.\"); \\n\\t\\tthrow new IllegalAccessException(\"demo\"); \\t}\\n\\tpublic static void main(String args[]) { \\n\\t\\ttry { \\n\\t\\t\\tthrowOne(); \\n\\t\\t} catch (IllegalAccessException e) { \\n\\t\\t\\tSystem.out.println(\"Caught \" + e); \\n\\t\\t} \\n\\t} \\n} \\n\\nHere is the output generated by running this example program: \\n\\ninside throwOne \\ncaught java.lang.IllegalAccessException: demo\\n",
201 "50",
202 "THREADS, the main thread",
203 "Multithreaded Programming \\n\\nJava provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.\\n \\nWhen a Java program starts up, one thread begins running immediately. This is usually called the main thread of your program, because it is the one that is executed when your program begins. The main thread is important for two reasons: \\n• It is the thread from which other child threads will be spawned. \\n• Often, it must be the last thread to finish execution because it performs various \\nshutdown actions.\\n\\nThe main method begins the main thread:\\n \\npublic static void main(String args[]) {\\n\\t// code\\n\\t// …\\n}\\n\\nLets look more closely at the method main:\\n\\nIn Java the public means that something is available across packages. Thus main() is public.\\n\\nIn Java, main is a static method. This means the method is part of its class and not part of objects. When you run the program does not yet exist a single object.\\n\\nvoid - means that the program does not return any values.\\n\\nString args [] is an argument. In most cases, not used. The fact that, in the Java language are allowed to use several methods called main (), even in the same class. Therefore, in the present main method contains arguments (String [] args). Thus, \"String [] args\" used for additional identification method main, which runs the main stream.\\n\\nAlthough the main thread is created automatically when your program is started, it can be controlled through a Thread object. To do so, you must obtain a reference to it by calling the method currentThread( ), which is a public static member of Thread. Its general form is shown here: \\n\\nstatic Thread currentThread( ) \\n\\nThis method returns a reference to the thread in which it is called. Once you have a reference to the main thread, you can control it just like any other thread. Lets begin by reviewing the following example:\\n\\n// Controlling the main Thread. \\nclass CurrentThreadDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tThread t = Thread.currentThread(); \\n\\t\\tSystem.out.println(\"Current thread: \" + t); \\n\\t\\t// change the name of the thread \\n\\t\\tt.setName(\"My Thread\"); \\n\\t\\tSystem.out.println(\"After name change: \" + t); \\n\\t} \\n}\\n \\nHere is the output generated by this program: \\nCurrent thread: Thread[main,5,main] \\nAfter name change: Thread[My Thread,5,main]\\n \\nIn this program, a reference to the current thread (the main thread, in this case) is obtained by calling currentThread( ), and this reference is stored in the local variable t. Next, the program displays information about the thread. The program then calls setName( ) to change the internal name of the thread. Information about the thread is then redisplayed. \\n\\nThe output produced when t is used as an argument to println( ). This displays, in order: the name of the thread, its priority, and the name of its group. By default, the name of the main thread is main. Its priority is 5, which is the default value, and main is also the name of the group of threads to which this thread belongs. A thread group is a data structure that controls the state of a collection of threads as a whole. After the name of the thread is changed, t is again output. This time, the new name of the thread is displayed.\\n\\nThe Thread class defines several methods that help manage threads: \\n\\ngetName - Obtain a threads name. \\ngetPriority - Obtain a threads priority. \\nisAlive - Determine if a thread is still running. \\njoin - Wait for a thread to terminate. \\nrun - Entry point for the thread. \\nsleep - Suspend a thread for a period of time. \\nstart - Start a thread by calling its run method.\\n\\nThe sleep( ) method causes the thread from which it is called to suspend execution for the specified period of milliseconds. Its general form is shown here: \\n\\nstatic void sleep(long milliseconds) throws InterruptedException \\n\\nThe number of milliseconds to suspend is specified in milliseconds. This method may throw an InterruptedException, thus we need try/catch.\\n",
204 "51",
205 "THREADS, runnable, start(), sleep(), run()",
206 "Implementing Runnable \\n\\nThe easiest way to create a thread is to create a class that implements the Runnable interface. Runnable abstracts a unit of executable code. You can construct a thread on any object that implements Runnable. To implement Runnable, a class need only implement a single method called run( ), which is declared like this: \\n\\npublic void run( ) \\n\\nInside run( ), you will define the code that constitutes the new thread. It is important to understand that run( ) can call other methods, use other classes, and declare variables, just like the main thread can.\\n\\nAfter you create a class that implements Runnable, you will instantiate an object of type Thread from within that class:\\n \\nThread(Runnable threadOb, String threadName) \\n\\nIn this constructor, threadOb is an instance of a class that implements the Runnable interface. This defines where execution of the thread will begin. The name of the new thread is specified by threadName. \\n\\nAfter the new thread is created, it will not start running until you call its start( ) method, which is declared within Thread. In essence, start( ) executes a call to run( ). The start( ) method is shown here: \\n\\nvoid start( ) \\n\\nHere is an example that creates a new thread and starts it running: \\n// Create a second thread. \\nclass NewThread implements Runnable { \\n\\tThread t; \\n\\tNewThread() { \\n\\t\\t// Create a new, second thread \\n\\t\\tt = new Thread(this, \"Demo Thread\"); \\n\\t\\tSystem.out.println(\"Child thread: \" + t); \\n\\t\\tt.start(); // Start the thread \\n\\t}\\n\\t// This is the entry point for the second thread. \\n\\tpublic void run() { \\n\\t\\ttry { \\n\\t\\t\\tfor(int i = 5; i > 0; i - - ) { \\n\\t\\t\\t\\tSystem.out.println(\"Child Thread: \" + i); \\n\\t\\t\\t\\tThread.sleep(500); \\n\\t\\t\\t} \\n\\t\\t} catch (InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Child interrupted.\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"Exiting child thread.\"); \\n\\t} \\n}\\n\\nclass ThreadDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tnew NewThread(); // create a new thread \\n\\t\\ttry { \\n\\t\\t\\tfor(int i = 5; i > 0; i - - ) { \\n\\t\\t\\t\\tSystem.out.println(\"Main Thread: \" + i); \\n\\t\\t\\t\\tThread.sleep(1000); \\n\\t\\t\\t} \\n\\t\\t} catch (InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Main thread interrupted.\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"Main thread exiting.\"); \\n\\t} \\n}\\n \\nInside NewThreads constructor, a new Thread object is created by the following statement: \\n\\nt = new Thread(this, \"Demo Thread\"); \\n\\nPassing this as the first argument indicates that you want the new thread to call the run( ) method on this object. Next, start( ) is called, which starts the thread of execution beginning at the run( ) method. This causes the child threads for loop to begin. After calling start( ), NewThreads constructor returns to main( ). When the main thread resumes, it enters its for loop. Both threads continue running, sharing the CPU, until their loops finish. The output produced by this program is as follows. (Your output may vary based on processor speed and task load.) \\n\\nChild thread: Thread[Demo Thread,5,main] \\nMain Thread: 5 \\nChild Thread: 5 \\nChild Thread: 4 \\nMain Thread: 4 \\nChild Thread: 3 \\nChild Thread: 2 \\nMain Thread: 3 \\nChild Thread: 1 \\nExiting child thread. \\nMain Thread: 2 \\nMain Thread: 1 \\nMain thread exiting. \\n\\nAs mentioned earlier, in a multithreaded program, often the main thread must be the last thread to finish running. In fact, for some older JVMs, if the main thread finishes before a child thread has completed, then the Java run-time system may hang. The preceding program ensures that the main thread finishes last, because the main thread sleeps for 1,000 milliseconds between iterations, but the child thread sleeps for only 500 milliseconds. This causes the child thread to terminate earlier than the main thread. Shortly, you will see a better way to wait for a thread to finish. \\n",
207 "52",
208 "THREADS, isAlive(), join()",
209 "Using isAlive( ) and join( ) \\n\\nAs mentioned, often you will want the main thread to finish last. In the preceding examples, this is accomplished by calling sleep( ) within main( ), with a long enough delay to ensure that all child threads terminate prior to the main thread. However, this is hardly a satisfactory solution, and it also raises a larger question: How can one thread know when another thread has ended? Fortunately, Thread provides a means by which you can answer this question. \\n \\nTwo ways exist to determine whether a thread has finished. First, you can call isAlive( ) on the thread. This method is defined by Thread, and its general form is shown here:\\n \\nfinal boolean isAlive( ) \\n\\nThe isAlive( ) method returns true if the thread upon which it is called is still running. It returns false otherwise. \\nWhile isAlive( ) is occasionally useful, the method that you will more commonly use to wait for a thread to finish is called join( ), shown here: \\n\\nfinal void join( ) throws InterruptedException \\n\\nThis method waits until the thread on which it is called terminates. Its name comes from the concept of the calling thread waiting until the specified thread joins it. \\n\\nHere is an improved version of the preceding example that uses join( ) to ensure that the main thread is the last to stop. It also demonstrates the isAlive( ) method:\\n\\n// Using join() to wait for threads to finish. \\nclass NewThread implements Runnable { \\n\\tString name; // name of thread \\n\\tThread t; \\n\\tNewThread(String threadname) { \\n\\t\\tname = threadname; \\n\\t\\tt = new Thread(this, name); \\n\\t\\tSystem.out.println(\"New thread: \" + t); \\n\\t\\tt.start(); // Start the thread \\n\\t}\\n\\t// This is the entry point for thread. \\n\\tpublic void run() { \\n\\t\\ttry { \\n\\t\\t\\tfor(int i = 5; i > 0; i - -) { \\n\\t\\t\\t\\tSystem.out.println(name + \": \" + i); \\n\\t\\t\\t\\tThread.sleep(1000); \\n\\t\\t\\t} \\n\\t\\t} catch (InterruptedException e) { \\n\\t\\t\\tSystem.out.println(name + \" interrupted.\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(name + \" exiting.\"); \\n\\t} \\n}\\n\\nclass DemoJoin { \\n\\tpublic static void main(String args[]) { \\n\\t\\tNewThread ob1 = new NewThread(\"One\"); \\n\\t\\tNewThread ob2 = new NewThread(\"Two\"); \\n\\t\\tNewThread ob3 = new NewThread(\"Three\");\\n\\t\\tSystem.out.println(\"Thread One is alive: \" \\n\\t\\t+ ob1.t.isAlive()); \\n\\t\\tSystem.out.println(\"Thread Two is alive: \" \\n\\t\\t+ ob2.t.isAlive()); \\n\\t\\tSystem.out.println(\"Thread Three is alive: \" \\n\\t\\t+ ob3.t.isAlive()); \\n\\t\\t// wait for threads to finish \\n\\t\\ttry { \\n\\t\\t\\tSystem.out.println(\"Waiting for threads to finish.\"); \\n\\t\\t\\tob1.t.join(); \\n\\t\\t\\tob2.t.join(); \\n\\t\\t\\tob3.t.join(); \\n\\t\\t} catch (InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Main thread Interrupted\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"Thread One is alive: \" \\n\\t\\t+ ob1.t.isAlive()); \\n\\t\\tSystem.out.println(\"Thread Two is alive: \" \\n\\t\\t+ ob2.t.isAlive()); \\n\\t\\tSystem.out.println(\"Thread Three is alive: \" \\n\\t\\t+ ob3.t.isAlive()); \\n\\t\\tSystem.out.println(\"Main thread exiting.\"); \\n\\t} \\n}\\n\\nSample output from this program is shown here. (Your output may vary based on processor speed and task load.) \\n\\nNew thread: Thread[One,5,main] \\nNew thread: Thread[Two,5,main] \\nNew thread: Thread[Three,5,main] \\nThread One is alive: true \\nThread Two is alive: true \\nThread Three is alive: true \\nWaiting for threads to finish. \\nOne: 5 \\nTwo: 5 \\nThree: 5 \\nOne: 4 \\nTwo: 4 \\nThree: 4 \\nOne: 3 \\nTwo: 3 \\nThree: 3 \\nOne: 2 \\nTwo: 2 \\nThree: 2\\nOne: 1 \\nTwo: 1 \\nThree: 1 \\nTwo exiting. \\nThree exiting. \\nOne exiting. \\nThread One is alive: false \\nThread Two is alive: false \\nThread Three is alive: false \\nMain thread exiting. \\nAs you can see, after the calls to join( ) return, the threads have stopped executing. \\n",
210 "53",
211 "THREADS, synchronized",
212 "Synchronization \\n\\nWhen two or more threads need access to a shared resource, they need some way to ensure that the resource will be used by only one thread at a time. The process by which this is achieved is called synchronization. \\n\\nKey to synchronization is the concept of the monitor (also called a semaphore). A monitor is an object that is used as a mutually exclusive lock, or mutex. Only one thread can own a monitor at a given time. When a thread acquires a lock, it is said to have entered the monitor. All other threads attempting to enter the locked monitor will be suspended until the first thread exits the monitor. These other threads are said to be waiting for the monitor. A thread that owns a monitor can reenter the same monitor if it so desires. \\n\\nUsing Synchronized Methods \\nSynchronization is easy in Java, because all objects have their own implicit monitor associated with them. To enter an objects monitor, just call a method that has been modified with the synchronized keyword. While a thread is inside a synchronized method, all other threads that try to call it (or any other synchronized method) on the same instance have to wait. To exit the monitor and relinquish control of the object to the next waiting thread, the owner of the monitor simply returns from the synchronized method.\\n \\nTo understand the need for synchronization, lets begin with a simple example that does not use it—but should. The following program has three simple classes. The first one, Callme, has a single method named call( ). The call( ) method takes a String parameter called msg. This method tries to print the msg string inside of square brackets. The interesting thing to notice is that after call( ) prints the opening bracket and the msg string, it calls Thread .sleep(1000), which pauses the current thread for one second. \\nThe constructor of the next class, Caller, takes a reference to an instance of the Callme class and a String, which are stored in target and msg, respectively. The constructor also creates a new thread that will call this objects run( ) method. The thread is started immediately. The run( ) method of Caller calls the call( ) method on the target instance of Callme, passing in the msg string. Finally, the Synch class starts by creating a single instance of Callme, and three instances of Caller, each with a unique message string. The same instance of Callme is passed to each Caller. \\n\\n// This program is not synchronized. \\nclass Callme { \\n\\tvoid call(String msg) { \\n\\t\\tSystem.out.print(\"[\" + msg); \\n\\t\\ttry { \\n\\t\\t\\tThread.sleep(1000); \\n\\t\\t} catch(InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Interrupted\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"]\"); \\n\\t} \\n}\\n\\nclass Caller implements Runnable { \\n\\tString msg; \\n\\tCallme target; \\n\\tThread t;\\n\\tpublic Caller(Callme targ, String s) { \\n\\t\\ttarget = targ; \\n\\t\\tmsg = s; \\n\\t\\tt = new Thread(this); \\n\\t\\tt.start(); \\n\\t}\\n\\tpublic void run() { \\n\\t\\ttarget.call(msg); \\n\\t} \\n}\\n\\nclass Synch { \\n\\tpublic static void main(String args[]) { \\n\\t\\tCallme target = new Callme(); \\n\\t\\tCaller ob1 = new Caller(target, \"Hello\"); \\n\\t\\tCaller ob2 = new Caller(target, \"Synchronized\"); \\n\\t\\tCaller ob3 = new Caller(target, \"World\"); \\n\\t\\t// wait for threads to end \\n\\t\\ttry { \\n\\t\\t\\tob1.t.join(); \\n\\t\\t\\tob2.t.join(); \\n\\t\\t\\tob3.t.join(); \\n\\t\\t} catch(InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Interrupted\"); \\n\\t\\t} \\n\\t} \\n}\\n\\nHere is the output produced by this \\n\\n[Hello[Synchronized[World] \\n]\\n] \\n\\nAs you can see, by calling sleep( ), the call( ) method allows execution to switch to another thread. This results in the mixed-up output of the three message strings. In this program, nothing exists to stop all three threads from calling the same method, on the same object, at the same time. This is known as a race condition, because the three threads are racing each other to complete the method. This example used sleep( ) to make the effects repeatable and obvious. In most situations, a race condition is more subtle and less predictable, because you cant be sure when the context switch will occur. This can cause a program to run right one time and wrong the next. \\n\\nTo fix the preceding program, you must serialize access to call( ). That is, you must restrict its access to only one thread at a time. To do this, you simply need to precede call( )s definition with the keyword synchronized, as shown here: \\n\\nclass Callme { \\n\\tsynchronized void call(String msg) { \\n… \\n\\nThis prevents other threads from entering call( ) while another thread is using it. After synchronized has been added to call( ), the output of the program is as follows: \\n\\n[Hello] \\n[Synchronized] \\n[World] \\n\\nAny time that you have a method, or group of methods, that manipulates the internal state of an object in a multithreaded situation, you should use the synchronized keyword to guard the state from race conditions. Remember, once a thread enters any synchronized method on an instance, no other thread can enter any other synchronized method on the same instance. However, nonsynchronized methods on that instance will continue to be callable. \\n \\nWhile creating synchronized methods within classes that you create is an easy and effective means of achieving synchronization, it will not work in all cases. To understand why, consider the following. Imagine that you want to synchronize access to objects of a class that was not designed for multithreaded access. That is, the class does not use synchronized methods. Further, this class was not created by you, but by a third party, and you do not have access to the source code. Thus, you cant add synchronized to the appropriate methods within the class. How can access to an object of this class be synchronized? Fortunately, the solution to this problem is quite easy: You simply put calls to the methods defined by this class inside a synchronized block. \\n\\nThis is the general form of the synchronized statement: \\n\\nsynchronized(object) { \\n\\t// statements to be synchronized \\n} \\n\\nHere, object is a reference to the object being synchronized. A synchronized block ensures that a call to a method that is a member of object occurs only after the current thread has successfully entered objects monitor. \\nHere is an alternative version of the preceding example, using a synchronized block within the run( ) method: \\n\\n// This program uses a synchronized block. \\nclass Callme { \\n\\tvoid call(String msg) { \\n\\t\\tSystem.out.print(\"[\" + msg); \\n\\t\\ttry { \\n\\t\\t\\tThread.sleep(1000); \\n\\t\\t} catch (InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Interrupted\"); \\n\\t\\t}\\n\\t\\tSystem.out.println(\"]\"); \\n\\t} \\n}\\n\\nclass Caller implements Runnable { \\n\\tString msg; \\n\\tCallme target; \\n\\tThread t; \\n\\tpublic Caller(Callme targ, String s) { \\n\\t\\ttarget = targ; \\n\\t\\tmsg = s; \\n\\t\\tt = new Thread(this); \\n\\t\\tt.start(); \\n\\t}\\n\\t// synchronize calls to call() \\n\\tpublic void run() { \\n\\t\\tsynchronized(target) { // synchronized block \\n\\t\\t\\ttarget.call(msg); \\n\\t\\t} \\n\\t} \\n}\\n\\nclass Synch1 { \\n\\tpublic static void main(String args[]) { \\n\\t\\tCallme target = new Callme(); \\n\\t\\tCaller ob1 = new Caller(target, \"Hello\"); \\n\\t\\tCaller ob2 = new Caller(target, \"Synchronized\"); \\n\\t\\tCaller ob3 = new Caller(target, \"World\"); \\n\\t\\t// wait for threads to end \\n\\t\\ttry { \\n\\t\\t\\tob1.t.join(); \\n\\t\\t\\tob2.t.join(); \\n\\t\\t\\tob3.t.join(); \\n\\t\\t} catch(InterruptedException e) { \\n\\t\\t\\tSystem.out.println(\"Interrupted\"); \\n\\t\\t} \\n\\t} \\n}\\n\\nHere, the call( ) method is not modified by synchronized. Instead, the synchronized statement is used inside Callers run( ) method. This causes the same correct output as the preceding example, because each thread waits for the prior one to finish before proceeding. \\n",
213 "54",
214 "ENUMERATIONS, examples",
215 "Enumerations\\n \\nAn enumeration is created using the enum keyword. For example, here is a simple enumeration that lists various apple varieties: \\n\\n// An enumeration of apple varieties. \\nenum Apple { \\n\\tJonathan, GoldenDel, RedDel, Winesap, Cortland \\n} \\n\\nThe identifiers Jonathan, GoldenDel, and so on, are called enumeration constants. Each is implicitly declared as a public, static final member of Apple. Furthermore, their type is the type of the enumeration in which they are declared, which is Apple in this case. Thus, in the language of Java, these constants are called self-typed, in which self refers to the enclosing enumeration. \\nOnce you have defined an enumeration, you can create a variable of that type. However, even though enumerations define a class type, you do not instantiate an enum using new. Instead, you declare and use an enumeration variable in much the same way as you do one of the primitive types. For example, this declares ap as a variable of enumeration type Apple: \\n\\nApple ap; \\n\\nBecause ap is of type Apple, the only values that it can be assigned (or can contain) are those defined by the enumeration. For example, this assigns ap the value RedDel: \\n\\nap = Apple.RedDel; \\n\\nNotice that the symbol RedDel is preceded by Apple. Two enumeration constants can be compared for equality by using the = = relational operator. For example, this statement compares the value in ap with the GoldenDel constant: \\n\\nif(ap == Apple.GoldenDel) // … \\n\\nAn enumeration value can also be used to control a switch statement. Of course, all of the case statements must use constants from the same enum as that used by the switch expression. For example, this switch is perfectly valid: \\n\\n// Use an enum to control a switch statement. \\nswitch(ap) { \\n\\tcase Jonathan: \\n\\t// … \\n\\tcase Winesap: \\n\\t// … \\n\\nNotice that in the case statements, the names of the enumeration constants are used without being qualified by their enumeration type name. That is, Winesap, not Apple.Winesap, is used. This is because the type of the enumeration in the switch expression has already implicitly specified the enum type of the case constants. There is no need to qualify the constants in the case statements with their enum type name. In fact, attempting to do so will cause a compilation error. \\n\\nWhen an enumeration constant is displayed, such as in a println( ) statement, its name is output. For example, given this statement: \\n\\nSystem.out.println(Apple.Winesap); \\n\\nthe name Winesap is displayed. \\n\\nThe following program puts together all of the pieces and demonstrates the Apple enumeration: \\n\\n// An enumeration of apple varieties. \\nenum Apple { \\n\\tJonathan, GoldenDel, RedDel, Winesap, Cortland \\n}\\nclass EnumDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tApple ap; \\n\\t\\tap = Apple.RedDel; \\n\\t\\t// Output an enum value. \\n\\t\\tSystem.out.println(\"Value of ap: \" + ap); \\n\\t\\tSystem.out.println(); \\n\\t\\tap = Apple.GoldenDel; \\n\\t\\t// Compare two enum values. \\n\\t\\tif(ap == Apple.GoldenDel) \\n\\t\\tSystem.out.println(\"ap contains GoldenDel.\"); \\n\\t\\t// Use an enum to control a switch statement. \\n\\t\\tswitch(ap) { \\n\\t\\tcase Jonathan: \\n\\t\\t\\tSystem.out.println(\"Jonathan is red.\"); \\n\\t\\t\\tbreak; \\n\\t\\tcase GoldenDel: \\n\\t\\t\\tSystem.out.println(\"Golden Delicious is yellow.\"); \\n\\t\\t\\tbreak; \\n\\t\\tcase RedDel: \\n\\t\\t\\tSystem.out.println(\"Red Delicious is red.\"); \\n\\t\\t\\tbreak; \\n\\t\\tcase Winesap: \\n\\t\\t\\tSystem.out.println(\"Winesap is red.\"); \\n\\t\\t\\tbreak; \\n\\t\\tcase Cortland: \\n\\t\\t\\tSystem.out.println(\"Cortland is red.\"); \\n\\t\\t\\tbreak; \\n\\t\\t} \\n\\t} \\n} \\n\\nThe output from the program is shown here: \\n\\nValue of ap: RedDel \\nap contains GoldenDel. \\nGolden Delicious is yellow.\\n",
216 "55",
217 "ENUMERATIONS, valueOf(), values()",
218 "The values( ) and valueOf( ) Methods \\nAll enumerations automatically contain two predefined methods: values( ) and valueOf( ). \\n\\nTheir general forms are shown here: \\n\\npublic static enum-type[ ] values( ) \\npublic static enum-type valueOf(String str) \\n\\nThe values( ) method returns an array that contains a list of the enumeration constants. The valueOf( ) method returns the enumeration constant whose value corresponds to the string passed in str. In both cases, enum-type is the type of the enumeration. For example, in the case of the Apple enumeration shown earlier, the return type of Apple.valueOf(Winesap) is Winesap. \\nThe following program demonstrates the values( ) and valueOf( ) methods: \\n\\n// Use the built-in enumeration methods. \\n// An enumeration of apple varieties. \\nenum Apple { \\n\\tJonathan, GoldenDel, RedDel, Winesap, Cortland \\n}\\nclass EnumDemo2 { \\n\\tpublic static void main(String args[]){ \\n\\t\\tApple ap; \\n\\t\\tSystem.out.println(\"Here are all Apple constants:\"); \\n\\t\\t// use values() \\n\\t\\tApple allapples[] = Apple.values(); \\n\\t\\tfor(Apple a : allapples){ \\n\\t\\t\\tSystem.out.println(a); \\n\\t\\t}\\n\\t\\tSystem.out.println(); \\n\\t\\t// use valueOf() \\n\\t\\tap = Apple.valueOf(\"Winesap\"); \\n\\t\\tSystem.out.println(\"ap contains \" + ap); \\n\\t} \\n}\\n\\nThe output from the program is shown here: \\nHere are all Apple constants: \\nJonathan \\nGoldenDel \\nRedDel \\nWinesap \\nCortland \\n\\nap contains Winesap\\n\\nNotice that this program uses a for-each style for loop to cycle through the array of constants obtained by calling values( ). For the sake of illustration, the variable allapples was created and assigned a reference to the enumeration array. However, this step is not necessary because the for could have been written as shown here, eliminating the need for the allapples variable: \\n\\nfor(Apple a : Apple.values()) \\nSystem.out.println(a); \\n\\nNow, notice how the value corresponding to the name Winesap was obtained by calling valueOf( ). \\n\\nap = Apple.valueOf(\"Winesap\"); \\n\\nAs explained, valueOf( ) returns the enumeration value associated with the name of the constant represented as a String.\\n",
219 "56",
220 "ENUMERATIONS, ordinal(), compareTo(), equals()",
221 "Enumerations Inherit Enum \\n \\nAlthough you cant inherit a superclass when declaring an enum, all enumerations automatically inherit one: java.lang.Enum. This class defines several methods that are available for use by all enumerations. \\n \\nYou can obtain a value that indicates an enumeration constants position in the list of constants. This is called its ordinal value, and it is retrieved by calling the ordinal( ) method, shown here: \\n \\nfinal int ordinal( ) \\n \\nIt returns the ordinal value of the invoking constant. Ordinal values begin at zero. Thus, in the Apple enumeration, Jonathan has an ordinal value of zero, GoldenDel has an ordinal value of 1, RedDel has an ordinal value of 2, and so on. \\n \\nYou can compare the ordinal value of two constants of the same enumeration by using the compareTo( ) method. It has this general form: \\n \\nfinal int compareTo(enum-type e) \\n \\nHere, enum-type is the type of the enumeration, and e is the constant being compared to the invoking constant. Remember, both the invoking constant and e must be of the same enumeration. If the invoking constant has an ordinal value less than es, then compareTo( ) returns a negative value. If the two ordinal values are the same, then zero is returned. If the invoking constant has an ordinal value greater than es, then a positive value is returned. \\n \\nYou can compare for equality an enumeration constant with any other object by using equals( ), which overrides the equals( ) method defined by Object. Although equals( ) can compare an enumeration constant to any other object, those two objects will only be equal if they both refer to the same constant, within the same enumeration. Simply having ordinal values in common will not cause equals( ) to return true if the two constants are from different enumerations. \\n \\nRemember, you can compare two enumeration references for equality by using = =. \\n \\nThe following program demonstrates the ordinal( ), compareTo( ), and equals( ) methods: \\n\\n// Demonstrate ordinal(), compareTo(), and equals(). \\n// An enumeration of apple varieties. \\nenum Apple { \\n Jonathan, GoldenDel, RedDel, Winesap, Cortland \\n} \\n \\nclass EnumDemo4 { \\n\\tpublic static void main(String args[]){ \\n\\t\\tApple ap, ap2, ap3; \\n\\t\\t// Obtain all ordinal values using ordinal(). \\n\\t\\tSystem.out.println(\"Here are all apple constants\" + \\n\\t\\t\" and their ordinal values: \"); \\n\\t\\tfor(Apple a : Apple.values()){ \\n\\t\\t\\tSystem.out.println(a + \" \" + a.ordinal()); \\n\\t\\t} \\n\\t\\tap = Apple.RedDel; \\n\\t\\tap2 = Apple.GoldenDel; \\n\\t\\tap3 = Apple.RedDel; \\n\\t\\tSystem.out.println(); \\n\\t\\t// Demonstrate compareTo() and equals() \\n\\t\\tif(ap.compareTo(ap2) < 0) \\n\\t\\tSystem.out.println(ap + \" comes before \" + ap2); \\n\\t\\tif(ap.compareTo(ap2) > 0) \\n\\t\\tSystem.out.println(ap2 + \" comes before \" + ap); \\n\\t\\tif(ap.compareTo(ap3) == 0) \\n\\t\\tSystem.out.println(ap + \" equals \" + ap3); \\n \\t\\tSystem.out.println(); \\n\\t\\tif(ap.equals(ap2)) \\n\\t\\tSystem.out.println(\"Error!\"); \\n\\t\\tif(ap.equals(ap3)) \\n\\t\\tSystem.out.println(ap + \" equals \" + ap3); \\n\\t\\tif(ap == ap3) \\n\\t\\tSystem.out.println(ap + \" == \" + ap3); \\n\\t} \\n} \\n \\nThe output from the program is shown here: \\n \\nHere are all apple constants and their ordinal values: \\nJonathan 0 \\nGoldenDel 1 \\nRedDel 2 \\nWinesap 3 \\nCortland 4 \\nGoldenDel comes before RedDel \\nRedDel equals RedDel \\nRedDel equals RedDel \\nRedDel == RedDel \\n",
222 "57",
223 "I/O STREAMS, the file class",
224 "File \\n\\nAlthough most of the classes defined by java.io operate on streams, the File class does not. It deals directly with files and the file system. That is, the File class does not specify how information is retrieved from or stored in files; it describes the properties of a file itself. A File object is used to obtain or manipulate the information associated with a disk file, such as the permissions, time, date, and directory path, and to navigate subdirectory hierarchies. Files are a primary source and destination for data within many programs. A directory in Java is treated simply as a File with one additional property—a list of filenames that can be examined by the list( ) method. \\n\\nThe following constructors can be used to create File objects: \\n\\nFile(String directoryPath) \\nFile(String directoryPath, String filename) \\nFile(File dirObj, String filename) \\nFile(URI uriObj)\\n\\nHere, directoryPath is the path name of the file, filename is the name of the file or subdirectory, dirObj is a File object that specifies a directory, and uriObj is a URI object that describes a file. \\nThe following example creates three files: f1, f2, and f3. The first File object is constructed with a directory path as the only argument. The second includes two arguments—the path and the filename. The third includes the file path assigned to f1 and a filename; f3 refers to the same file as f2. \\n\\nFile f1 = new File(\"/\"); \\nFile f2 = new File(\"/\",\"autoexec.bat\"); \\nFile f3 = new File(f1,\"autoexec.bat\");\\n \\nFile defines many methods that obtain the standard properties of a File object. For example, getName( ) returns the name of the file, getParent( ) returns the name of the parent directory, and exists( ) returns true if the file exists, false if it does not. The File class, however, is not symmetrical. By this, we mean that there are a few methods that allow you to examine the properties of a simple file object, but no corresponding function exists to change those attributes. The following example demonstrates several of the File methods:\\n \\n// Demonstrate File. \\nimport java.io.File; \\nclass FileDemo { \\n\\tstatic void p(String s) { \\n\\t\\tSystem.out.println(s); \\n\\t}\\n\\tpublic static void main(String args[]) { \\n\\t\\tFile f1 = new File(\"/java/COPYRIGHT\"); \\n\\t\\tp(\"File Name: \" + f1.getName()); \\n\\t\\tp(\"Path: \" + f1.getPath()); \\n\\t\\tp(\"Abs Path: \" + f1.getAbsolutePath()); \\n\\t\\tp(\"Parent: \" + f1.getParent()); \\n\\t\\tp(f1.exists() ? \"exists\" : \"does not exist\"); \\n\\t\\tp(f1.canWrite() ? \"is writeable\" : \"is not writeable\"); \\n\\t\\tp(f1.canRead() ? \"is readable\" : \"is not readable\"); \\n\\t\\tp(\"is \" + (f1.isDirectory() ? : \"not\" + \" a directory\")); \\n\\t\\tp(f1.isFile() ? \"is normal file\" : \"might be a named pipe\"); \\n\\t\\tp(f1.isAbsolute() ? \"is absolute\" : \"is not absolute\"); \\n\\t\\tp(\"File last modified: \" + f1.lastModified()); \\n\\t\\tp(\"File size: \" + f1.length() + \" Bytes\"); \\n\\t} \\n}\\n\\nWhen you run this program, you will see something similar to the following: \\n\\nFile Name: COPYRIGHT \\nPath: /java/COPYRIGHT \\nAbs Path: /java/COPYRIGHT \\nParent: /java \\nexists \\nis writeable \\nis readable \\nis not a directory \\nis normal file \\nis absolute \\nFile last modified: 812465204000 \\nFile size: 695 Bytes \\n\\nMost of the File methods are self-explanatory. isFile( ) and isAbsolute( ) are not. isFile( ) returns true if called on a file and false if called on a directory. Also, isFile( ) returns false for some special files, such as device drivers and named pipes, so this method can be used to make sure the file will behave as a file. The isAbsolute( ) method returns true if the file has an absolute path and false if its path is relative. \\n\\nFile also includes two useful utility methods. The first is renameTo( ), shown here: \\n\\nboolean renameTo(File newName) \\n\\nHere, the filename specified by newName becomes the new name of the invoking File object. It will return true upon success and false if the file cannot be renamed (if you either attempt to rename a file so that it moves from one directory to another or use an existing filename, for example). \\n\\nThe second utility method is delete( ), which deletes the disk file represented by the path of the invoking File object. It is shown here: \\n\\nboolean delete( ) \\n\\nYou can also use delete( ) to delete a directory if the directory is empty. delete( ) returns true if it deletes the file and false if the file cannot be removed. Here are some other File methods that you will find helpful. \\n\\nvoid deleteOnExit( ) \\n\\nRemoves the file associated with the invoking object when the Java Virtual Machine terminates. \\n\\nlong getFreeSpace( ) \\n\\nReturns the number of free bytes of storage available on the partition associated with the invoking object. \\n\\nlong getTotalSpace( ) \\n\\nReturns the storage capacity of the partition associated with the invoking object. \\n \\nlong getUsableSpace( ) \\n\\nReturns the number of usable free bytes of storage available on the partition associated with the invoking object.\\n\\nboolean isHidden( ) \\n\\nReturns true if the invoking file is hidden. Returns false otherwise. \\n\\nboolean setLastModified(long millisec) \\n\\nSets the time stamp on the invoking file to that specified by millisec, which is the number of milliseconds from January 1, 1970, Coordinated Universal Time (UTC). \\n\\nboolean setReadOnly( ) \\n\\nSets the invoking file to read-only. Methods also exist to mark files as readable, writable, and executable. Because File implements the Comparable interface, the method compareTo( ) is also supported. \\n\\nDirectories \\n\\nA directory is a File that contains a list of other files and directories. When you create a File object and it is a directory, the isDirectory( ) method will return true. In this case, you can call list( ) on that object to extract the list of other files and directories inside. It has two forms. The first is shown here: \\n\\nString[ ] list( ) \\n\\nThe list of files is returned in an array of String objects. The program shown here illustrates how to use list( ) to examine the contents of a directory: \\n\\n// Using directories. \\nimport java.io.File; \\nclass DirList { \\n\\tpublic static void main(String args[]) { \\n\\t\\tString dirname = \"/java\"; \\n\\t\\tFile f1 = new File(dirname); \\n\\t\\tif (f1.isDirectory()) { \\n\\t\\t\\tSystem.out.println(\"Directory of \" + dirname); \\n\\t\\t\\tString s[] = f1.list(); \\n\\t\\t\\tfor (int i=0; i < s.length; i++) { \\n\\t\\t\\t\\tFile f = new File(dirname + \"/\" + s[i]); \\n\\t\\t\\t\\tif (f.isDirectory()) { \\n\\t\\t\\t\\t\\tSystem.out.println(s[i] + \" is a directory\"); \\n\\t\\t\\t\\t} else { \\n\\t\\t\\t\\t\\tSystem.out.println(s[i] + \" is a file\"); \\n\\t\\t\\t\\t} \\n\\t\\t\\t} \\n\\t\\t} else { \\n\\t\\t\\tSystem.out.println(dirname + \" is not a directory\"); \\n\\t\\t} \\n\\t} \\n}\\n\\nHere is sample output from the program. (Of course, the output you see will be different, based on what is in the directory.) \\nDirectory of /java \\nbin is a directory \\nlib is a directory \\ndemo is a directory \\nCOPYRIGHT is a file \\nREADME is a file \\nindex.html is a file \\ninclude is a directory \\nsrc.zip is a file \\nsrc is a directory \\n",
225 "58",
226 "I/O STREAMS, connection streams",
227 "Streams in java can be divided into two parts:\\n\\n1.connection streams\\n2.chain streams\\n\\nStreams for connection represent a connection to source or destination (file, array, sockets, etc.). When transmitting data, must be one stream for connection. Streams for connection typically are low-level. These data are usually transmitted in bytes. Sometimes it is sufficient to connect one stream, but in most cases, we need the help of chain streams.\\n\\nConnection streams are:\\n\\nFileOutputStream\\nFileInputStream\\nByteArrayOutputStream\\nByteArrayInputStream\\n\\nHere are some examples:\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\t// creates a stream for connection FileOutputStream\\n\\t\\tFileOutputStream streamOut1 = new FileOutputStream(file1);\\n\\t\\t// creates a stream for connection FileInputStream\\n\\t\\tFileInputStream streamIn1 = new FileInputStream(file1);\\n\\n\\t\\tbyte b = 99;\\n\\t\\tstreamOut1.write(b);\\n\\t\\tb = 65;\\n\\t\\tstreamOut1.write(b);\\n\\n\\t\\t// reading from a file, FileInputStream\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\n\\t\\tstreamOut1.close();\\n\\t\\tstreamIn1.close();\\n\\t}\\n}\\n\\nOutput from this program is shown here:\\n99\\n65\\n-1\\n",
228 "59",
229 "I/O STREAMS, chain streams",
230 "Streams in java can be divided into two parts:\\n\\n1.connection streams\\n2.chain streams\\n\\nStreams for connection represent a connection to source or destination (file, array, sockets, etc.). When transmitting data, must be one stream for connection. Streams for connection typically are low-level. These data are usually transmitted in bytes. Sometimes it is sufficient to connect one stream, but in most cases, we need the help of chain streams.\\n\\nTo write double data, lines and objects, we need chain streams. Chain streams can be several, but can not be altogether.\\n\\nChain streams are:\\n\\nBufferedOutputStream\\nBufferedInputStream\\nDataOutputStream\\nDataInputStream\\nObjectOutputStream\\nObjectInputStream\\n\\nHere are some examples:\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\n\\t\\t// creates a stream for connection FileOutputStream\\n\\t\\tFileOutputStream outputSream1 = new FileOutputStream(file1);\\n\\n\\t\\t// creates a chain stream for boolean data\\n\\t\\tDataOutputStream dataOutputSream1 = new DataOutputStream(outputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tboolean b = i % 2 == 0 ? false : true;\\n\\t\\t\\tdataOutputSream1.writeBoolean(b);\\n\\t\\t}\\n\\t\\tFileInputStream inputSream1 = new FileInputStream(file1);\\n\\t\\tDataInputStream dataInputSream1 = new DataInputStream(inputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tSystem.out.println(dataInputSream1.readBoolean());\\n\\t\\t}\\n\\t\\tdataOutputSream1.close();\\n\\t\\tdataInputSream1.close();\\n\\t}\\n}\\n\\nOutput from this program is shown here:\\n\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\n",
231 "60",
232 "I/O STREAMS, the object serialization",
233 "To serialize an object means to convert its state to a byte stream so that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements either the java.io.Serializable interface or its subinterface, java.io.Externalizable. Deserialization is the process of converting the serialized form of an object back into a copy of the object.\\n\\nFor example, the java.awt.Button class implements the Serializable interface, so you can serialize a java.awt.Button object and store that serialized state in a file. Later, you can read back the serialized state and deserialize into a java.awt.Button object.\\n\\nThe Java platform specifies a default way by which serializable objects are serialized. A (Java) class can override this default serialization and define its own way of serializing objects of that class. The Object Serialization Specification describes object serialization in detail.\\n\\nSerializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.The String class and all the wrapper classes implements java.io.Serializable interface by default.Let's see the example given below:\\n\\nimport java.io.Serializable; \\npublic class Student implements Serializable { \\n\\tint id; \\n\\tString name; \\n\\tpublic Student(int id, String name) { \\n\\t\\tthis.id = id; \\n\\t\\tthis.name = name; \\n\\t} \\n} \\n\\nThe ObjectOutputStream class is used to write primitive data types and Java objects to an OutputStream. Only objects that support the java.io.Serializable interface can be written to streams.\\n\\nExample of Java Serialization\\n\\nIn this example, we are going to serialize the object of Student class. The writeObject() method of ObjectOutputStream class provides the functionality to serialize the object. We are saving the state of the object in the file named f.txt.\\n\\nimport java.io.*; \\nclass Persist{ \\n\\tpublic static void main(String args[])throws Exception{ \\n\\t\\tStudent s1 = new Student(10,\"Jon\"); \\n \\n\\t\\tFileOutputStream fout=new FileOutputStream(\"f.txt\"); \\n\\t\\tObjectOutputStream out=new ObjectOutputStream(fout); \\n \\n\\t\\tout.writeObject(s1); \\n\\t\\tout.flush(); \\n\\t\\tSystem.out.println(\"success\"); \\n\\t} \\n} \\n\\nThe output from the program is shown here:\\n \\nsuccess\\n\\nDeserialization is the process of reconstructing the object from the serialized state.It is the reverse operation of serialization.\\n\\nAn ObjectInputStream deserializes objects and primitive data written using an ObjectOutputStream.\\n\\nExample of Java Deserialization\\n\\nimport java.io.*; \\nclass Depersist{ \\n\\tpublic static void main(String args[])throws Exception{ \\n \\n\\t\\tObjectInputStream in=new ObjectInputStream(new FileInputStream(\"f.txt\"));\\n \\t\\tStudent s=(Student)in.readObject(); \\n\\t\\tSystem.out.println(s.id + \" \" + s.name); \\n \\n\\t\\tin.close();\\n \\t} \\n} \\n\\nThe output from the program is shown here: \\n\\n10 Jon\\n\\nIf a class implements serializable then all its sub classes will also be serializable. Let's see the example given below:\\n\\nimport java.io.Serializable; \\nclass Person implements Serializable{ \\n\\tint id; \\n\\tString name; \\n\\tPerson(int id, String name) { \\n\\t\\tthis.id = id; \\n\\t\\tthis.name = name; \\n\\t} \\n} \\n\\nclass Student extends Person{ \\n\\tString course; \\n\\tint fee; \\n\\tpublic Student(int id, String name, String course, int fee) { \\n\\t\\tsuper(id,name); \\n\\t\\tthis.course=course; \\n\\t\\tthis.fee=fee; \\n\\t} \\n} \\n\\nNow you can serialize the Student class object that extends the Person class which is Serializable. Parent class properties are inherited to subclasses so if parent class is Serializable, subclass would also be.\\n",
234 "61",
235 "I/O STREAMS, character streams",
236 "The Character Stream Classes \\n\\nCharacter streams are defined by using two class hierarchies. At the top are two abstract classes, Reader and Writer. These abstract classes handle Unicode character streams. Java has several concrete subclasses of each of these. Some character stream classes are shown below:\\n\\nBufferedReader - input character stream - a chain stream\\nBufferedWriter - output character stream - a chain stream\\nFileReader - Input stream that reads from a file - a connection stream\\nFileWriter - Output stream that writes to a file - a connection stream\\nReader - Abstract class that describes stream input\\nWriter - Abstract class that describes stream output \\n\\nThe abstract classes Reader and Writer define several key methods that the other stream classes implement. Two of the most important methods are read( ) and write( ), which read and write characters of data, respectively. These methods are overridden by derived stream classes.\\n\\nLet's see the example given below:\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tFile file = new File(\"file.txt\");\\n\\t\\tFileWriter fWriter = new FileWriter(file);\\n\\t\\t// creates the character stream\\n\\n\\t\\tfWriter.write(\"Hello\");\\n\\t\\tfWriter.close();\\n\\n\\t\\tFileReader fReader = new FileReader(file);\\n\\t\\tint g = fReader.read();\\n\\t\\twhile (g != -1) {\\n\\t\\t\\tSystem.out.print((char) g);\\n\\t\\t\\tg = fReader.read();\\n\\t\\t}\\n\\t\\tfReader.close();\\n\\t}\\n}\\n\\nThe output from the program is shown here:\\n\\nHello\\n\\nLet's see next example:\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tFile file = new File(\"file.txt\");\\n\\t\\tFileWriter fWriter = new FileWriter(file);\\n\\n\\t\\tBufferedWriter bufferedWriter = new BufferedWriter(fWriter);\\n\\t\\tbufferedWriter.write(\"Hello\");\\n\\t\\tbufferedWriter.close();\\n \\n\\t\\tFileReader fReader = new FileReader(file);\\n\\t\\tBufferedReader bufferedReader = new BufferedReader(fReader);\\n\\t\\tString s = bufferedReader.readLine();\\n\\n\\t\\twhile (s != null) {\\n\\t\\t\\tSystem.out.print(s);\\n\\t\\t\\ts = bufferedReader.readLine();\\n\\t\\t}\\n\\t\\tbufferedReader.close();\\n\\t}\\n}\\n\\nThe output from the program is shown here:\\n\\nHello\\n",
237 "62",
238 "COLLECTIONS, ArrayList<>",
239 "The ArrayList Class \\n\\nThe ArrayList class extends AbstractList and implements the List interface. ArrayList is a generic class that has this declaration: \\n\\nclass ArrayList<E> \\n\\nHere, E specifies the type of objects that the list will hold. \\n\\nArrayList supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you must know in advance how many elements an array will hold. But, sometimes, you may not know until run time precisely how large an array you need. To handle this situation, the Collections Framework defines ArrayList. In essence, an ArrayList is a variable-length array of object references. That is, an ArrayList can dynamically increase or decrease in size. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array can be shrunk. \\n\\nArrayList has the constructors shown here: \\nArrayList( ) \\nArrayList(Collection<? extends E> c) \\nArrayList(int capacity) \\n\\nThe first constructor builds an empty array list. The second constructor builds an array list that is initialized with the elements of the collection c. The third constructor builds an array list that has the specified initial capacity. The capacity is the size of the underlying array that is used to store the elements. The capacity grows automatically as elements are added to an array list.\\n \\nThe following program shows a simple use of ArrayList. An array list is created for objects of type String, and then several strings are added to it. (Recall that a quoted string is translated into a String object.) The list is then displayed. Some of the elements are removed and the list is displayed again. \\n\\n// Demonstrate ArrayList. \\nimport java.util.*; \\nclass ArrayListDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// Create an array list. \\n\\t\\tArrayList<String> al = new ArrayList<String>(); \\n\\t\\tSystem.out.println(\"Initial size of al: \" + \\n\\t\\tal.size()); \\n\\t\\t// Add elements to the array list. \\n\\t\\tal.add(\"C\"); \\n\\t\\tal.add(\"A\"); \\n\\t\\tal.add(\"E\"); \\n\\t\\tal.add(\"B\"); \\n\\t\\tal.add(\"D\"); \\n\\t\\tal.add(\"F\"); \\n\\t\\tal.add(1, \"A2\"); \\n\\t\\tSystem.out.println(\"Size of al after additions: \" + \\n\\t\\tal.size()); \\n\\t\\t// Display the array list. \\n\\t\\tSystem.out.println(\"Contents of al: \" + al); \\n\\t\\t// Remove elements from the array list. \\n\\t\\tal.remove(\"F\"); \\n\\t\\tal.remove(2); \\n\\t\\tSystem.out.println(\"Size of al after deletions: \" + \\n\\t\\tal.size());\\n\\t\\tSystem.out.println(\"Contents of al: \" + al); \\n\\t} \\n}\\n\\nThe output from this program is shown here: \\nInitial size of al: 0 \\nSize of al after additions: 7 \\nContents of al: [C, A2, A, E, B, D, F] \\nSize of al after deletions: 5 \\nContents of al: [C, A2, E, B, D]\\n \\nNotice that al starts out empty and grows as elements are added to it. When elements are removed, its size is reduced. \\n\\nIn the preceding example, the contents of a collection are displayed using the default conversion provided by toString( ), which was inherited from AbstractCollection. Although it is sufficient for short, sample programs, you seldom use this method to display the contents of a real-world collection. Usually, you provide your own output routines. But, for the next few examples, the default output created by toString( ) is sufficient.\\n \\nAlthough the capacity of an ArrayList object increases automatically as objects are stored in it, you can increase the capacity of an ArrayList object manually by calling ensureCapacity( ). You might want to do this if you know in advance that you will be storing many more items in the collection than it can currently hold. By increasing its capacity once, at the start, you can prevent several reallocations later. Because reallocations are costly in terms of time, preventing unnecessary ones improves performance. The signature for ensureCapacity( ) is shown here:\\n \\nvoid ensureCapacity(int cap) \\n\\nHere, cap is the new capacity. Conversely, if you want to reduce the size of the array that underlies an ArrayList object so that it is precisely as large as the number of items that it is currently holding, call trimToSize( ), shown here: \\n\\nvoid trimToSize( ) \\n\\nObtaining an Array from an ArrayList \\nWhen working with ArrayList, you will sometimes want to obtain an actual array that contains the contents of the list. You can do this by calling toArray( ), which is defined by Collection. Several reasons exist why you might want to convert a collection into an array, such as: \\n• To obtain faster processing times for certain operations \\n• To pass an array to a method that is not overloaded to accept a collection \\n• To integrate collection-based code with legacy code that does not understand collections \\nWhatever the reason, converting an ArrayList to an array is a trivial matter. As explained earlier, there are two versions of toArray( ), which are shown again here for your convenience: \\n\\nObject[ ] toArray( ) \\n<T> T[ ] toArray(T array[ ])\\n\\nThe first returns an array of Object. The second returns an array of elements that have the same type as T. Normally, the second form is more convenient because it returns the proper type of array. The following program demonstrates its use: \\n\\n// Convert an ArrayList into an array. \\nimport java.util.*; \\nclass ArrayListToArray { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// Create an array list. \\n\\t\\tArrayList<Integer> al = new ArrayList<Integer>(); \\n\\t\\t// Add elements to the array list. \\n\\t\\tal.add(1); \\n\\t\\tal.add(2); \\n\\t\\tal.add(3); \\n\\t\\tal.add(4); \\n\\t\\tSystem.out.println(\"Contents of al: \" + al); \\n\\t\\t// Get the array. \\n\\t\\tInteger ia[] = new Integer[al.size()]; \\n\\t\\tia = al.toArray(ia); \\n\\t\\tint sum = 0; \\n\\t\\t// Sum the array. \\n\\t\\tfor(int i : ia) {\\n\\t\\t\\tsum += i; \\n\\t\\t}\\n\\t\\tSystem.out.println(\"Sum is: \" + sum);\\n \\t} \\n}\\n\\nThe output from the program is shown here: \\nContents of al: [1, 2, 3, 4] \\nSum is: 10 \\n\\nThe program begins by creating a collection of integers. Next, toArray( ) is called and it obtains an array of Integers. Then, the contents of that array are summed by use of a for-each style for loop. \\nThere is something else of interest in this program. As you know, collections can store only references to, not values of, primitive types. However, autoboxing makes it possible to pass values of type int to add( ) without having to manually wrap them within an Integer, as the program shows. Autoboxing causes them to be automatically wrapped. In this way, autoboxing significantly improves the ease with which collections can be used to store primitive values. \\n",
240 "63",
241 "COLLECTIONS, HashMap<>",
242 "The HashMap Class \\n\\nA map is an object that stores associations between keys and values, or key/value pairs. Given a key, you can find its value. Both keys and values are objects. The keys must be unique, but the values may be duplicated.\\n\\nIt uses a hash table to store the map. This allows the execution time of get( ) and put( ) to remain constant even for large sets. HashMap is a generic class that has this declaration: \\n\\nclass HashMap<K, V> \\n\\nHere, K specifies the type of keys, and V specifies the type of values. The following constructors are defined: \\n\\nHashMap( ) \\nHashMap(Map<? extends K, ? extends V> m) \\n\\nThe first form constructs a default hash map. The second form initializes the hash map by using the elements of m. HashMap implements Map and extends AbstractMap. It does not add any methods of its own. The methods declared by Map interface are summarized below:\\n\\n1. void clear( ) \\n\\nRemoves all key/value pairs from the invoking map. \\n\\n2. boolean containsKey(Object k) \\n\\nReturns true if the invoking map contains k as a key. Otherwise, returns false. \\n\\n3. boolean containsValue(Object v) \\n\\nReturns true if the map contains v as a value. Otherwise, returns false.\\n \\n4. Set<Map.Entry<K, V>> entrySet( ) \\n\\nReturns a Set that contains the entries in the map. The set contains objects of type Map.Entry. Thus, this method provides a set-view of the invoking map.\\n \\n5. boolean equals(Object obj) \\n\\nReturns true if obj is a Map and contains the same entries. Otherwise, returns false. \\n\\n6. V get(Object k) \\n\\nReturns the value associated with the key k. Returns null if the key is not found. \\n\\n7. int hashCode( ) \\n\\nReturns the hash code for the invoking map.\\n \\n8. boolean isEmpty( ) \\n\\nReturns true if the invoking map is empty. Otherwise, returns false. \\n\\n9. Set<K> keySet( ) \\n\\nReturns a Set that contains the keys in the invoking map. This method provides a set-view of the keys in the invoking map. \\n\\n10. V put(K k, V v) \\n\\nPuts an entry in the invoking map, overwriting any previous value associated with the key. The key and value are k and v, respectively. Returns null if the key did not already exist. Otherwise, the previous value linked to the key is returned. \\n\\n11. void putAll(Map<? extends K, void putAll(Map<? extends V> m) \\n\\nPuts all the entries from m into this map.\\n \\n12. V remove(Object k) \\n\\nRemoves the entry whose key equals k. \\n\\n13. int size( ) \\n\\nReturns the number of key/value pairs in the map. \\n\\n14. Collection<V> values( ) \\n\\nReturns a collection containing the values in the map. This method provides a collection-view of the values in the map. \\n\\nYou should note that a hash map does not guarantee the order of its elements. Therefore, the order in which elements are added to a hash map is not necessarily the order in which they are read by an iterator. The following program illustrates HashMap. It maps names to account balances. Notice how a set-view is obtained and used.\\n\\nimport java.util.*; \\nclass HashMapDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// Create a hash map. \\n\\t\\tHashMap<String, Double> hm = new HashMap<String, Double>(); \\n\\t\\t// Put elements to the map \\n\\t\\thm.put(\"John Doe\", new Double(3434.34)); \\n\\t\\thm.put(\"Tom Smith\", new Double(123.22)); \\n\\t\\thm.put(\"Jane Baker\", new Double(1378.00)); \\n\\t\\thm.put(\"Tod Hall\", new Double(99.22)); \\n\\t\\thm.put(\"Ralph Smith\", new Double(-19.08)); \\n\\t\\t// Get a set of the entries. \\n\\t\\tSet<Map.Entry<String, Double>> set = hm.entrySet(); \\n\\t\\t// Display the set. \\n\\t\\tfor(Map.Entry<String, Double> me : set) { \\n\\t\\t\\tSystem.out.print(me.getKey() + \": \"); \\n\\t\\t\\tSystem.out.println(me.getValue()); \\n\\t\\t}\\n\\t\\tSystem.out.println(); \\n\\t\\t// Deposit 1000 into John Doe's account. \\n\\t\\tdouble balance = hm.get(\"John Doe\"); \\n\\t\\thm.put(\"John Doe\", balance + 1000); \\n\\t\\tSystem.out.println(\"John Doe's new balance: \" + \\n\\t\\thm.get(\"John Doe\")); \\n\\t} \\n}\\n\\nOutput from this program is shown here (the precise order may vary): \\n\\nRalph Smith: -19.08 \\nTom Smith: 123.22 \\nJohn Doe: 3434.34 \\nTod Hall: 99.22 \\nJane Baker: 1378.0 \\nJohn Does new balance: 4434.34 \\n\\nThe program begins by creating a hash map and then adds the mapping of names to balances. Next, the contents of the map are displayed by using a set-view, obtained by calling entrySet( ). The keys and values are displayed by calling the getKey( ) and getValue( ) methods that are defined by Map.Entry. Pay close attention to how the deposit is made into John Does account. The put( ) method automatically replaces any preexisting value that is associated with the specified key with the new value. Thus, after John Does account is updated, the hash map will still contain just one John Doe account.\\n",
243 "64",
244 "COLLECTIONS, TreeSet<>",
245 "The TreeSet Class \\n\\nTreeSet extends AbstractSet and implements the NavigableSet interface. It creates a collection that uses a tree for storage. Objects are stored in sorted, ascending order. Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly. \\n\\nTreeSet is a generic class that has this declaration: \\n\\nclass TreeSet<E> \\n\\nHere, E specifies the type of objects that the set will hold. TreeSet has the following constructors: \\n\\nTreeSet( ) \\nTreeSet(Collection<? extends E> c) \\nTreeSet(Comparator<? super E> comp) \\nTreeSet(SortedSet<E> ss) \\n\\nThe first form constructs an empty tree set that will be sorted in ascending order according to the natural order of its elements. The second form builds a tree set that contains the elements of c. The third form constructs an empty tree set that will be sorted according to the comparator specified by comp. (Comparators are described later in this chapter.) The fourth form builds a tree set that contains the elements of ss. \\n\\nHere is an example that demonstrates a TreeSet: \\n// Demonstrate TreeSet. \\nimport java.util.*; \\nclass TreeSetDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// Create a tree set. \\n\\t\\tTreeSet<String> ts = new TreeSet<String>(); \\n\\t\\t// Add elements to the tree set. \\n\\t\\tts.add(\"C\"); \\n\\t\\tts.add(\"A\"); \\n\\t\\tts.add(\"B\"); \\n\\t\\tts.add(\"E\"); \\n\\t\\tts.add(\"F\"); \\n\\t\\tts.add(\"D\"); \\n\\t\\tSystem.out.println(ts); \\n\\t\\t} \\n}\\n\\nThe output from this program is shown here: \\n\\n[A, B, C, D, E, F] \\n\\nAs explained, because TreeSet stores its elements in a tree, they are automatically arranged in sorted order, as the output confirms.\\n",
246 "65",
247 "COLLECTIONS, ArrayList<Object>",
248 "ArrayList<Object>\\n\\nEarlier in the collections stored only objects of type Object. It was uncomfortable.\\n1. The programmer had to keep track of what type objects are placed in the collection. Now the compiler keeps track of the object type.\\n2. Objects of type Object now do not give back to the desired data type.\\n\\nHowever, today the collection containing type Object used quite often.The most commonly used collections ArrayList.\\n\\nConsider the following example: \\n\\nimport java.util.ArrayList;\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tDouble numer1 = 5.666666666;\\n\\t\\tSystem.out.println(numer1);\\n\\t\\tInteger numer2 = 100;\\n\\t\\tSystem.out.println(numer2);\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tSystem.out.println(car1);\\n\\n\\t\\t// declares ArrayList consisting of the object Object\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\n\\t\\tarray1.add(numer1);// adds object type Double to the array\\n\\t\\tarray1.add(numer2);// adds object type Integer to the array \\n\\t\\tarray1.add(car1);// adds object type Car to the array \\n\\n\\t\\tSystem.out.println(array1.toString());\\n\\n\\t\\tString name = ((Car)array1.get(2)).name;\\n\\t\\tSystem.out.println(name);\\n\\t}\\n}\\n\\npublic class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n\\nThis program generates the following output:\\n\\n5.666666666\\n100\\nCar KIA.\\n[5.666666666, 100, Car KIA.]\\nKIA\\n",
249 "66",
250 "GENERICS, generic classes",
251 "Generics \\n\\nAt its core, the term generics means parameterized types. Parameterized types are important because they enable you to create classes, interfaces, and methods in which the type of data upon which they operate is specified as a parameter. Using generics, it is possible to create a single class, for example, that automatically works with different types of data. A class, interface, or method that operates on a parameterized type is called generic, as in generic class or generic method.\\n \\nIt is important to understand that Java has always given you the ability to create generalized classes, interfaces, and methods by operating through references of type Object. Because Object is the superclass of all other classes, an Object reference can refer to any type object. Thus, in pre-generics code, generalized classes, interfaces, and methods used Object references to operate on various types of objects. The problem was that they could not do so with type safety. Generics add the type safety that was lacking. They also streamline the process, because it is no longer necessary to explicitly employ casts to translate between Object and the type of data that is actually being operated upon.With generics, all casts are automatic and implicit. Thus, generics expand your ability to reuse code and let you do so safely and easily. \\n\\nA Simple Generics Example \\n\\nLets begin with a simple example of a generic class. The following program defines two classes. The first is the generic class Gen, and the second is GenDemo, which uses Gen.\\n \\n// A simple generic class. \\n// Here, T is a type parameter that \\n// will be replaced by a real type \\n// when an object of type Gen is created. \\nclass Gen<T> { \\n\\tT ob; // declare an object of type T \\n\\t// Pass the constructor a reference to \\n\\t// an object of type T. \\n\\tGen(T o) { \\n\\t\\tob = o; \\n\\t}\\n\\t// Return ob. \\n\\tT getob() { \\n\\t\\treturn ob; \\n\\t}\\n\\t// Show type of T. \\n\\tvoid showType() { \\n\\t\\tSystem.out.println(\"Type of T is \" + \\n\\t\\tob.getClass().getName()); \\n\\t} \\n}\\n\\n// Demonstrate the generic class. \\nclass GenDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\t// Create a Gen reference for Integers. \\n\\t\\tGen<Integer> iOb; \\n\\t\\t// Create a Gen<Integer> object and assign its \\n\\t\\t// reference to iOb. Notice the use of autoboxing \\n\\t\\t// to encapsulate the value 88 within an Integer object. \\n\\t\\tiOb = new Gen<Integer>(88); \\n\\t\\t// Show the type of data used by iOb. \\n\\t\\tiOb.showType(); \\n\\t\\t// Get the value in iOb. Notice that \\n\\t\\t// no cast is needed. \\n\\t\\tint v = iOb.getob(); \\n\\t\\tSystem.out.println(\"value: \" + v); \\n\\t\\tSystem.out.println(); \\n\\t\\t// Create a Gen object for Strings. \\n\\t\\tGen<String> strOb = new Gen<String>(\"Generics Test\"); \\n\\t\\t// Show the type of data used by strOb. \\n\\t\\tstrOb.showType(); \\n\\t\\t// Get the value of strOb. Again, notice \\n\\t\\t// that no cast is needed. \\n\\t\\tString str = strOb.getob(); \\n\\t\\tSystem.out.println(\"value: \" + str); \\n\\t} \\n}\\n\\nThe output produced by the program is shown here: \\nType of T is java.lang.Integer \\nvalue: 88 \\nType of T is java.lang.String \\nvalue: Generics Test \\n\\nLets examine this program carefully. First, notice how Gen is declared by the following line: \\n\\nclass Gen<T> { \\n\\nHere, T is the name of a type parameter. This name is used as a placeholder for the actual type that will be passed to Gen when an object is created. Thus, T is used within Gen whenever the type parameter is needed. Notice that T is contained within < >. This syntax can be generalized. Whenever a type parameter is being declared, it is specified within angle brackets. Because Gen uses a type parameter, Gen is a generic class, which is also called a parameterized type.\\n\\nNext, T is used to declare an object called ob, as shown here: \\n\\nT ob; // declare an object of type T\\n \\nAs explained, T is a placeholder for the actual type that will be specified when a Gen object is created. Thus, ob will be an object of the type passed to T. For example, if type String is passed to T, then in that instance, ob will be of type String. Now consider Gens constructor: \\n\\nGen(T o) { \\n\\tob = o; \\n}\\n\\nNotice that its parameter, o, is of type T. This means that the actual type of o is determined by the type passed to T when a Gen object is created. Also, because both the parameter o and the member variable ob are of type T, they will both be of the same actual type when a Gen object is created. \\n\\nThe type parameter T can also be used to specify the return type of a method, as is the case with the getob( ) method, shown here: \\n\\nT getob() { \\n\\treturn ob; \\n}\\n\\nBecause ob is also of type T, its type is compatible with the return type specified by getob( ). The showType( ) method displays the type of T by calling getName( ) on the Class object returned by the call to getClass( ) on ob. The getClass( ) method is defined by Object and is thus a member of all class types. It returns a Class object that corresponds to the type of the class of the object on which it is called. Class defines the getName( ) method, which returns a string representation of the class name. \\n\\nThe GenDemo class demonstrates the generic Gen class. It first creates a version of Gen for integers, as shown here: \\n\\nGen<Integer> iOb; \\n\\nLook closely at this declaration. First, notice that the type Integer is specified within the angle brackets after Gen. In this case, Integer is a type argument that is passed to Gens type parameter, T. This effectively creates a version of Gen in which all references to T are translated into references to Integer. Thus, for this declaration, ob is of type Integer, and the return type of getob( ) is of type Integer. \\nBefore moving on, its necessary to state that the Java compiler does not actually create different versions of Gen, or of any other generic class. Although its helpful to think in these terms, it is not what actually happens. Instead, the compiler removes all generic type information, substituting the necessary casts, to make your code behave as if a specific version of Gen were created. Thus, there is really only one version of Gen that actually exists in your program. The process of removing generic type information is called erasure, and we will return to this topic later in this chapter. \\nThe next line assigns to iOb a reference to an instance of an Integer version of the Gen class: \\n\\niOb = new Gen<Integer>(88); \\n\\nNotice that when the Gen constructor is called, the type argument Integer is also specified. This is necessary because the type of the object (in this case iOb) to which the reference is being assigned is of type Gen<Integer>. Thus, the reference returned by new must also be of type Gen<Integer>. If it isnt, a compile-time error will result. For example, the following assignment will cause a compile-time error:\\n \\niOb = new Gen<Double>(88.0); // Error! \\n\\nBecause iOb is of type Gen<Integer>, it cant be used to refer to an object of Gen<Double>. This type checking is one of the main benefits of generics because it ensures type safety. As the comments in the program state, the assignment \\n\\niOb = new Gen<Integer>(88); \\n\\nmakes use of autoboxing to encapsulate the value 88, which is an int, into an Integer. This works because Gen<Integer> creates a constructor that takes an Integer argument. Because an Integer is expected, Java will automatically box 88 inside one. Of course, the assignment could also have been written explicitly, like this: \\n\\niOb = new Gen<Integer>(new Integer(88)); \\n\\nHowever, there would be no benefit to using this version. The program then displays the type of ob within iOb, which is Integer. Next, the program obtains the value of ob by use of the following line: \\n\\nint v = iOb.getob(); \\n\\nBecause the return type of getob( ) is T, which was replaced by Integer when iOb was declared, the return type of getob( ) is also Integer, which unboxes into int when assigned to v (which is an int). Thus, there is no need to cast the return type of getob( ) to Integer. Of course, its not necessary to use the auto-unboxing feature. The preceding line could have been written like this, too:\\n \\nint v = iOb.getob().intValue(); \\n\\nHowever, the auto-unboxing feature makes the code more compact. \\n\\nNext, GenDemo declares an object of type Gen<String>: \\nGen<String> strOb = new Gen<String>(\"Generics Test\"); \\n\\nBecause the type argument is String, String is substituted for T inside Gen. This creates (conceptually) a String version of Gen, as the remaining lines in the program demonstrate. \\n\\nGenerics Work Only with Objects \\n\\nWhen declaring an instance of a generic type, the type argument passed to the type parameter must be a class type. You cannot use a primitive type, such as int or char. For example, with Gen, it is possible to pass any class type to T, but you cannot pass a primitive type to a type parameter. Therefore, the following declaration is illegal: \\n\\nGen<int> strOb = new Gen<int>(53); // Error, can't use primitive type \\n\\nOf course, not being able to specify a primitive type is not a serious restriction because you can use the type wrappers (as the preceding example did) to encapsulate a primitive type. Further, Javas autoboxing and auto-unboxing mechanism makes the use of the type wrapper transparent. \\n\\nGeneric Types Differ Based on Their Type Arguments \\n\\nA key point to understand about generic types is that a reference of one specific version of a generic type is not type compatible with another version of the same generic type. For example, assuming the program just shown, the following line of code is in error and will not compile: \\n\\niOb = strOb; // Wrong! \\n\\nEven though both iOb and strOb are of type Gen<T>, they are references to different types because their type parameters differ. This is part of the way that generics add type safety and prevent errors. \\n\\nHow Generics Improve Type Safety\\n \\nAt this point, you might be asking yourself the following question: Given that the same functionality found in the generic Gen class can be achieved without generics, by simply specifying Object as the data type and employing the proper casts, what is the benefit of making Gen generic? The answer is that generics automatically ensure the type safety of all operations involving Gen. In the process, they eliminate the need for you to enter casts and to type-check code by hand. \\n\\nTo understand the benefits of generics, first consider the following program that creates a non-generic equivalent of Gen: \\n\\n// NonGen is functionally equivalent to Gen \\n// but does not use generics. \\nclass NonGen { \\n\\tObject ob; // ob is now of type Object \\n\\t// Pass the constructor a reference to \\n\\t// an object of type Object\\n \\tNonGen(Object o) { \\n\\t\\tob = o; \\n\\t}\\n\\t// Return type Object. \\n\\tObject getob() { \\n\\t\\treturn ob; \\n\\t}\\n\\t// Show type of ob. \\n\\tvoid showType() { \\n\\t\\tSystem.out.println(\"Type of ob is \" + \\n\\t\\tob.getClass().getName()); \\n\\t} \\n}\\n\\n// Demonstrate the non-generic class. \\nclass NonGenDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tNonGen iOb; \\n\\t\\t// Create NonGen Object and store \\n\\t\\t// an Integer in it. Autoboxing still occurs. \\n\\t\\tiOb = new NonGen(88); \\n\\t\\t// Show the type of data used by iOb. \\n\\t\\tiOb.showType(); \\n\\t\\t// Get the value of iOb. \\n\\t\\t// This time, a cast is necessary. \\n\\t\\tint v = (Integer) iOb.getob(); \\n\\t\\tSystem.out.println(\"value: \" + v); \\n\\t\\tSystem.out.println(); \\n\\t\\t// Create another NonGen object and \\n\\t\\t// store a String in it. \\n\\t\\tNonGen strOb = new NonGen(\"Non-Generics Test\"); \\n\\t\\t// Show the type of data used by strOb. \\n\\t\\tstrOb.showType(); \\n\\t\\t// Get the value of strOb. \\n\\t\\t// Again, notice that a cast is necessary. \\n\\t\\tString str = (String) strOb.getob(); \\n\\t\\tSystem.out.println(\"value: \" + str); \\n\\t\\t// This compiles, but is conceptually wrong! \\n\\t\\tiOb = strOb; \\n\\t\\tv = (Integer) iOb.getob(); // run-time error! \\n\\t} \\n}\\n \\nThere are several things of interest in this version. First, notice that NonGen replaces all uses of T with Object. This makes NonGen able to store any type of object, as can the generic version. However, it also prevents the Java compiler from having any real knowledge about the type of data actually stored in NonGen, which is bad for two reasons. First, explicit casts must be employed to retrieve the stored data. Second, many kinds of type mismatch errors cannot be found until run time. Lets look closely at each problem. \\n\\nNotice this line:\\n \\nint v = (Integer) iOb.getob(); \\n\\nBecause the return type of getob( ) is Object, the cast to Integer is necessary to enable that value to be auto-unboxed and stored in v. If you remove the cast, the program will not compile. With the generic version, this cast was implicit. In the non-generic version, the cast must be explicit. This is not only an inconvenience, but also a potential source of error. Now, consider the following sequence from near the end of the program: \\n\\n// This compiles, but is conceptually wrong! \\niOb = strOb; \\nv = (Integer) iOb.getob(); // run-time error! \\n\\nHere, strOb is assigned to iOb. However, strOb refers to an object that contains a string, not an integer. This assignment is syntactically valid because all NonGen references are the same, and any NonGen reference can refer to any other NonGen object. However, the statement is semantically wrong, as the next line shows. Here, the return type of getob( ) is cast to Integer, and then an attempt is made to assign this value to v. The trouble is that iOb now refers to an object that stores a String, not an Integer. Unfortunately, without the use of generics, the Java compiler has no way to know this. Instead, a run-time exception occurs when the cast to Integer is attempted. As you know, it is extremely bad to have run-time exceptions occur in your code! \\n\\nThe preceding sequence can’t occur when generics are used. If this sequence were attempted in the generic version of the program, the compiler would catch it and report an error, thus preventing a serious bug that results in a run-time exception. The ability to create type-safe code in which type-mismatch errors are caught at compile time is a key advantage of generics. Although using Object references to create “generic†code has always been possible, that code was not type safe, and its misuse could result in run-time exceptions. Generics prevent this from occurring. In essence, through generics, what were once run-time errors have become compile-time errors. This is a major advantage. \\n",
252 "67",
253 "GENERICS, a generic class with two type parameters",
254 "A Generic Class with Two Type Parameters \\n\\nYou can declare more than one type parameter in a generic type. To specify two or more type parameters, simply use a comma-separated list. For example, the following TwoGen class is a variation of the Gen class that has two type parameters: \\n\\n// A simple generic class with two type \\n// parameters: T and V. \\nclass TwoGen<T, V> { \\n\\tT ob1; \\n\\tV ob2; \\n\\t// Pass the constructor a reference to \\n\\t// an object of type T and an object of type V. \\n\\tTwoGen(T o1, V o2) { \\n\\t\\tob1 = o1; \\n\\t\\tob2 = o2; \\n\\t}\\n\\n\\t// Show types of T and V. \\n\\tvoid showTypes() { \\n\\t\\tSystem.out.println(\"Type of T is \" + \\n\\t\\tob1.getClass().getName()); \\n\\t\\tSystem.out.println(\"Type of V is \" + \\n\\t\\tob2.getClass().getName()); \\n\\t}\\n\\n\\tT getob1() { \\n\\t\\treturn ob1; \\n\\t}\\n\\tV getob2() { \\n\\t\\treturn ob2; \\n\\t} \\n}\\n\\n// Demonstrate TwoGen. \\nclass SimpGen { \\n\\tpublic static void main(String args[]) { \\n\\t\\tTwoGen<Integer, String> tgObj = \\n\\t\\tnew TwoGen<Integer, String>(88, \"Generics\"); \\n\\t\\t// Show the types. \\n\\t\\ttgObj.showTypes(); \\n\\t\\t// Obtain and show values. \\n\\t\\tint v = tgObj.getob1(); \\n\\t\\tSystem.out.println(\"value: \" + v); \\n\\t\\tString str = tgObj.getob2(); \\n\\t\\tSystem.out.println(\"value: \" + str); \\n\\t} \\n}\\n\\nThe output from this program is shown here:\\n \\nType of T is java.lang.Integer \\nType of V is java.lang.String \\nvalue: 88 \\nvalue: Generics \\n\\nNotice how TwoGen is declared: \\n\\nclass TwoGen<T, V> { \\n\\nIt specifies two type parameters: T and V, separated by a comma. Because it has two type parameters, two type arguments must be passed to TwoGen when an object is created, as shown next: \\n\\nTwoGen<Integer, String> tgObj = \\nnew TwoGen<Integer, String>(88, \"Generics\");\\n\\nIn this case, Integer is substituted for T, and String is substituted for V. \\n\\nAlthough the two type arguments differ in this example, it is possible for both types to be the same. For example, the following line of code is valid: \\n\\nTwoGen<String, String> x = new TwoGen<String, String>(\"A\", \"B\"); \\n\\nIn this case, both T and V would be of type String. Of course, if the type arguments were always the same, then two type parameters would be unnecessary. \\n",
255 "68",
256 "GENERICS, extends and ?",
257 "Bounded Types\\n \\nIn the preceding examples, the type parameters could be replaced by any class type. This is fine for many purposes, but sometimes it is useful to limit the types that can be passed to a type parameter. For example, assume that you want to create a generic class that contains a method that returns the average of an array of numbers. Furthermore, you want to use the class to obtain the average of an array of any type of number, including integers, floats, and doubles. Thus, you want to specify the type of the numbers generically, using a type parameter. To create such a class, you might try something like this: \\n\\n// Stats attempts (unsuccessfully) to \\n// create a generic class that can compute \\n// the average of an array of numbers of \\n// any given type. \\n// \\n// The class contains an error! \\nclass Stats<T> { \\n\\tT[] nums; // nums is an array of type T \\n\\t// Pass the constructor a reference to \\n\\t// an array of type T. \\n\\tStats(T[] o) { \\n\\t\\tnums = o; \\n\\t}\\n\\t// Return type double in all cases. \\n\\tdouble average() { \\n\\t\\tdouble sum = 0.0;\\n\\t\\tfor(int i=0; i < nums.length; i++) {\\n\\t\\t\\tsum += nums[i].doubleValue(); // Error!!! \\n\\t\\t}\\n\\t\\treturn sum / nums.length; \\n\\t} \\n}\\n\\nIn Stats, the average( ) method attempts to obtain the double version of each number in the nums array by calling doubleValue( ). Because all numeric classes, such as Integer and Double, are subclasses of Number, and Number defines the doubleValue( ) method, this method is available to all numeric wrapper classes. The trouble is that the compiler has no way to know that you are intending to create Stats objects using only numeric types. Thus, when you try to compile Stats, an error is reported that indicates that the doubleValue( ) method is unknown. To solve this problem, you need some way to tell the compiler that you intend to pass only numeric types to T. Furthermore, you need some way to ensure that only numeric types are actually passed. \\n\\nTo handle such situations, Java provides bounded types. When specifying a type parameter, you can create an upper bound that declares the superclass from which all type arguments must be derived. This is accomplished through the use of an extends clause when specifying the type parameter, as shown here: \\n\\n<T extends superclass> \\n\\nThis specifies that T can only be replaced by superclass, or subclasses of superclass. Thus, superclass defines an inclusive, upper limit. \\nYou can use an upper bound to fix the Stats class shown earlier by specifying Number as an upper bound, as shown here: \\n\\n// In this version of Stats, the type argument for \\n// T must be either Number, or a class derived \\n// from Number. \\nclass Stats<T extends Number> { \\n\\tT[] nums; // array of Number or subclass \\n\\t// Pass the constructor a reference to \\n\\t// an array of type Number or subclass. \\n\\tStats(T[] o) { \\n\\t\\tnums = o; \\n\\t}\\n\\t// Return type double in all cases. \\n\\tdouble average() { \\n\\t\\tdouble sum = 0.0; \\n\\t\\tfor(int i=0; i < nums.length; i++) {\\n\\t\\t\\tsum += nums[i].doubleValue();\\n\\t\\t} \\n\\t\\treturn sum / nums.length; \\n\\t} \\n} \\n \\n// Demonstrate Stats. \\nclass BoundsDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tInteger inums[] = { 1, 2, 3, 4, 5 }; \\n\\t\\tStats<Integer> iob = new Stats<Integer>(inums); \\n\\t\\tdouble v = iob.average(); \\n\\t\\tSystem.out.println(\"iob average is \" + v); \\n\\t\\tDouble dnums[] = { 1.1, 2.2, 3.3, 4.4, 5.5 }; \\n\\t\\tStats<Double> dob = new Stats<Double>(dnums); \\n\\t\\tdouble w = dob.average(); \\n\\t\\tSystem.out.println(\"dob average is \" + w); \\n\\t\\t// This won't compile because String is not a \\n\\t\\t// subclass of Number. \\n\\t\\t// String strs[] = { \"1\", \"2\", \"3\", \"4\", \"5\" }; \\n\\t\\t// Stats<String> strob = new Stats<String>(strs); \\n\\t\\t// double x = strob.average(); \\n\\t\\t// System.out.println(\"strob average is \" + v); \\n\\t} \\n}\\n\\nThe output is shown here:\\n Average is 3.0 \\nAverage is 3.3 \\n\\nNotice how Stats is now declared by this line:\\n \\nclass Stats<T extends Number> { \\n\\nBecause the type T is now bounded by Number, the Java compiler knows that all objects of type T can call doubleValue( ) because it is a method declared by Number. This is, by itself, a major advantage. However, as an added bonus, the bounding of T also prevents nonnumeric Stats objects from being created. For example, if you try removing the comments from the lines at the end of the program, and then try recompiling, you will receive compile-time errors because String is not a subclass of Number. \\nIn addition to using a class type as a bound, you can also use an interface type. In fact, you can specify multiple interfaces as bounds. Furthermore, a bound can include both a class type and one or more interfaces. In this case, the class type must be specified first. When a bound includes an interface type, only type arguments that implement that interface are legal. When specifying a bound that has a class and an interface, or multiple interfaces, use the & operator to connect them. For example:\\n\\nclass Gen<T extends MyClass & MyInterface> { // …\\n\\nHere, T is bounded by a class called MyClass and an interface called MyInterface. Thus, any type argument passed to T must be a subclass of MyClass and implement MyInterface.\\n \\nUsing Wildcard Arguments \\n\\nAs useful as type safety is, sometimes it can get in the way of perfectly acceptable constructs. For example, given the Stats class shown at the end of the preceding section, assume that you want to add a method called sameAvg( ) that determines if two Stats objects contain arrays that yield the same average, no matter what type of numeric data each object holds. For example, if one object contains the double values 1.0, 2.0, and 3.0, and the other object contains the integer values 2, 1, and 3, then the averages will be the same. One way to implement sameAvg( ) is to pass it a Stats argument, and then compare the average of that argument against the invoking object, returning true only if the averages are the same. For example, you want to be able to call sameAvg( ), as shown here: \\n\\nInteger inums[] = { 1, 2, 3, 4, 5 }; \\nDouble dnums[] = { 1.1, 2.2, 3.3, 4.4, 5.5 }; \\nStats<Integer> iob = new Stats<Integer>(inums); \\nStats<Double> dob = new Stats<Double>(dnums); \\nif(iob.sameAvg(dob)) {\\n\\tSystem.out.println(\"Averages are the same.\"); \\n}\\nelse {\\n\\tSystem.out.println(\"Averages differ.\"); \\n}\\n\\nAt first, creating sameAvg( ) seems like an easy problem. Because Stats is generic and its average( ) method can work on any type of Stats object, it seems that creating sameAvg( ) would be straightforward. Unfortunately, trouble starts as soon as you try to declare a parameter of type Stats. Because Stats is a parameterized type, what do you specify for Stats type parameter when you declare a parameter of that type? \\n\\nAt first, you might think of a solution like this, in which T is used as the type parameter: \\n\\n// This won't work! \\n// Determine if two averages are the same. \\nboolean sameAvg(Stats<T> ob) { \\n\\tif(average() == ob.average()) \\n\\treturn true; \\n\\treturn false; \\n}\\n\\nThe trouble with this attempt is that it will work only with other Stats objects whose type is the same as the invoking object. For example, if the invoking object is of type Stats<Integer>, then the parameter ob must also be of type Stats<Integer>. It cant be used to compare the average of an object of type Stats<Double> with the average of an object of type Stats<Short>, for example. Therefore, this approach wont work except in a very narrow context and does not yield a general (that is, generic) solution.\\n\\nTo create a generic sameAvg( ) method, you must use another feature of Java generics: the wildcard argument. The wildcard argument is specified by the ?, and it represents an unknown type. Using a wildcard, here is one way to write the sameAvg( ) method: \\n\\n// Determine if two averages are the same. \\n// Notice the use of the wildcard. \\nboolean sameAvg(Stats<?> ob) { \\n\\tif(average() == ob.average()) {\\n\\t\\treturn true; \\n\\t}\\n\\treturn false; \\n}\\n\\nHere, Stats<?> matches any Stats object, allowing any two Stats objects to have their averages compared. The following program demonstrates this:\\n \\n// Use a wildcard. \\nclass Stats<T extends Number> { \\n\\tT[] nums; // array of Number or subclass \\n\\t// Pass the constructor a reference to \\n\\t// an array of type Number or subclass. \\n\\tStats(T[] o) { \\n\\t\\tnums = o; \\n\\t}\\n\\t// Return type double in all cases. \\n\\tdouble average() { \\n\\t\\tdouble sum = 0.0; \\n\\t\\tfor(int i=0; i < nums.length; i++) {\\n\\t\\t\\tsum += nums[i].doubleValue(); \\n\\t\\t}\\n\\t\\treturn sum / nums.length; \\n\\t}\\n\\n\\t// Determine if two averages are the same. \\n\\t// Notice the use of the wildcard. \\n\\tboolean sameAvg(Stats<?> ob) { \\n\\t\\tif(average() == ob.average()) {\\n\\t\\t\\treturn true; \\n\\t\\t}\\n\\t\\treturn false; \\n\\t} \\n}\\n\\n// Demonstrate wildcard. \\nclass WildcardDemo { \\n\\tpublic static void main(String args[]) { \\n\\t\\tInteger inums[] = { 1, 2, 3, 4, 5 }; \\n\\t\\tStats<Integer> iob = new Stats<Integer>(inums); \\n\\t\\tdouble v = iob.average(); \\n\\t\\tSystem.out.println(\"iob average is \" + v);\\n\\t\\tDouble dnums[] = { 1.1, 2.2, 3.3, 4.4, 5.5 }; \\n\\t\\tStats<Double> dob = new Stats<Double>(dnums); \\n\\t\\tdouble w = dob.average(); \\n\\t\\tSystem.out.println(\"dob average is \" + w); \\n\\t\\tFloat fnums[] = { 1.0F, 2.0F, 3.0F, 4.0F, 5.0F }; \\n\\t\\tStats<Float> fob = new Stats<Float>(fnums); \\n\\t\\tdouble x = fob.average(); \\n\\t\\tSystem.out.println(\"fob average is \" + x); \\n\\t\\t// See which arrays have same average. \\n\\t\\tSystem.out.print(\"Averages of iob and dob \"); \\n\\t\\tif(iob.sameAvg(dob)) {\\n\\t\\t\\tSystem.out.println(\"are the same.\");\\n\\t\\t} \\n\\t\\telse {\\n\\t\\t\\tSystem.out.println(\"differ.\"); \\n\\t\\t}\\n\\t\\tSystem.out.print(\"Averages of iob and fob \"); \\n\\t\\tif(iob.sameAvg(fob)) {\\n\\t\\t\\tSystem.out.println(\"are the same.\"); \\n\\t\\t}\\n\\t\\telse {\\n\\t\\t\\tSystem.out.println(\"differ.\"); \\n\\t\\t}\\n\\t} \\n}\\n\\nThe output is shown here: \\niob average is 3.0 \\ndob average is 3.3 \\nfob average is 3.0 \\nAverages of iob and dob differ. \\nAverages of iob and fob are the same. \\n\\nOne last point: It is important to understand that the wildcard does not affect what type of Stats objects can be created. This is governed by the extends clause in the Stats declaration. The wildcard simply matches any valid Stats object.\\n \\nBounded Wildcards \\n\\nWildcard arguments can be bounded in much the same way that a type parameter can be \\nbounded. A bounded wildcard is especially important when you are creating a generic type \\nthat will operate on a class hierarchy. To understand why, lets work through an example. \\nConsider the following hierarchy of classes that encapsulate coordinates:\\n \\n// Two-dimensional coordinates. \\nclass TwoD { \\n\\tint x, y; \\n\\tTwoD(int a, int b) { \\n\\t\\tx = a; \\n\\t\\ty = b; \\n\\t} \\n}\\n\\n// Three-dimensional coordinates. \\nclass ThreeD extends TwoD { \\n\\tint z; \\n\\tThreeD(int a, int b, int c) { \\n\\t\\tsuper(a, b); \\n\\t\\tz = c; \\n\\t} \\n}\\n\\n// Four-dimensional coordinates. \\nclass FourD extends ThreeD { \\n\\tint t; \\n\\tFourD(int a, int b, int c, int d) { \\n\\t\\tsuper(a, b, c); \\n\\t\\tt = d; \\n\\t} \\n}\\n \\nAt the top of the hierarchy is TwoD, which encapsulates a two-dimensional, XY coordinate. TwoD is inherited by ThreeD, which adds a third dimension, creating an XYZ coordinate. ThreeD is inherited by FourD, which adds a fourth dimension (time), yielding a four-dimensional coordinate. \\n\\nShown next is a generic class called Coords, which stores an array of coordinates: \\n\\n// This class holds an array of coordinate objects. \\nclass Coords<T extends TwoD> { \\n\\tT[] coords; \\n\\tCoords(T[] o) { coords = o; } \\n}\\n\\nNotice that Coords specifies a type parameter bounded by TwoD. This means that any array stored in a Coords object will contain objects of type TwoD or one of its subclasses. Now, assume that you want to write a method that displays the X and Y coordinates for each element in the coords array of a Coords object. Because all types of Coords objects have at least two coordinates (X and Y), this is easy to do using a wildcard, as shown here: \\n\\nstatic void showXY(Coords<?> c) { \\n\\tSystem.out.println(\"X Y Coordinates:\"); \\n\\tfor(int i=0; i < c.coords.length; i++) {\\n\\t\\tSystem.out.println(c.coords[i].x + \" \" + c.coords[i].y); \\n\\t}\\n\\tSystem.out.println(); \\n}\\n\\nBecause Coords is a bounded generic type that specifies TwoD as an upper bound, all objects that can be used to create a Coords object will be arrays of type TwoD, or of classes derived from TwoD. Thus, showXY( ) can display the contents of any Coords object. \\n \\nHowever, what if you want to create a method that displays the X, Y, and Z coordinates of a ThreeD or FourD object? The trouble is that not all Coords objects will have three coordinates, because a Coords<TwoD> object will only have X and Y. Therefore, how do you write a method that displays the X, Y, and Z coordinates for Coords<ThreeD> and Coords<FourD> objects, while preventing that method from being used with Coords<TwoD> objects? The answer is the bounded wildcard argument.\\n \\nA bounded wildcard specifies either an upper bound or a lower bound for the type argument. This enables you to restrict the types of objects upon which a method will operate. The most common bounded wildcard is the upper bound, which is created using an extends clause in much the same way it is used to create a bounded type. \\nUsing a bounded wildcard, it is easy to create a method that displays the X, Y, and Z coordinates of a Coords object, if that object actually has those three coordinates. For example, the following showXYZ( ) method shows the X, Y, and Z coordinates of the elements stored in a Coords object, if those elements are actually of type ThreeD (or are derived from ThreeD): \\n\\nstatic void showXYZ(Coords<? extends ThreeD> c) { \\n\\tSystem.out.println(\"X Y Z Coordinates:\"); \\n\\tfor(int i=0; i < c.coords.length; i++) {\\n\\t\\tSystem.out.println(c.coords[i].x + \" \" + \\n\\t\\tc.coords[i].y + \" \" + c.coords[i].z); \\n\\t}\\n\\tSystem.out.println(); \\n}\\n \\nNotice that an extends clause has been added to the wildcard in the declaration of parameter c. It states that the ? can match any type as long as it is ThreeD, or a class derived from ThreeD. Thus, the extends clause establishes an upper bound that the ? can match. Because of this bound, showXYZ( ) can be called with references to objects of type Coords<ThreeD> or Coords<FourD>, but not with a reference of type Coords<TwoD>. Attempting to call showXZY( ) with a Coords<TwoD> reference results in a compile-time error, thus ensuring type safety. \\n\\nHere is an entire program that demonstrates the actions of a bounded wildcard argument:\\n \\n// Bounded Wildcard arguments. \\n// Two-dimensional coordinates. \\nclass TwoD { \\n\\tint x, y; \\n\\tTwoD(int a, int b) { \\n\\t\\tx = a; \\n\\t\\ty = b; \\n\\t} \\n}\\n\\n// Three-dimensional coordinates. \\nclass ThreeD extends TwoD { \\n\\tint z; \\n\\tThreeD(int a, int b, int c) { \\n\\t\\tsuper(a, b); \\n\\t\\tz = c; \\n\\t} \\n}\\n\\n// Four-dimensional coordinates. \\nclass FourD extends ThreeD { \\n\\tint t; \\n\\tFourD(int a, int b, int c, int d) { \\n\\t\\tsuper(a, b, c); \\n\\t\\tt = d; \\n\\t} \\n}\\n\\n// This class holds an array of coordinate objects. \\nclass Coords<T extends TwoD> { \\n\\tT[] coords; \\n\\tCoords(T[] o) { coords = o; } \\n}\\n\\n// Demonstrate a bounded wildcard. \\nclass BoundedWildcard { \\n\\tstatic void showXY(Coords<?> c) { \\n\\t\\tSystem.out.println(\"X Y Coordinates:\"); \\n\\t\\tfor(int i=0; i < c.coords.length; i++){ \\n\\t\\t\\tSystem.out.println(c.coords[i].x + \" \" + \\n\\t\\t\\tc.coords[i].y); \\n\\t\\t}\\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tstatic void showXYZ(Coords<? extends ThreeD> c) { \\n\\t\\tSystem.out.println(\"X Y Z Coordinates:\"); \\n\\t\\tfor(int i=0; i < c.coords.length; i++) {\\n\\t\\t\\tSystem.out.println(c.coords[i].x + \" \" + \\n\\t\\t\\tc.coords[i].y + \" \" + c.coords[i].z)\\n\\t\\t}\\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tstatic void showAll(Coords<? extends FourD> c) { \\n\\t\\tSystem.out.println(\"X Y Z T Coordinates:\"); \\n\\t\\tfor(int i=0; i < c.coords.length; i++) {\\n\\t\\t\\tSystem.out.println(c.coords[i].x + \" \" + \\n\\t\\t\\tc.coords[i].y + \" \" + c.coords[i].z + \" \" + \\n\\t\\t\\tc.coords[i].t); \\n\\t\\t}\\n\\t\\tSystem.out.println(); \\n\\t}\\n\\n\\tpublic static void main(String args[]) { \\n\\t\\tTwoD td[] = {\\n\\t\\t\\tnew TwoD(0, 0), \\n\\t\\t\\tnew TwoD(7, 9), \\n\\t\\t\\tnew TwoD(18, 4), \\n\\t\\t\\tnew TwoD(-1, -23) \\n\\t\\t};\\n\\t\\tCoords<TwoD> tdlocs = new Coords<TwoD>(td); \\n\\t\\tSystem.out.println(\"Contents of tdlocs.\"); \\n\\t\\tshowXY(tdlocs); // OK, is a TwoD \\n\\t\\t// showXYZ(tdlocs); // Error, not a ThreeD \\n\\t\\t// showAll(tdlocs); // Error, not a FourD \\n\\t\\t// Now, create some FourD objects. \\n\\t\\tFourD fd[] = { \\n\\t\\t\\tnew FourD(1, 2, 3, 4), \\n\\t\\t\\tnew FourD(6, 8, 14, 8), \\n\\t\\t\\tnew FourD(22, 9, 4, 9), \\n\\t\\t\\tnew FourD(3, -2, -23, 17) \\n\\t\\t}; \\n\\t\\tCoords<FourD> fdlocs = new Coords<FourD>(fd); \\n\\t\\tSystem.out.println(\"Contents of fdlocs.\"); \\n\\t\\t// These are all OK. \\n\\t\\tshowXY(fdlocs); \\n\\t\\tshowXYZ(fdlocs); \\n\\t\\tshowAll(fdlocs); \\n\\t} \\n}\\n\\nThe output from the program is shown here: \\nContents of tdlocs. \\nX Y Coordinates: \\n0 0 \\n7 9 \\n18 4 \\n-1 -23 \\nContents of fdlocs. \\nX Y Coordinates: \\n1 2 \\n6 8 \\n22 9 \\n3 -2 \\nX Y Z Coordinates: \\n1 2 3 \\n6 8 14 \\n22 9 4 \\n3 -2 -23\\nX Y Z T Coordinates: \\n1 2 3 4 \\n6 8 14 8 \\n22 9 4 9 \\n3 -2 -23 17 \\n\\nNotice these commented-out lines: \\n\\n// showXYZ(tdlocs); // Error, not a ThreeD \\n// showAll(tdlocs); // Error, not a FourD \\n\\nBecause tdlocs is a Coords(TwoD) object, it cannot be used to call showXYZ( ) or showAll( ) because bounded wildcard arguments in their declarations prevent it. To prove this to yourself, try removing the comment symbols, and then attempt to compile the program. You will receive compilation errors because of the type mismatches. In general, to establish an upper bound for a wildcard, use the following type of wildcard expression: \\n\\n<? extends superclass> \\n\\nwhere superclass is the name of the class that serves as the upper bound. Remember, this is an inclusive clause because the class forming the upper bound (that is, specified by superclass) is also within bounds. \\nYou can also specify a lower bound for a wildcard by adding a super clause to a wildcard declaration. Here is its general form: \\n\\n<? super subclass> \\n\\nIn this case, only classes that are superclasses of subclass are acceptable arguments. This is an exclusive clause, because it will not match the class specified by subclass. \\n",
258 "69",
259 "GENERICS, generic methods",
260 "Creating a Generic Method \\n\\nAs the preceding examples have shown, methods inside a generic class can make use of a class type parameter and are, therefore, automatically generic relative to the type parameter. However, it is possible to declare a generic method that uses one or more type parameters of its own. Furthermore, it is possible to create a generic method that is enclosed within a non-generic class.\\n \\nLets begin with an example. The following program declares a non-generic class called GenMethDemo and a static generic method within that class called isIn( ). The isIn( ) method determines if an object is a member of an array. It can be used with any type of object and array as long as the array contains objects that are compatible with the type of the object being sought. \\n\\n// Demonstrate a simple generic method. \\nclass GenMethDemo { \\n\\t// Determine if an object is in an array. \\n\\tstatic <T, V extends T> boolean isIn(T x, V[] y) { \\n\\t\\tfor(int i=0; i < y.length; i++) {\\n\\t\\t\\tif(x.equals(y[i])) return true; \\n\\t\\t}\\n\\t\\treturn false; \\n\\t}\\n\\tpublic static void main(String args[]) { \\n\\t\\t// Use isIn() on Integers. \\n\\t\\tInteger nums[] = { 1, 2, 3, 4, 5 }; \\n\\t\\tif(isIn(2, nums)) {\\n\\t\\t\\tSystem.out.println(\"2 is in nums\"); \\n\\t\\t}\\n\\t\\tif(!isIn(7, nums)) {\\n\\t\\t\\tSystem.out.println(\"7 is not in nums\");\\n\\t\\t} \\n\\t\\tSystem.out.println(); \\n\\t\\t// Use isIn() on Strings. \\n\\t\\tString strs[] = { \"one\", \"two\", \"three\", \"four\", \"five\" }; \\n\\t\\tif(isIn(\"two\", strs)){ \\n\\t\\t\\tSystem.out.println(\"two is in strs\"); \\n\\t\\t{\\n\\t\\tif(!isIn(\"seven\", strs)) {\\n\\t\\t\\tSystem.out.println(\"seven is not in strs\");\\n\\t\\t} \\n\\t\\t// Oops! Won't compile! Types must be compatible. \\n\\t\\t// if(isIn(\"two\", nums)) \\n\\t\\t// System.out.println(\"two is in strs\"); \\n\\t} \\n}\\n\\nThe output from the program is shown here:\\n2 is in nums \\n7 is not in nums \\ntwo is in strs \\nseven is not in strs \\n\\nLets examine isIn( ) closely. First, notice how it is declared by this line: \\n\\nstatic <T, V extends T> boolean isIn(T x, V[] y) { \\n\\nThe type parameters are declared before the return type of the method. Second, notice that the type V is upper-bounded by T. Thus, V must either be the same as type T, or a subclass of T. This relationship enforces that isIn( ) can be called only with arguments that are compatible with each other. Also notice that isIn( ) is static, enabling it to be called independently of any object. Understand, though, that generic methods can be either static or non-static. There is no restriction in this regard.\\nNow, notice how isIn( ) is called within main( ) by use of the normal call syntax, without the need to specify type arguments. This is because the types of the arguments are automatically discerned, and the types of T and V are adjusted accordingly. For example, in the first callif(isIn(2, nums)) the type of the first argument is Integer (due to autoboxing), which causes Integer to be substituted for T. The base type of the second argument is also Integer, which makes Integer a substitute for V, too. In the second call, String types are used, and the types of T and V are replaced by String. Now, notice the commented-out code, shown here: \\n\\n// if(isIn(\"two\", nums)) \\n// System.out.println(\"two is in strs\"); \\n\\nIf you remove the comments and then try to compile the program, you will receive an error. The reason is that the type parameter V is bounded by T in the extends clause in Vs declaration. This means that V must be either type T, or a subclass of T. In this case, the first argument is of type String, making T into String, but the second argument is of type Integer, which is not a subclass of String. This causes a compile-time type-mismatch error. This ability to enforce type safety is one of the most important advantages of generic methods. \\nThe syntax used to create isIn( ) can be generalized. Here is the syntax for a generic method: \\n\\n<type-param-list> ret-type meth-name(param-list) { // … \\n\\nIn all cases, type-param-list is a comma-separated list of type parameters. Notice that for a generic method, the type parameter list precedes the return type. \\n",
261 "70",
262 "GENERICS, collections",
263 "Actually more than 90 percent of cases, when you'll deal with Generics, it will Generics in collections.\\n\\nAfter the appearance of Generics all the collections have been completely redesigned. Now all collections take Generics objects and many of the methods that operate on collections, also take Generics parameters.\\n\\nGeneric is that what was missing collections. Before all collections store a reference to the class Object, which meant that any collection can store objects of any type. Thus, it was possible to unintentionally save incompatible types in the same collection. This could lead to errors incompatibility types at runtime.\\nA simple example of collections is shown here: \\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tCar car2 = new Car(\"AUDI\");\\n\\t\\tCar car3 = new Car(\"RENO\");\\n\\t\\tBMW bmw1 = new BMW(\"BMW 5x\", 10000);\\n\\t\\tBMW bmw2 = new BMW(\"BMW 4x\", 9000);\\n\\t\\tBMW bmw3 = new BMW(\"BMW 3x\", 8000);\\n\\t\\tArrayList<Car> carArray = new ArrayList<>();\\n\\t\\tcarArray.add(car2);\\n\\t\\tcarArray.add(car1);\\n\\t\\tcarArray.add(bmw2);\\n\\t\\tcarArray.add(car3);\\n\\t\\tArrayList<BMW> bmwArray = new ArrayList<>();\\n\\t\\tbmwArray.add(bmw3);\\n\\t\\tbmwArray.add(bmw1);\\n\\t\\tbmwArray.add(bmw2);\\n\\n\\t\\tMain.outArray1(carArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray1(bmwArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray2(bmwArray);\\n\\t}\\n\\n\\tstatic public void outArray1(ArrayList<? extends Car> carAr) {\\n\\t\\tfor (Car c : carAr) {\\n\\t\\t\\tSystem.out.println(c.name);\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public void outArray2(ArrayList<BMW> carA) {\\n\\t\\tfor (BMW c : carA) {\\n\\t\\t\\tSystem.out.println(c.name + \" \" + c.cost + \" $\");\\n\\t\\t}\\n\\t}\\n}\\n\\npublic class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n\\npublic class BMW extends Car {\\n\\tint cost;\\n\\n\\tBMW(String name, int cost) {\\n\\t\\tsuper(name);\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n\\nThe output from this program is shown here: \\nAUDI\\nKIA\\nBMW 4x\\nRENO\\n\\nBMW 3x\\nBMW 5x\\nBMW 4x\\n\\nBMW 3x 8000 $\\nBMW 5x 10000 $\\nBMW 4x 9000 $\\n"
264 ]
265 },
266 {
267 "-name": "purple_list",
268 "item": [
269 "public",
270 "enum",
271 "byte",
272 "synchronized",
273 "abstract",
274 "class",
275 "void",
276 "import",
277 "if",
278 "static",
279 "int",
280 "new",
281 "else",
282 "return",
283 "for",
284 "extends",
285 "implements",
286 "interface",
287 "double",
288 "float",
289 "long",
290 "boolean",
291 "true",
292 "false",
293 "protected",
294 "private",
295 "break",
296 "case",
297 "default",
298 "package",
299 "final",
300 "super",
301 "this",
302 "null",
303 "do",
304 "while",
305 "throws",
306 "throw",
307 "short",
308 "char",
309 "default:",
310 "switch",
311 "try",
312 "finally",
313 "catch"
314 ]
315 },
316 {
317 "-name": "question001",
318 "item": [
319 "1",
320 "1",
321 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\n\\t\\tSystem.out.println(\"Hello world\");\\n\\t\\tSystem.out.println(\"5 times\");\\n\\t}\\n}\\n\\n",
322 "The program displays the inscription:\\n\\nHello world\\n5 times\\n\\n",
323 "Hello world\\n5 times",
324 "1",
325 "1",
326 "59"
327 ]
328 },
329 {
330 "-name": "question002",
331 "item": [
332 "2",
333 "1",
334 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\n\\t\\tSystem.out.print(\"Hello \");\\n\\t\\tSystem.out.println(\"world\");\\n\\t\\tSystem.out.print(\"5 \");\\n\\t\\tSystem.out.print(\"times\");\\n\\t}\\n}\\n\\n",
335 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
336 "Hello world\\n5 times",
337 "1",
338 "1",
339 "59"
340 ]
341 },
342 {
343 "-name": "question003",
344 "item": [
345 "3",
346 "1",
347 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\n\\t\\tString a = \"Hello world\";\\n\\t\\tString b = \"5 times\";\\n\\n\\t\\tSystem.out.println(a);\\n\\t\\tSystem.out.print(b);\\n\\t}\\n}\\n\\n",
348 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
349 "Hello world\\n5 times",
350 "1",
351 "1",
352 "59"
353 ]
354 },
355 {
356 "-name": "question004",
357 "item": [
358 "4",
359 "1",
360 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tString a;\\n\\t\\tString b;\\n\\t\\tString c;\\n\\t\\tString d;\\n\\n\\t\\ta = \"Hello \";\\n\\t\\tb = \"world\";\\n\\t\\tc = \"5 \";\\n\\t\\td = \"times\";\\n\\n\\t\\tSystem.out.println(a + b);\\n\\t\\tSystem.out.println(c + d);\\n\\t}\\n}\\n",
361 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
362 "Hello world\\n5 times",
363 "1",
364 "1",
365 "59"
366 ]
367 },
368 {
369 "-name": "question005",
370 "item": [
371 "5",
372 "1",
373 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tString a = \"Hello \";\\n\\t\\tString c = \"5 \";\\n\\n\\t\\tSystem.out.println(a + \"world\");\\n\\t\\tSystem.out.println(c + \"times\");\\n\\t}\\n}\\n",
374 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
375 "Hello world\\n5 times",
376 "1",
377 "1",
378 "58"
379 ]
380 },
381 {
382 "-name": "question006",
383 "item": [
384 "6",
385 "2",
386 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tString a = \"Hello world\";\\n\\t\\tint b = 5;\\n\\n\\t\\tSystem.out.println(a);\\n\\t\\tSystem.out.print(b + \" times\");\\n\\t}\\n}\\n\\n",
387 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
388 "Hello world\\n5 times",
389 "1",
390 "1",
391 "58"
392 ]
393 },
394 {
395 "-name": "question007",
396 "item": [
397 "7",
398 "2",
399 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\n\\t\\tString a = \"Hello\";\\n\\n\\t\\tSystem.out.println(a + \" world\");\\n\\t\\tSystem.out.println(5 + \" times\" );\\n\\t}\\n}\\n\\n",
400 "Display the inscription:\\n\\nHello world\\n5 times\\n",
401 "Hello world\\n5 times",
402 "1",
403 "1",
404 "59"
405 ]
406 },
407 {
408 "-name": "question008",
409 "item": [
410 "8",
411 "2",
412 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint a;\\n\\t\\ta = 5;\\n\\n\\t\\tSystem.out.println(\"Hello world\");\\n\\t\\tSystem.out.println(a + \" times\");\\n\\t}\\n}\\n",
413 "Display the inscription:\\n\\nHello world\\n5 times\\n",
414 "Hello world\\n5 times",
415 "1",
416 "1",
417 "58"
418 ]
419 },
420 {
421 "-name": "question009",
422 "item": [
423 "9",
424 "2",
425 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint a = 2;\\n\\t\\tint b = 3;\\n\\n\\t\\tSystem.out.println(\"Hello world\");\\n\\t\\tSystem.out.println((b + a) + \" times\");\\n\\t}\\n}\\n\\n",
426 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
427 "Hello world\\n5 times",
428 "1",
429 "1",
430 "58"
431 ]
432 },
433 {
434 "-name": "question010",
435 "item": [
436 "10",
437 "2",
438 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint a = 2;\\n\\n\\t\\tSystem.out.println(\"Hello world\");\\n\\t\\tSystem.out.println((3 + a) + \" times\");\\n\\t}\\n}\\n\\n",
439 "Display the inscription:\\n\\nHello world\\n5 times\\n\\n",
440 "Hello world\\n5 times",
441 "1",
442 "1",
443 "58"
444 ]
445 },
446 {
447 "-name": "question011",
448 "item": [
449 "11",
450 "3",
451 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint i = (int) (Math.random() * 10);\\n\\n\\t\\tSystem.out.println(\"Random number:\" + i);\\n\\n\\t}\\n}\\n\\n",
452 "The program generates a random number from 0 to 9.\\n\\nPossible answer:\\n\\nRandom number:5\\n\\n",
453 "Random number:5",
454 "1",
455 "2",
456 "58"
457 ]
458 },
459 {
460 "-name": "question012",
461 "item": [
462 "12",
463 "3",
464 "public class Test {// class Test is declared \\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint i = (int) (Math.random() * 100 + 1);\\n\\n\\t\\tSystem.out.println(\"Loading capacity:\" + i + \" %\");\\n\\n\\t}\\n}\\n\\n",
465 "The program randomly produces loading capacity from 1 to 100 percent.\\n\\nPossible answer:\\n\\nLoading capacity:48%\\n\\n",
466 "Loading capacity:48%",
467 "1",
468 "2",
469 "58"
470 ]
471 },
472 {
473 "-name": "question013",
474 "item": [
475 "13",
476 "3",
477 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint i = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tSystem.out.println(\"Random number:\" + i);\\n\\n\\t}\\n}\\n\\n",
478 "The program generates a random number from 1 to 10.\\n\\nPossible answer:\\n\\nRandom number:5\\n\\n",
479 "Random number:5",
480 "1",
481 "2",
482 "58"
483 ]
484 },
485 {
486 "-name": "question014",
487 "item": [
488 "14",
489 "3",
490 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint i = (int) (Math.random() * 31 + 1);\\n\\n\\t\\tSystem.out.println(\" January,\" + i);\\n\\n\\t}\\n}\\n\\n",
491 "The program generates a random date in January.\\n\\nPossible answer:\\n\\nJanuary,11\\n\\n",
492 "January,11",
493 "1",
494 "2",
495 "58"
496 ]
497 },
498 {
499 "-name": "question015",
500 "item": [
501 "15",
502 "3",
503 "public class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program ,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tint i = (int) (Math.random() * 101);\\n\\n\\t\\tSystem.out.println(\"Loading capacity:\" + i + \"%\");\\n\\n\\t}\\n}\\n\\n",
504 "The program randomly produces loading capacity from 0 to 100 percent.\\n\\nPossible answer:\\n\\nLoading capacity:48%\\n\\n",
505 "Loading capacity:48%",
506 "1",
507 "2",
508 "58"
509 ]
510 },
511 {
512 "-name": "question016",
513 "item": [
514 "16",
515 "4",
516 "import java.util.Scanner; // class Scanner is imported\\n\\npublic class Test { // class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"Your number is \" + a);\\n\\n\\t}\\n}\\n\\n",
517 "The program displays the number entered by the user.\\n\\nPossible answer:\\n\\nYour number is 4\\n\\n",
518 "Type a number:\\n4\\nYour number is 4",
519 "1",
520 "2",
521 "74"
522 ]
523 },
524 {
525 "-name": "question017",
526 "item": [
527 "17",
528 "4",
529 "import java.util.Scanner;// class Scanner is imported\\n\\npublic class Test {// class Test is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint b = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"Sum:\" + (a + b));\\n\\n\\t}\\n}\\n\\n",
530 "The program displays the sum of the numbers entered by the user.\\n\\nPossible answer:\\n\\nSum:18\\n\\n",
531 "Type a number:\\n3\\nType a number:\\n15\\nSum:18",
532 "1",
533 "2",
534 "74"
535 ]
536 },
537 {
538 "-name": "question018",
539 "item": [
540 "18",
541 "4",
542 "import java.util.Scanner;// class Scanner is imported\\n\\npublic class Main {// class Main is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint b = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"Difference:\" + (a - b));\\n\\n\\t}\\n}\\n\\n",
543 "The program displays the difference between the numbers entered by the user.\\n\\nPossible answer:\\n\\nDifference:-2\\n\\n",
544 "Type a number:\\n5\\nType a number:\\n7\\nDifference:-2",
545 "1",
546 "2",
547 "74"
548 ]
549 },
550 {
551 "-name": "question019",
552 "item": [
553 "19",
554 "4",
555 "import java.util.Scanner;// class Scanner is imported\\n\\npublic class Main {// class Main is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = -sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"Opposite number:\" + a);\\n\\n\\t}\\n}\\n\\n",
556 "User inputs a number. The program displays the opposite number.\\n\\nPossible answer:\\n\\nOpposite number:-5\\n\\n",
557 "Type a number:\\n5\\nOpposite number:-5",
558 "1",
559 "2",
560 "74"
561 ]
562 },
563 {
564 "-name": "question020",
565 "item": [
566 "20",
567 "4",
568 "import java.util.Scanner;// class Scanner is imported\\n\\npublic class Main {// class Main is declared\\n\\n\\tpublic static void main(String[] args) {// this is the beginning of the program,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// just remember this\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"The squared number:\" + (a * a));\\n\\n\\t}\\n}\\n\\n",
569 "The program displays the squared number entered by the user.\\n\\nPossible answer:\\n\\nThe squared number:25\\n\\n",
570 "Type a number:\\n5\\nThe squared number:25",
571 "1",
572 "2",
573 "74"
574 ]
575 },
576 {
577 "-name": "question021",
578 "item": [
579 "21",
580 "5",
581 "import java.util.Scanner;\\n\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint b = scan.nextInt();\\n\\t\\tscan.close();\\n\\t\\tint min;\\n\\t\\tif (a < b) {\\n\\t\\t\\tmin = a;\\n\\t\\t\\tSystem.out.println(\"Min=\" + min);\\n\\t\\t}\\n\\t\\tif (a > b) {\\n\\t\\t\\tmin = b;\\n\\t\\t\\tSystem.out.println(\"Min=\" + min);\\n\\t\\t}\\n\\t\\tif (a == b) {\\n\\t\\t\\tSystem.out.println(\"a equals b\");\\n\\t\\t}\\n\\t}\\n}\\n",
582 "Type two numbers a and b. The program determines the smallest of them, or reports that the numbers are equal.\\n\\nPossible answer:\\n\\nMin=5\\n",
583 "Type a number:\\n5\\nType a number:\\n7\\nMin=5",
584 "1",
585 "2",
586 "102"
587 ]
588 },
589 {
590 "-name": "question022",
591 "item": [
592 "22",
593 "5",
594 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint mathematics = (int) (Math.random() * 10);\\n\\t\\tint physics = (int) (Math.random() * 10);\\n\\t\\tint english = (int) (Math.random() * 10);\\n\\n\\t\\tif (mathematics < 5) {\\n\\t\\t\\tSystem.out.println(\"Bad\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Good\");\\n\\t\\t}\\n\\t\\tif (physics < 5) {\\n\\t\\t\\tSystem.out.println(\"Bad\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Good\");\\n\\t\\t}\\n\\t\\tif (english < 5) {\\n\\t\\t\\tSystem.out.println(\"Bad\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Good\");\\n\\t\\t}\\n\\t}\\n}\\n",
595 "A student passed three exams and received three grades on a 10-points scale. The grades for each exam are generated by the program randomly. The program evaluates whether the student's performance was good or bad.\\n\\nPossible answer:\\n\\nBad\\nGood\\nBad\\n",
596 "Bad\\nGood\\nBad\\n",
597 "1",
598 "2",
599 "75"
600 ]
601 },
602 {
603 "-name": "question023",
604 "item": [
605 "23",
606 "5",
607 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint first = (int) (Math.random() * 2);\\n\\t\\tint second = (int) (Math.random() * 2);\\n\\t\\tint third = (int) (Math.random() * 2);\\n\\t\\tint result = 0;\\n\\n\\t\\tif (first == 1) {\\n\\t\\t\\tSystem.out.println(\"Hit the target\");\\n\\t\\t\\tresult = result + 1;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Missed\");\\n\\t\\t\\tresult = result + 0;\\n\\t\\t}\\n\\t\\tif (second == 1) {\\n\\t\\t\\tSystem.out.println(\"Hit the target\");\\n\\t\\t\\tresult = result + 1;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Missed\");\\n\\t\\t\\tresult = result + 0;\\n\\t\\t}\\n\\t\\tif (third == 1) {\\n\\t\\t\\tSystem.out.println(\"Hit the target\");\\n\\t\\t\\tresult = result + 1;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Missed\");\\n\\t\\t\\tresult = result + 0;\\n\\t\\t}\\n\\t\\tSystem.out.println(result);\\n\\t}\\n}\\n",
608 "An athlete shoots at three targets. For each target hit athlete is given one point. The program displays the result of each shoot and the total score of the athlete. The result of each shoot is formed by the program randomly.\\nPossible answer:\\n\\nHit the target\\nMissed\\nHit the target\\n2\\n",
609 "Hit the target\\nMissed\\nHit the target\\n2",
610 "1",
611 "3",
612 "75"
613 ]
614 },
615 {
616 "-name": "question024",
617 "item": [
618 "24",
619 "5",
620 "import java.util.Scanner;\\n\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tscan.close();\\n\\t\\tif (a < 0) {\\n\\t\\t\\tSystem.out.println(a + \" < 0\");\\n\\t\\t}\\n\\t\\tif (a > 0) {\\n\\t\\t\\tSystem.out.println(a + \" > 0\");\\n\\t\\t}\\n\\t\\tif (a == 0) {\\n\\t\\t\\tSystem.out.println(a + \" = 0\");\\n\\t\\t}\\n\\t}\\n}\\n",
621 "Type a number. The program tells the user whether the number was greater, less than or equals to 0.\\n\\nPossible answer:\\n\\n3 > 0\\n",
622 "Type a number:\\n3\\n3 > 0",
623 "1",
624 "2",
625 "75"
626 ]
627 },
628 {
629 "-name": "question025",
630 "item": [
631 "25",
632 "5",
633 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint john = (int) (Math.random() * 3);\\n\\t\\tint peter = (int) (Math.random() * 3);\\n\\n\\t\\tif (john == 0) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tif (john == 1) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tif (john == 2) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t}\\n\\t\\t\\tif (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
634 "Peter and John are playing the game \"Rock-paper-scissors-shoot\". Each makes his choice: stone-0, scissors-1, paper-2. The program determines which of those two won.\\nThe choice of the participants is formed in a random way.\\n\\nPossible answer:\\nThe tie\\n",
635 "The tie",
636 "1",
637 "3",
638 "58"
639 ]
640 },
641 {
642 "-name": "question026",
643 "item": [
644 "26",
645 "6",
646 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint john = (int) (Math.random() * 3);\\n\\t\\tint peter = (int) (Math.random() * 3);\\n\\n\\t\\tif (john == 0) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t} else if (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t} else if (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t}\\n\\t\\t} else if (john == 1) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t} else if (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t} else if (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t}\\n\\t\\t} else if (john == 2) {\\n\\t\\t\\tif (peter == 0) {\\n\\t\\t\\t\\tSystem.out.println(\"John\");\\n\\t\\t\\t} else if (peter == 1) {\\n\\t\\t\\t\\tSystem.out.println(\"Peter\");\\n\\t\\t\\t} else if (peter == 2) {\\n\\t\\t\\t\\tSystem.out.println(\"The tie\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n",
647 "Peter and John are playing a game \"Rock-paper-scissors-shoot\". Each of them shows his shoots either stone-0, scissors-1, paper-2.The program determines which of them won. The choice of each participant is formed in a random way.\\n\\nPossible answer:\\n\\nThe tie\\n\\n",
648 "The tie",
649 "1",
650 "3",
651 "58"
652 ]
653 },
654 {
655 "-name": "question027",
656 "item": [
657 "27",
658 "6",
659 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint week = (int) (Math.random() * 7);\\n\\n\\t\\tif (week == 0) {\\n\\t\\t\\tSystem.out.println(\"Monday\");\\n\\t\\t} else if (week == 1) {\\n\\t\\t\\tSystem.out.println(\"Tuesday\");\\n\\t\\t} else if (week == 2) {\\n\\t\\t\\tSystem.out.println(\"Wednesday\");\\n\\t\\t}else if (week == 3) {\\n\\t\\t\\tSystem.out.println(\"Thursday\");\\n\\t\\t}else if (week == 4) {\\n\\t\\t\\tSystem.out.println(\"Friday\");\\n\\t\\t}else if (week == 5) {\\n\\t\\t\\tSystem.out.println(\"Saturday\");\\n\\t\\t}else if (week == 6) {\\n\\t\\t\\tSystem.out.println(\"Sunday\");\\n\\t\\t}\\n\\t}\\n}\\n",
660 "The program shows a day of the week randomly. \\n\\nPossible answer:\\nSaturday",
661 "Saturday",
662 "1",
663 "2",
664 "38"
665 ]
666 },
667 {
668 "-name": "question028",
669 "item": [
670 "28",
671 "6",
672 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint season = (int) (Math.random() * 4);\\n\\n\\t\\tif (season == 0) {\\n\\t\\t\\tSystem.out.println(\"Winter\");\\n\\t\\t} else if (season == 1) {\\n\\t\\t\\tSystem.out.println(\"Spring\");\\n\\t\\t} else if (season == 2) {\\n\\t\\t\\tSystem.out.println(\"Summer\");\\n\\t\\t}else if (season == 3) {\\n\\t\\t\\tSystem.out.println(\"Fall\");\\n\\t\\t}\\n\\t}\\n}\\n",
673 "The program shows a season of the year randomly.\\nPossible answer:\\nWinter",
674 "Winter",
675 "1",
676 "2",
677 "38"
678 ]
679 },
680 {
681 "-name": "question029",
682 "item": [
683 "29",
684 "6",
685 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint exam = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tif (exam < 3) {\\n\\t\\t\\tSystem.out.println(exam + \"-very bad\");\\n\\t\\t} else if (exam < 5) {\\n\\t\\t\\tSystem.out.println(exam + \"-bad\");\\n\\t\\t} else if (exam < 7) {\\n\\t\\t\\tSystem.out.println(exam + \"-satisfactorily\");\\n\\t\\t} else if (exam < 9) {\\n\\t\\t\\tSystem.out.println(exam + \"-good\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(exam + \"-excellent\");\\n\\t\\t}\\n\\t}\\n}\\n",
686 "A student passed the exam. The program displays the results of the exam and gives its own assessment of student's knowledge. Assessment is determined by the program randomly.\\n\\nPossible answer: 10-excellent\\n",
687 "10-excellent",
688 "1",
689 "2",
690 "40"
691 ]
692 },
693 {
694 "-name": "question030",
695 "item": [
696 "30",
697 "6",
698 "import java.util.Scanner;\\n\\npublic class Test {\\npublic static void main(String[] args) {\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tscan.close();\\n\\t\\tif (a < 0) {\\n\\t\\t\\tSystem.out.println(a + \" < 0\");\\n\\t\\t}\\n\\t\\telse if (a > 0) {\\n\\t\\t\\tSystem.out.println(a + \" > 0\");\\n\\t\\t}\\n\\t\\telse if (a == 0) {\\n\\t\\t\\tSystem.out.println(a + \" = 0\");\\n\\t\\t}\\n\\t}\\n}\\n",
699 "Type a number. The program determines if the number is greater than, less than or equals to 0.\\n\\nPossible answer:\\n\\n7 > 0\\n",
700 "Type a number:\\n7\\n7 > 0",
701 "1",
702 "2",
703 "75"
704 ]
705 },
706 {
707 "-name": "question031",
708 "item": [
709 "31",
710 "7",
711 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint week = (int) (Math.random() * 7);\\n\\n\\t\\tswitch (week) {\\n\\t\\tcase 0:\\n\\t\\t\\tSystem.out.println(\"Monday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 1:\\n\\t\\t\\tSystem.out.println(\"Tuesday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.println(\"Wednesday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 3:\\n\\t\\t\\tSystem.out.println(\"Thursday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 4:\\n\\t\\t\\tSystem.out.println(\"Friday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 5:\\n\\t\\t\\tSystem.out.println(\"Saturday\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 6:\\n\\t\\t\\tSystem.out.println(\"Sunday\");\\n\\t\\t\\tbreak;\\n\\t\\t}\\n\\t}\\n}\\n",
712 "The program shows a day of the week randomly.\\n\\nPossible answer: \\nSaturday",
713 "Saturday",
714 "1",
715 "2",
716 "38"
717 ]
718 },
719 {
720 "-name": "question032",
721 "item": [
722 "32",
723 "7",
724 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint season = (int) (Math.random() * 4);\\n\\n\\t\\tswitch (season) {\\n\\t\\tcase 0:\\n\\t\\t\\tSystem.out.println(\"Winter\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 1:\\n\\t\\t\\tSystem.out.println(\"Spring\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.println(\"Summer\");\\n\\t\\t\\tbreak;\\n\\t\\tdefault:\\n\\t\\t\\tSystem.out.println(\"Fall\");\\n\\t\\t}\\n\\t}\\n}\\n",
725 "The program shows a season of the year randomly.\\n\\nPossible answer: \\nFall\\n",
726 "Fall",
727 "1",
728 "2",
729 "38"
730 ]
731 },
732 {
733 "-name": "question033",
734 "item": [
735 "33",
736 "7",
737 "import java.util.Scanner;\\n\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tscan.close();\\n\\t\\tswitch (a) {\\n\\t\\tcase 1:\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.println(\"Grade:\" + a + \"-very bad\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 3:\\n\\t\\tcase 4:\\n\\t\\t\\tSystem.out.println(\"Grade:\" + a + \"-bad\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 5:\\n\\t\\tcase 6:\\n\\t\\t\\tSystem.out.println(\"Grade:\" + a + \"-satisfactorily\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 7:\\n\\t\\tcase 8:\\n\\t\\t\\tSystem.out.println(\"Grade:\" + a + \"-good\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 9:\\n\\t\\tcase 10:\\n\\t\\t\\tSystem.out.println(\"Grade:\" + a + \"-excellent\");\\n\\t\\t\\tbreak;\\n\\t\\tdefault:\\n\\t\\t\\tSystem.out.println(\"Wrong grade\");\\n\\t\\t}\\n\\t}\\n}\\n",
738 "A student passed the exam. Enter student's assessment on 10 points system. The program will give its own assessment of the student's work.\\n\\nPossible answer: \\nGrade:7-good\\n",
739 "Type a number:\\n7\\nGrade:7-good",
740 "1",
741 "3",
742 "75"
743 ]
744 },
745 {
746 "-name": "question034",
747 "item": [
748 "34",
749 "7",
750 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint season = (int) (Math.random() * 4);\\n\\t\\tint month = (int) (Math.random() * 3);\\n\\t\\tswitch (season) {\\n\\t\\tcase 0:\\n\\t\\t\\tSystem.out.print(\"Winter-\");\\n\\t\\t\\tswitch (month) {\\n\\t\\t\\tcase 0:\\n\\t\\t\\t\\tSystem.out.println(\"December\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 1:\\n\\t\\t\\t\\tSystem.out.println(\"January\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2:\\n\\t\\t\\t\\tSystem.out.println(\"February\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t}\\n\\t\\t\\tbreak;\\n\\t\\tcase 1:\\n\\t\\t\\tSystem.out.print(\"Spring-\");\\n\\t\\t\\tswitch (month) {\\n\\t\\t\\tcase 0:\\n\\t\\t\\t\\tSystem.out.println(\"March\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 1:\\n\\t\\t\\t\\tSystem.out.println(\"April\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2:\\n\\t\\t\\t\\tSystem.out.println(\"May\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t}\\n\\t\\t\\tbreak;\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.print(\"Summer-\");\\n\\t\\t\\tswitch (month) {\\n\\t\\t\\tcase 0:\\n\\t\\t\\t\\tSystem.out.println(\"June\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 1:\\n\\t\\t\\t\\tSystem.out.println(\"July\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2:\\n\\t\\t\\t\\tSystem.out.println(\"August\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t}\\n\\t\\t\\tbreak;\\n\\t\\tcase 3:\\n\\t\\t\\tSystem.out.print(\"Fall-\");\\n\\t\\t\\tswitch (month) {\\n\\t\\t\\tcase 0:\\n\\t\\t\\t\\tSystem.out.println(\"September\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 1:\\n\\t\\t\\t\\tSystem.out.println(\"October\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2:\\n\\t\\t\\t\\tSystem.out.println(\"November\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n",
751 "The program shows a season of the year and a month randomly.\\n\\nPossible answer:\\n\\nFall-September\\n\\n",
752 "Fall-September",
753 "1",
754 "3",
755 "57"
756 ]
757 },
758 {
759 "-name": "question035",
760 "item": [
761 "35",
762 "7",
763 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tscan.close();\\n\\t\\tswitch (a) {\\n\\t\\tcase 1:\\n\\t\\t\\tSystem.out.println(\"One\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.println(\"Two\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 3:\\n\\t\\t\\tSystem.out.println(\"Three\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 4:\\n\\t\\t\\tSystem.out.println(\"Four\");\\n\\t\\t\\tbreak;\\n\\t\\tcase 5:\\n\\t\\t\\tSystem.out.println(\"Five\");\\n\\t\\t\\tbreak;\\n\\t\\tdefault:\\n\\t\\t\\tSystem.out.println(\"Wrong number\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
764 "The user types a number from 1 to 5. The program converts numbers into words, or reports that the user has entered an invalid number.\\n\\nPossible answer:\\n\\nFive\\n\\n",
765 "Type a number:\\n5\\nFive",
766 "1",
767 "2",
768 "75"
769 ]
770 },
771 {
772 "-name": "question036",
773 "item": [
774 "36",
775 "8",
776 "import java.util.Scanner;\\n\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tscan.close();\\n\\n\\t\\tint k = a < 0 ? -a : a;\\n\\t\\tSystem.out.println(\"The absolute value of \" + a + \" is \" + k);\\n\\t}\\n}\\n\\n",
777 "The program outputs the absolute value of the number entered by the user.\\n\\nPossible answer:\\n\\nThe absolute value of -7 is 7\\n\\n",
778 "Type a number:\\n-7\\nThe absolute valua of -7 is 7",
779 "1",
780 "1",
781 "77"
782 ]
783 },
784 {
785 "-name": "question037",
786 "item": [
787 "37",
788 "8",
789 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner scan = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = scan.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint b = scan.nextInt();\\n\\t\\tscan.close();\\n\\n\\t\\tint k = a < b ? a : b;\\n\\t\\tSystem.out.println(\"Smallest number:\" + k);\\n\\t}\\n}\\n\\n",
790 "The program displays the smallest number of two numbers entered by the user.\\n\\nPossible answer:\\n\\nSmallest number:-4\\n\\n",
791 "Type a number:\\n5\\nType a number:\\n-4\\nSmallest number:-4",
792 "1",
793 "1",
794 "103"
795 ]
796 },
797 {
798 "-name": "question038",
799 "item": [
800 "38",
801 "8",
802 "public class Home {// class Home is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint a = (int) (Math.random() * 2);\\n\\t\\tint b = (int) (Math.random() * 2);\\n\\t\\tint c = (int) (Math.random() * 2);\\n\\n\\t\\tString k = a == 0 ? \"Dad is at home\" : \"Dad is not at home\";\\n\\t\\tString g = b == 0 ? \"Mom is at home\" : \"Mom is not at home\";\\n\\t\\tString j = c == 0 ? \"Son is at home\" : \"Son is not at home\";\\n\\n\\t\\tSystem.out.println(k);\\n\\t\\tSystem.out.println(g);\\n\\t\\tSystem.out.println(j);\\n\\t}\\n}\\n\\n",
803 "The program reports, who is at home now: father, mother or son.The answer is generated randomly.\\n\\nPossible answer:\\n\\nDad is at home\\nMom is at home\\nSon is not at home\\n\\n",
804 "Dad is at home\\nMom is at home\\nSon is not at home",
805 "1",
806 "2",
807 "83"
808 ]
809 },
810 {
811 "-name": "question039",
812 "item": [
813 "39",
814 "8",
815 "public class Week {// class Week is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint week = (int) (Math.random() * 7 + 1);\\n\\t\\tString k = week < 6 ? \"work day.\" : \"day off.\";\\n\\t\\tSystem.out.println(\"Number \"+ week + \".\");\\n\\t\\tSystem.out.println(\"Today is a \" + k);\\n\\t}\\n}\\n\\n",
816 "The program displays the number of the day of the week randomly and gives a message.\\n\\nPossible answer:\\n\\nNumber 2. \\nToday is a work day.\\n\\n",
817 "Number 2. \\nToday is a work day.",
818 "1",
819 "2",
820 "47"
821 ]
822 },
823 {
824 "-name": "question040",
825 "item": [
826 "40",
827 "8",
828 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint first = (int) (Math.random() * 2);\\n\\t\\tint second = (int) (Math.random() * 2);\\n\\t\\tint third = (int) (Math.random() * 2);\\n\\t\\tint result = 0;\\n\\t\\tString results;\\n\\n\\t\\tresult = first == 0 ? result + 0 : result + 1;\\n\\t\\tresults = first == 0 ? \"Missed\" : \"Hit the target\";\\n\\t\\tSystem.out.println(results);\\n\\t\\tresult = second == 0 ? result + 0 : result + 1;\\n\\t\\tresults = second == 0 ? \"Missed\" : \"Hit the target\";\\n\\t\\tSystem.out.println(results);\\n\\t\\tresult = third == 0 ? result + 0 : result + 1;\\n\\t\\tresults = third == 0 ? \"Missed\" : \"Hit the target\";\\n\\t\\tSystem.out.println(results);\\n\\n\\t\\tSystem.out.println(result);\\n\\t}\\n}\\n\\n",
829 "An athlete shoots in three targets. For each target hit athlete is given one point. The program displays the result of each shoot and the total score of the athlete. The result of each shoot is formed by the program randomly.\\nPossible answer:\\n\\nHit the target\\nMissed\\nHit the target\\n2\\n",
830 "Hit the target\\nMissed\\nHit the target\\n2",
831 "1",
832 "2",
833 "92"
834 ]
835 },
836 {
837 "-name": "question041",
838 "item": [
839 "41",
840 "9",
841 "public class Year { // class Year is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint month = (int) ((Math.random() * 12 + 1));\\n\\n\\t\\tString s;\\n\\t\\tif (month == 1 || month == 2 || month == 12) {\\n\\t\\t\\ts = \"Winter\";\\n\\t\\t}\\n\\t\\tif (month == 3 || month == 4 || month == 5) {\\n\\t\\t\\ts = \"Spring\";\\n\\t\\t}\\n\\t\\tif (month == 6 || month == 7 || month == 8) {\\n\\t\\t\\ts = \"Summer\";\\n\\t\\t}\\n\\t\\telse s = \"Fall\";\\n\\t\\tSystem.out.println(s);\\n\\t}\\n}\\n\\n",
842 "The program displays the season of the year according to the sequence number of the month. A month is chosen randomly.\\n\\nPossible answer:\\n\\nFall\\n\\n",
843 "Fall",
844 "1",
845 "2",
846 "49"
847 ]
848 },
849 {
850 "-name": "question042",
851 "item": [
852 "42",
853 "9",
854 "public class Game { // class Game is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint exam = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tif (exam < 3) {\\n\\t\\t\\tSystem.out.println(exam + \"-very bad\");\\n\\t\\t}\\n\\t\\tif (3 <= exam && exam < 5) {\\n\\t\\t\\tSystem.out.println(exam + \"-bad\");\\n\\t\\t}\\n\\t\\tif (5 <= exam && exam < 7) {\\n\\t\\t\\tSystem.out.println(exam + \"-satisfactorily\");\\n\\t\\t}\\n\\t\\tif (7 <= exam && exam < 9) {\\n\\t\\t\\tSystem.out.println(exam + \"-good\");\\n\\t\\t}\\n\\t\\tif (9 <= exam && exam <= 10) {\\n\\t\\t\\tSystem.out.println(exam + \"-excellent\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
855 "A student passed the exam. The program displays the result of the examination and shows it's own assessment of student's knowledge. The assessment is determined by the program randomly.\\n\\nPossible answer: \\n\\n10-excellent\\n\\n",
856 "10-excellent",
857 "1",
858 "2",
859 "47"
860 ]
861 },
862 {
863 "-name": "question043",
864 "item": [
865 "43",
866 "9",
867 "public class Game { // class Game is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint john = (int) (Math.random() * 3);\\n\\t\\tint peter = (int) (Math.random() * 3);\\n\\n\\t\\tString s;\\n\\t\\tif (john == 0 && peter == 0 || john == 1 && peter == 1 || john == 2\\n\\t\\t\\t\\t&& peter == 2) {\\n\\t\\t\\ts = \"The tie\";\\n\\t\\t} else if (john == 0 && peter == 1 || john == 1 && peter == 2\\n\\t\\t\\t\\t|| john == 2 && peter == 0) {\\n\\t\\t\\ts = \"John\";\\n\\t\\t} else {\\n\\t\\t\\ts = \"Peter\";\\n\\t\\t}\\n\\t\\tSystem.out.println(s);\\n\\t}\\n}\\n\\n",
868 "Peter and John are playing the game \"Rock-paper-scissors-shoot\". Each of them shows his shoots either stone-0, scissors-1, paper-2. The program determines which of them won. The choice of each participant is formed in a random way.\\n\\nPossible answer:\\n\\nThe tie\\n\\n",
869 "The tie",
870 "1",
871 "2",
872 "64"
873 ]
874 },
875 {
876 "-name": "question044",
877 "item": [
878 "44",
879 "9",
880 "public class Task {// class Task is declared\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint a = 3;\\n\\t\\tint b = 4;\\n\\t\\tint c = 5;\\n\\t\\tdouble square = 0;// double-fractional variable type\\n\\n\\t\\tif (a > b && a > c) {\\n\\t\\t\\tsquare = b * c / 2;\\n\\t\\t}\\n\\t\\tif (b > a && b > c) {\\n\\t\\t\\tsquare = a * c / 2;\\n\\t\\t}\\n\\t\\tif (c > a && c > b) {\\n\\t\\t\\tsquare = a * b / 2;\\n\\t\\t}\\n\\t\\tSystem.out.println(\"The area is \" + square);\\n\\t}\\n}\\n\\n",
881 "We have a right triangle with sides 3, 4 and 5 cm. The program determines the hypotenuse and the area of the triangle.\\n\\nAnswer:\\n\\nThe area is 6.0\\n\\n",
882 "The area is 6.0",
883 "1",
884 "2",
885 "65"
886 ]
887 },
888 {
889 "-name": "question045",
890 "item": [
891 "45",
892 "9",
893 "import java.util.Scanner;// import the class Scanner\\n\\npublic class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint b = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tif (a != b) {\\n\\t\\t\\tif (a > b) {\\n\\t\\t\\t\\tSystem.out.println(a + \" is greater than \" + b);\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.println(b + \" is greater than \" + a);\\n\\t\\t\\t}\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"The numbers are equal\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
894 "The program determines the greater of two numbers entered by the user, or displays a message that the numbers are equal.\\n\\nPossible answer:\\n\\n7 is greater than 1\\n\\n",
895 "Type a number:\\n7\\nType a number:\\n1\\n7 is greater than 1",
896 "1",
897 "2",
898 "110"
899 ]
900 },
901 {
902 "-name": "question046",
903 "item": [
904 "46",
905 "10",
906 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint i = 0;\\n\\t\\tint sum = 0;\\n\\t\\tdo {\\n\\t\\t\\tsum = sum + i;\\n\\t\\t\\ti = i + 1;\\n\\t\\t} while (i != 11);\\n\\t\\tSystem.out.println(sum);\\n\\t}\\n}\\n\\n",
907 "The program sums the numbers from 1 to 10.\\n\\nAnswer:\\n\\n55\\n\\n",
908 "55",
909 "1",
910 "1",
911 "20"
912 ]
913 },
914 {
915 "-name": "question047",
916 "item": [
917 "47",
918 "10",
919 "import java.util.Scanner;\\n\\npublic class Game {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tint result = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tdo {\\n\\t\\t\\tSystem.out.println(\"Guess the number:\");\\n\\t\\t\\ta = sc.nextInt();\\n\\t\\t} while (result != a);\\n\\n\\t\\tSystem.out.println(\"Answer:\" + a);\\n\\t\\tsc.close();\\n\\t}\\n}\\n\\n",
920 "The program thinks of a number from 1 to 10. The user tries to guess the number.The user retries until guesses.\\n\\nPossible answer:\\n\\nGuess the number:\\n4\\nGuess the number:\\n7\\nGuess the number:\\n9\\nGuess the number:\\n1\\nGuess the number:\\n2\\nAnswer:2\\n\\n",
921 "Guess the number:\\n4\\nGuess the number:\\n7\\nGuess the number:\\n9\\nGuess the number:\\n1\\nGuess the number:\\n2\\nAnswer:2",
922 "1",
923 "2",
924 "71"
925 ]
926 },
927 {
928 "-name": "question048",
929 "item": [
930 "48",
931 "10",
932 "import java.util.Scanner;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\")\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tint i = 0;\\n\\t\\tdo {\\n\\t\\t\\tSystem.out.println(\"Repetition:\" + i);\\n\\t\\t\\ti = i + 1;\\n\\t\\t} while (i < (a + 1));\\n\\t}\\n}\\n\\n",
933 "The program counts the repetitions of the cycle from 0 to the number entered by the user.\\n\\nPossible answer:\\n\\nRepetition:0\\nRepetition:1\\nRepetition:2\\nRepetition:3\\n\\n",
934 "Type a number:\\n3\\nRepetition:0\\nRepetition:1\\nRepetition:2\\nRepetition:3",
935 "1",
936 "1",
937 "78"
938 ]
939 },
940 {
941 "-name": "question049",
942 "item": [
943 "49",
944 "10",
945 "import java.util.Scanner;\\n\\npublic class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tif (a < 1 || a > 10) {\\n\\t\\t\\tSystem.out.println(\"The wrong number is entered\");\\n\\t\\t} else {\\n\\t\\t\\tint i = 1;\\n\\t\\t\\tdo {\\n\\t\\t\\t\\tSystem.out.println(\"The square \" + i + \" is \" + (i * i));\\n\\t\\t\\t\\ti = i + 1;\\n\\t\\t\\t} while (i < (a + 1));\\n\\t\\t}\\n\\t}\\n}\\n\\n",
946 "The program considers the squares of numbers from 1 to the number entered by the user. The number entered by the user should not go beyond the range of 1 to 10.\\n\\nPossible answer:\\n\\nThe square of 1 is 1\\nThe square of 2 is 4\\nThe square of 3 is 9\\n\\n",
947 "Type a number:\\n3\\nThe square of 1 is 1\\nThe square of 2 is 4\\nThe square of 3 is 9",
948 "1",
949 "2",
950 "116"
951 ]
952 },
953 {
954 "-name": "question050",
955 "item": [
956 "50",
957 "10",
958 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint i = 0;\\n\\t\\tdo {\\n\\t\\t\\ti = i + 1;\\n\\t\\t\\tSystem.out.print(\" \" + i + \" \");\\n\\t\\t} while (i < 10);\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tdo {\\n\\t\\t\\tSystem.out.print(\" \" + i + \" \");\\n\\t\\t\\ti = i - 1;\\n\\t\\t} while (i > 0);\\n\\t}\\n}\\n\\n",
959 "The program displays a line of numbers from 1 to 10, and then the other line, from 10 to 1.\\n\\nAnswer:\\n\\n1 2 3 4 5 6 7 8 9 10\\n10 9 8 7 6 5 4 3 2 1\\n\\n",
960 "1 2 3 4 5 6 7 8 9 10\\n10 9 8 7 6 5 4 3 2 1",
961 "1",
962 "2",
963 "20"
964 ]
965 },
966 {
967 "-name": "question051",
968 "item": [
969 "51",
970 "11",
971 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint sum = 0;\\n\\t\\tfor (int i = 0; i < 11; i++) {\\n\\t\\t\\tsum = sum + i;\\n\\t\\t}\\n\\t\\tSystem.out.println(sum);\\n\\t}\\n}\\n\\n",
972 "The program sums the numbers from 1 to 10.\\n\\nAnswer:\\n\\n55\\n\\n",
973 "55",
974 "1",
975 "2",
976 "1"
977 ]
978 },
979 {
980 "-name": "question052",
981 "item": [
982 "52",
983 "11",
984 "import java.util.Scanner;\\n\\npublic class Game {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tint result = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\tSystem.out.println(\"Guess the number:\");\\n\\t\\t\\ta = sc.nextInt();\\n\\t\\t\\tif (a == result) {\\n\\t\\t\\t\\tSystem.out.println(\"Right\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t} else{\\n\\t\\t\\t\\tif(result < a){\\n\\t\\t\\t\\t\\tSystem.out.println(\"Wrong.The number is < \" + a);\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tSystem.out.println(\"Wrong.The number is > \" + a);\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Answer:\" + result);\\n\\t\\tsc.close();\\n\\t}\\n}\\n\\n",
985 "The program thinks of a number from 1 to 10.The user tries to guess the number three attempts. The program helps the user and gives some messages.\\n\\nPossible answer:\\n\\nGuess the number:\\n5\\nWrong. The number is > 5\\nGuess the number:\\n7\\nWrong. The number is < 7\\nGuess the number:\\n6\\nRight\\nAnswer:6",
986 "Guess the number:\\n5\\nWrong. The number is > 5\\nGuess the number:\\n7\\nWrong. The number is < 7\\nGuess the number:\\n6\\nRight\\nAnswer:6",
987 "1",
988 "3",
989 "71"
990 ]
991 },
992 {
993 "-name": "question053",
994 "item": [
995 "53",
996 "11",
997 "import java.util.Scanner;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tif (a > 999 || a < 1) {\\n\\t\\t\\tSystem.out.print(\"Wrong\");\\n\\t\\t} else {\\n\\t\\t\\tfor (int i = 1; i < a; i++) {\\n\\t\\t\\t\\tSystem.out.print(i + \" \");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n",
998 "The user enters a number from 1 to 999. The program prints all the numbers between 0 and entered number, or throws an error message.\\n\\nPossible answer:\\n\\nType a number:\\n8\\n1 2 3 4 5 6 7\\n\\n",
999 "Type a number:\\n8\\n1 2 3 4 5 6 7",
1000 "1",
1001 "2",
1002 "77"
1003 ]
1004 },
1005 {
1006 "-name": "question054",
1007 "item": [
1008 "54",
1009 "11",
1010 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint i;\\n\\t\\tfor (i = 1; i <= 10; i++) {\\n\\t\\t\\tSystem.out.print(i + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tfor (i = 10; i > 0; i = i - 1) {\\n\\t\\t\\tSystem.out.print(i + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1011 "The program prints a line of numbers from 1 to 10, then the other line, from 10 to 1.\\n\\nAnswer:\\n\\n1 2 3 4 5 6 7 8 9 10\\n10 9 8 7 6 5 4 3 2 1\\n\\n",
1012 "1 2 3 4 5 6 7 8 9 10\\n10 9 8 7 6 5 4 3 2 1",
1013 "1",
1014 "2",
1015 "25"
1016 ]
1017 },
1018 {
1019 "-name": "question055",
1020 "item": [
1021 "55",
1022 "11",
1023 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint i;\\n\\t\\tfor (i = 1; i <= 10; i++) {\\n\\t\\t\\tSystem.out.print((i * i) + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tfor (i = 10; i > 0; i = i - 1) {\\n\\t\\t\\tSystem.out.print((i * i) + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1024 "The program prints squared numbers from 1 to 10, then the other line, squared numbers from 10 to 1.\\n\\nAnswer:\\n\\n1 4 9 16 25 36 49 64 81 100\\n100 81 64 49 36 25 16 9 4 1\\n\\n",
1025 "1 4 9 16 25 36 49 64 81 100\\n100 81 64 49 36 25 16 9 4 1",
1026 "1",
1027 "2",
1028 "19"
1029 ]
1030 },
1031 {
1032 "-name": "question056",
1033 "item": [
1034 "56",
1035 "12",
1036 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// Initialization of arrays when they are declared\\n\\n\\t\\tint[] j = { 1, 2, 3, 4, 5, 6, 7, 8 };\\n\\t\\tint[] g = { 8, 7, 6, 5, 4, 3, 2, 1 };\\n\\n\\t\\tint l = j.length;\\n\\n\\t\\tfor (int i = 0; i < l; i++) {\\n\\t\\t\\tSystem.out.print(j[i] + \" \" + g[i]);\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1037 "The program prints the arrays j and g in pairs.\\n\\nAnswer:\\n\\n1 8\\n2 7\\n3 6\\n4 5\\n5 4\\n6 3\\n7 2\\n8 1\\n\\n",
1038 "8 1\\n2 7\\n3 6\\n4 5\\n5 4\\n6 3\\n7 2\\n8 1",
1039 "1",
1040 "3",
1041 "33"
1042 ]
1043 },
1044 {
1045 "-name": "question057",
1046 "item": [
1047 "57",
1048 "12",
1049 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint j[] = new int[10];\\n\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tj[i] = (int) (Math.random() * 100 + 1);\\n\\t\\t\\tSystem.out.print(j[i]);\\n\\t\\t\\tif (i == 9) {\\n\\t\\t\\t\\tSystem.out.print(\".\");\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.print(\", \");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1050 "The program creates an array and fills it with random numbers from 1 to 100. After that, the program displays the array.\\n\\nPossible answer:\\n\\n69, 36, 1, 42, 18, 88, 75, 32, 49, 80.\\n\\n",
1051 "69, 36, 1, 42, 18, 88, 75, 32, 49, 80.",
1052 "1",
1053 "3",
1054 "20"
1055 ]
1056 },
1057 {
1058 "-name": "question058",
1059 "item": [
1060 "58",
1061 "12",
1062 "import java.util.Scanner;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tif (a < 1 || a > 10) {\\n\\t\\t\\tSystem.out.println(\"Wrong\");\\n\\t\\t} else {\\n\\t\\t\\tint j[] = new int[a];\\n\\n\\t\\t\\tfor (int i = 0; i < a; i++) {\\n\\t\\t\\t\\tj[i] = (int) (Math.random() * 10 + 1);\\n\\t\\t\\t\\tSystem.out.print(j[i]);\\n\\t\\t\\t\\tif (i == (a - 1)) {\\n\\t\\t\\t\\t\\tSystem.out.print(\".\");\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tSystem.out.print(\", \");\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1063 "The user types a number from 1 to 10.The program creates an array whose size equals the number,\\n entered by the user, fills it randomly and displays the array.\\n\\nPossible answer:\\n\\n4, 7, 10, 7.\\n\\n",
1064 "Type a number:\\n4\\n4, 7, 10, 7.",
1065 "1",
1066 "3",
1067 "77"
1068 ]
1069 },
1070 {
1071 "-name": "question059",
1072 "item": [
1073 "59",
1074 "12",
1075 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint j[] = new int[10];\\n\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tj[i] = (int) (Math.random() * 100 + 1);\\n\\t\\t\\tSystem.out.print(j[i] + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tif (i < 5) {\\n\\t\\t\\t\\tj[i] = -j[i];\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.print(j[i] + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1076 "The program creates an array of 10 elements and fills it randomly. The program changes sign first five elements of the array.\\n\\nPossible answer:\\n\\n43 23 89 99 14 2 20 1 69 23\\n-43 -23 -89 -99 -14 2 20 1 69 23\\n\\n",
1077 "43 23 89 99 14 2 20 1 69 23\\n-43 -23 -89 -99 -14 2 20 1 69 23",
1078 "1",
1079 "3",
1080 "20"
1081 ]
1082 },
1083 {
1084 "-name": "question060",
1085 "item": [
1086 "60",
1087 "12",
1088 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint j[] = new int[10];\\n\\t\\tint g[] = new int[10];\\n\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tj[i] = (int) (Math.random() * 100 + 1);\\n\\t\\t\\tSystem.out.print(j[i] + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tg[i] = j[i];\\n\\t\\t\\tSystem.out.print(g[i] + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1089 "The program creates two arrays 'j' and 'g' of 10 elements in each. The program fills first array 'j' randomly and displays this array. Then the program copies the data from the array 'j' to the array 'g' and displays the array 'g'.\\n\\nPossible answer:\\n\\n49 35 33 26 86 11 14 28 33 73\\n49 35 33 26 86 11 14 28 33 73\\n\\n",
1090 "49 35 33 26 86 11 14 28 33 73\\n49 35 33 26 86 11 14 28 33 73",
1091 "1",
1092 "2",
1093 "20"
1094 ]
1095 },
1096 {
1097 "-name": "question061",
1098 "item": [
1099 "61",
1100 "13",
1101 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// Initialization of arrays when they are declared\\n\\n\\t\\tString[] j = { \"Peter\", \"John\", \"Alice\", \"Bella\", \"Bill\" };\\n\\t\\tint[] g = { 8, 7, 6, 5, 4 };\\n\\n\\t\\tint l = j.length;\\n\\t\\tSystem.out.println(\"Assessments of students:\");\\n\\t\\tfor (int i = 0; i < l; i++) {\\n\\t\\t\\tSystem.out.println(j[i] + \" \" + g[i]);\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1102 "The program displays assessments of students.\\n\\nAnswer:\\n\\nAssessments of students:\\nPeter 8\\nJohn 7\\nAlice 6\\nBella 5\\nBill 4\\n",
1103 "Assessments of students:\\nPeter 8\\nJohn 7\\nAlice 6\\nBella 5\\nBill 4",
1104 "1",
1105 "3",
1106 "32"
1107 ]
1108 },
1109 {
1110 "-name": "question062",
1111 "item": [
1112 "62",
1113 "13",
1114 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString[] j = { \"Peter\", \"is at home\", \"Alice\", \"is at school\", \"Bill\", \"is at home\",\\n\\t\\t\\t\\t\"Mike\", \"is at school\" };\\n\\t\\tint l = j.length;\\n\\t\\tString stroka = \"\";\\n\\n\\t\\tfor (int i = 0; i < l; i = i + 2) {\\n\\t\\t\\tstroka = stroka + j[i] + \" \" + j[i + 1] + \". \";\\n\\n\\t\\t}\\n\\t\\tSystem.out.print(stroka);\\n\\t}\\n}\\n\\n",
1115 "The program creates a string from an array.\\n\\nAnswer:\\n\\nPeter is at home.Alice is at school.Bill is at home.Mike is at school.\\n\\n",
1116 "Peter is at home.Alice is at school.Bill is at home.Mike is at school.",
1117 "1",
1118 "3",
1119 "20"
1120 ]
1121 },
1122 {
1123 "-name": "question063",
1124 "item": [
1125 "63",
1126 "13",
1127 "public class Game {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString[] j1 = { \"The world\", \"The science\", \"The trade\", \"The idea\", \"Bill\" };\\n\\t\\tString[] j2 = { \" runs\", \" moves\", \" creeps\", \" climbs\", \" leads\" };\\n\\t\\tString[] j3 = { \" quickly.\", \" cleverly.\", \" zealously.\", \" wisely.\", \" really cool.\" };\\n\\n\\t\\tint i1 = (int) (Math.random() * 5);\\n\\t\\tint i2 = (int) (Math.random() * 5);\\n\\t\\tint i3 = (int) (Math.random() * 5);\\n\\n\\t\\tString stroka = j1[i1] + j2[i2] + j3[i3];\\n\\t\\tSystem.out.println(stroka);\\n\\t}\\n}\\n\\n",
1128 "The program generates random phrases from arrays of strings.\\n\\nPossible answer:\\n\\nThe world moves wisely.\\n\\n",
1129 "The world moves wisely.",
1130 "1",
1131 "2",
1132 "105"
1133 ]
1134 },
1135 {
1136 "-name": "question064",
1137 "item": [
1138 "64",
1139 "13",
1140 "public class Game {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString[] j1 = { \"Alice\", \"Julia\", \"Alex\", \"Bella\", \"Bill\" };\\n\\t\\tString[] j2 = { \" looks\", \" studies\", \" reads\", \" hurts\", \" writes\" };\\n\\t\\tString[] j3 = { \" a lesson.\", \"a test.\", \"a text.\", \"a task.\", \"a homework.\" };\\n\\n\\t\\tint i1 = (int) (Math.random() * 5);\\n\\t\\tint i2 = (int) (Math.random() * 5);\\n\\t\\tint i3 = (int) (Math.random() * 5);\\n\\n\\t\\tString stroka = j1[i1] + j2[i2] + j3[i3];\\n\\t\\tSystem.out.println(stroka);\\n\\n\\t}\\n}\\n\\n",
1141 "The program generates random phrases from arrays of strings.\\n\\nPossible answer:\\n\\nAlice studies a test.\\n\\n",
1142 "Alice studies a test.",
1143 "1",
1144 "2",
1145 "101"
1146 ]
1147 },
1148 {
1149 "-name": "question065",
1150 "item": [
1151 "65",
1152 "13",
1153 "import java.util.Scanner;\\n\\npublic class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString stroka;\\n\\t\\tString mas[] = new String[3];\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\tSystem.out.println(\"Type a word :\");\\n\\t\\t\\tstroka = sc.nextLine();\\n\\t\\t\\tmas[i] = stroka;\\n\\t\\t}\\n\\t\\tsc.close();\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\tSystem.out.print(mas[i] + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1154 "The user enters three words. The program writes them into an array and prints these words.\\n\\nPossible answer:\\n\\nGo home quickly.\\n\\n",
1155 "Type a word:\\nGo\\nType a word:\\nhome\\nType a word:\\nquickly.\\nGo home quickly.",
1156 "1",
1157 "2",
1158 "42"
1159 ]
1160 },
1161 {
1162 "-name": "question066",
1163 "item": [
1164 "66",
1165 "14",
1166 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString[] j = { \"Peter\", \"John\", \"Alice\", \"Bella\", \"Bill\" };\\n\\t\\tint[] g = { 8, 7, 10, 5, 4 };\\n\\n\\t\\tfor (String x : j) {\\n\\t\\t\\tSystem.out.print(x + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tfor (int y : g) {\\n\\t\\t\\tSystem.out.print(y + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1167 "The program displays two arrays.\\n\\nAnswer:\\n\\nPeter John Alice Bella Bill\\n8 7 10 5 4\\n\\n",
1168 "Peter John Alice Bella Bill\\n8 7 10 5 4",
1169 "1",
1170 "3",
1171 "20"
1172 ]
1173 },
1174 {
1175 "-name": "question067",
1176 "item": [
1177 "67",
1178 "14",
1179 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint[] g = { 8, 7, 10, 5, 4, 9, 2 };\\n\\n\\t\\tint num = 0;\\n\\n\\t\\tfor (int y : g) {\\n\\t\\t\\tif (y == 5) {\\n\\t\\t\\t\\tnum = num + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.println(num);\\n\\t}\\n}\\n\\n",
1180 "The program displays quantity of fives in the array.\\n\\nAnswer:\\n\\n1\\n\\n",
1181 "1",
1182 "1",
1183 "1",
1184 "45"
1185 ]
1186 },
1187 {
1188 "-name": "question068",
1189 "item": [
1190 "68",
1191 "14",
1192 "import java.util.Scanner;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint[] g = new int[10];\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tg[i] = (int) (Math.random() * 10 + 1);\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tint num = 0;\\n\\n\\t\\tfor (int y : g) {\\n\\t\\t\\tif (y == a) {\\n\\t\\t\\t\\tnum = num + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.println(a + \" meets \" + num + \" times\");\\n\\t}\\n}\\n\\n",
1193 "The program creates an array consisting of the numbers from 1 to 10. The user enters a number. The program reports how many times the entered number meets in the array.\\n\\nPossible answer:\\n\\nType a number:\\n5\\n5 meets 1 times\\n\\n",
1194 "Type a number:\\n5\\n5 meets 1 times",
1195 "1",
1196 "2",
1197 "144"
1198 ]
1199 },
1200 {
1201 "-name": "question069",
1202 "item": [
1203 "69",
1204 "14",
1205 "public class Home {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString[] j = { \"daddy\", \"mom\", \"son\", \"daughter\" };\\n\\n\\t\\tfor (String x : j) {\\n\\t\\t\\tSystem.out.println(\"Hello, \" + x);\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Hi all\");\\n\\t}\\n}\\n\\n",
1206 "The program greets each family member individually and all together.\\n\\nAnswer:\\n\\nHello, daddy\\nHello, mom\\nHello, son\\nHello, daughter\\nHi all\\n\\n",
1207 "Hello, daddy\\nHello, mom\\nHello, son\\nHello, daughter\\nHi all",
1208 "1",
1209 "1",
1210 "38"
1211 ]
1212 },
1213 {
1214 "-name": "question070",
1215 "item": [
1216 "70",
1217 "14",
1218 "public class Home {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString[] j = { \"daddy\", \"mom\", \"son\", \"daughter\" };\\n\\n\\t\\tfor (String x : j) {\\n\\t\\t\\tSystem.out.println(\"Hello, \" + x);\\n\\t\\t}\\n\\t\\tfor (String s : j) {\\n\\t\\t\\tSystem.out.println(\"Bye, \" + s);\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1219 "The program greets every member of the family, and then says goodbye to each member of the family.\\n\\nAnswer:\\n\\nHello, daddy\\nHello, mom\\nHello, son\\nHello, daughter\\nBye, daddy\\nBye, mom\\nBye, son\\nBye, daughter\\n\\n",
1220 "Hello, daddy\\nHello, mom\\nHello, son\\nHello, daughter\\nBye, daddy\\nBye, mom\\nBye, son\\nBye, daughter",
1221 "1",
1222 "1",
1223 "38"
1224 ]
1225 },
1226 {
1227 "-name": "question071",
1228 "item": [
1229 "71",
1230 "15",
1231 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint multiplication[][] = new int[10][10];\\n\\t\\tfor (int i = 1; i < 10; i++) {\\n\\t\\t\\tfor (int j = 1; j < 10; j++) {\\n\\t\\t\\t\\tmultiplication[i][j] = i * j;\\n\\t\\t\\t\\tSystem.out.print(multiplication[i][j] + \" \");\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1232 "The program puts the multiplication table in a two-dimensional array and displays the multiplication table.\\n\\nAnswer:\\n\\n1 2 3 4 5 6 7 8 9 10\\n2 4 6 8 10 12 14 16 18 20\\n3 6 9 12 15 18 21 24 27 30\\n4 8 12 16 20 24 28 32 36 40\\n5 10 15 20 25 30 35 40 45 50\\n6 12 18 24 30 36 42 48 54 60\\n7 14 21 28 35 42 49 56 63 70\\n8 16 24 32 40 48 56 64 72 80\\n9 18 27 36 45 54 63 72 81 90\\n10 20 30 40 50 60 70 80 90 100\\n\\n",
1233 "1 2 3 4 5 6 7 8 9 10\\n2 4 6 8 10 12 14 16 18 20\\n3 6 9 12 15 18 21 24 27 30\\n4 8 12 16 20 24 28 32 36 40\\n5 10 15 20 25 30 35 40 45 50\\n6 12 18 24 30 36 42 48 54 60\\n7 14 21 28 35 42 49 56 63 70\\n8 16 24 32 40 48 56 64 72 80\\n9 18 27 36 45 54 63 72 81 90\\n10 20 30 40 50 60 70 80 90 100",
1234 "1",
1235 "2",
1236 "20"
1237 ]
1238 },
1239 {
1240 "-name": "question072",
1241 "item": [
1242 "72",
1243 "15",
1244 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint multiplication[][] = new int[10][10];\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tfor (int j = 0; j < 10; j++) {\\n\\t\\t\\t\\tif (i < j) {\\n\\t\\t\\t\\t\\tmultiplication[i][j] = 0;\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tmultiplication[i][j] = 1;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tfor (int j = 0; j < 10; j++) {\\n\\t\\t\\t\\tSystem.out.print(multiplication[i][j] + \" \");\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1245 "The program fills the array, as shown below:\\n1 0 0 0 0 0 0 0 0 0\\n1 1 0 0 0 0 0 0 0 0\\n1 1 1 0 0 0 0 0 0 0\\n1 1 1 1 0 0 0 0 0 0\\n1 1 1 1 1 0 0 0 0 0\\n1 1 1 1 1 1 0 0 0 0\\n1 1 1 1 1 1 1 0 0 0\\n1 1 1 1 1 1 1 1 0 0\\n1 1 1 1 1 1 1 1 1 0\\n1 1 1 1 1 1 1 1 1 1\\n\\nAnswer:\\n\\n1 0 0 0 0 0 0 0 0 0\\n1 1 0 0 0 0 0 0 0 0\\n1 1 1 0 0 0 0 0 0 0\\n1 1 1 1 0 0 0 0 0 0\\n1 1 1 1 1 0 0 0 0 0\\n1 1 1 1 1 1 0 0 0 0\\n1 1 1 1 1 1 1 0 0 0\\n1 1 1 1 1 1 1 1 0 0\\n1 1 1 1 1 1 1 1 1 0\\n1 1 1 1 1 1 1 1 1 1\\n\\n",
1246 "1 0 0 0 0 0 0 0 0 0\\n1 1 0 0 0 0 0 0 0 0\\n1 1 1 0 0 0 0 0 0 0\\n1 1 1 1 0 0 0 0 0 0\\n1 1 1 1 1 0 0 0 0 0\\n1 1 1 1 1 1 0 0 0 0\\n1 1 1 1 1 1 1 0 0 0\\n1 1 1 1 1 1 1 1 0 0\\n1 1 1 1 1 1 1 1 1 0\\n1 1 1 1 1 1 1 1 1 1",
1247 "1",
1248 "2",
1249 "20"
1250 ]
1251 },
1252 {
1253 "-name": "question073",
1254 "item": [
1255 "73",
1256 "15",
1257 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint multiplication[][] = new int[10][10];\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tfor (int j = 0; j < 10; j++) {\\n\\t\\t\\t\\tif (i >= j) {\\n\\t\\t\\t\\t\\tmultiplication[i][j] = 0;\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tmultiplication[i][j] = 1;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tfor (int j = 0; j < 10; j++) {\\n\\t\\t\\t\\tSystem.out.print(multiplication[i][j] + \" \");\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1258 "The program fills the array, as shown below:\\n0 1 1 1 1 1 1 1 1 1\\n0 0 1 1 1 1 1 1 1 1\\n0 0 0 1 1 1 1 1 1 1\\n0 0 0 0 1 1 1 1 1 1\\n0 0 0 0 0 1 1 1 1 1\\n0 0 0 0 0 0 1 1 1 1\\n0 0 0 0 0 0 0 1 1 1\\n0 0 0 0 0 0 0 0 1 1\\n0 0 0 0 0 0 0 0 0 1\\n0 0 0 0 0 0 0 0 0 0\\n\\nAnswer:\\n\\n0 1 1 1 1 1 1 1 1 1\\n0 0 1 1 1 1 1 1 1 1\\n0 0 0 1 1 1 1 1 1 1\\n0 0 0 0 1 1 1 1 1 1\\n0 0 0 0 0 1 1 1 1 1\\n0 0 0 0 0 0 1 1 1 1\\n0 0 0 0 0 0 0 1 1 1\\n0 0 0 0 0 0 0 0 1 1\\n0 0 0 0 0 0 0 0 0 1\\n0 0 0 0 0 0 0 0 0 0\\n\\n",
1259 "0 1 1 1 1 1 1 1 1 1\\n0 0 1 1 1 1 1 1 1 1\\n0 0 0 1 1 1 1 1 1 1\\n0 0 0 0 1 1 1 1 1 1\\n0 0 0 0 0 1 1 1 1 1\\n0 0 0 0 0 0 1 1 1 1\\n0 0 0 0 0 0 0 1 1 1\\n0 0 0 0 0 0 0 0 1 1\\n0 0 0 0 0 0 0 0 0 1\\n0 0 0 0 0 0 0 0 0 0",
1260 "1",
1261 "2",
1262 "20"
1263 ]
1264 },
1265 {
1266 "-name": "question074",
1267 "item": [
1268 "74",
1269 "15",
1270 "public class Game {\\n\\tpublic static void main(String[] args) {\\n\\t\\tString[][] field = new String[5][5];\\n\\t\\tint num = 1;\\n\\t\\tfor (int i = 0; i < 5; i++) {\\n\\t\\t\\tfor (int j = 0; j < 5; j++) {\\n\\t\\t\\t\\tfield[i][j] = \" \" + num;\\n\\t\\t\\t\\tSystem.out.print(field[i][j]);\\n\\t\\t\\t\\tnum++;\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1271 "The program fills the array of the numbers in sequential order and displays it.\\n\\nAnswer:\\n\\n 1 2 3 4 5\\n 6 7 8 9 10\\n 11 12 13 14 15\\n 16 17 18 19 20\\n 21 22 23 24 25\\n\\n",
1272 "1 2 3 4 5\\n 6 7 8 9 10\\n 11 12 13 14 15\\n 16 17 18 19 20\\n 21 22 23 24 25",
1273 "1",
1274 "2",
1275 "18"
1276 ]
1277 },
1278 {
1279 "-name": "question075",
1280 "item": [
1281 "75",
1282 "15",
1283 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// initialization of the two-dimensional array\\n\\n\\t\\tString mas[][] = { { \"Winter\", \"Spring\", \"Summer\", \"Fall\" },\\n\\t\\t\\t\\t{ \"Daddy\", \"Mama\", \"Son\", \"Daughter\" },\\n\\t\\t\\t\\t{ \"Cold\", \"Warm\", \"Hot\", \"Comfy\" } };\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\tfor (int j = 0; j < 4; j++) {\\n\\t\\t\\t\\tSystem.out.print(mas[i][j] + \" \");\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1284 "The program displays a two-dimensional array. The array is initialized when the array is declared.\\n\\nAnswer:\\n\\nWinter Spring Summer Fall\\nDaddy Mama Son Daughter\\nCold Warm Hot Comfy\\n\\n",
1285 "Winter Spring Summer Fall\\nDaddy Mama Son Daughter\\nCold Warm Hot Comfy",
1286 "1",
1287 "2",
1288 "83"
1289 ]
1290 },
1291 {
1292 "-name": "question076",
1293 "item": [
1294 "76",
1295 "16",
1296 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// converting String into int and back\\n\\t\\tString stroki[] = { \"Saturday\", \"5\", \"Sunday\", \"2\" };\\n\\t\\tSystem.out.println(stroki[0] + \" - \" + stroki[1] + \", \" + stroki[2]\\n\\t\\t\\t\\t+ \" - \" + stroki[3]);\\n\\t\\tint j = Integer.parseInt(stroki[1]);\\n\\t\\tj++;\\n\\t\\tstroki[1] = j + \"\";\\n\\t\\tint g = Integer.parseInt(stroki[3]);\\n\\t\\tg = g + 5;\\n\\t\\tstroki[3] = g + \"\";\\n\\t\\tSystem.out.println(stroki[0] + \" - \" + stroki[1] + \", \" + stroki[2]\\n\\t\\t\\t\\t+ \" - \" + stroki[3]);\\n\\t}\\n}\\n\\n",
1297 "The program translates string data type into integer and then again translates into string data type.\\n\\nAnswer:\\n\\nSaturday - 5, Sunday - 2\\nSaturday - 6, Sunday - 7\\n\\n",
1298 "Saturday - 5, Sunday - 2\\nSaturday - 6, Sunday - 7",
1299 "1",
1300 "2",
1301 "96"
1302 ]
1303 },
1304 {
1305 "-name": "question077",
1306 "item": [
1307 "77",
1308 "16",
1309 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// converting String into int and back\\n\\t\\tString stroki[] = { \"Saturday\", \"5\", \"Sunday\", \"2\" };\\n\\t\\tSystem.out.println(stroki[0] + \" - \" + stroki[1] + \", \"\\n\\t\\t\\t\\t+ stroki[2] + \" - \" + stroki[3]);\\n\\t\\tint j = Integer.valueOf(stroki[1]);\\n\\t\\tj++;\\n\\t\\tstroki[1] = Integer.toString(j);\\n\\t\\tint g = Integer.valueOf(stroki[3]);\\n\\t\\tg = g + 5;\\n\\t\\tstroki[3] = Integer.toString(g);\\n\\t\\tSystem.out.println(stroki[0] + \" - \" + stroki[1] + \", \" + stroki[2]\\n\\t\\t\\t\\t+ \" - \" + stroki[3]);\\n\\t}\\n}\\n\\n",
1310 "The program translates string data type into integer and then again translates into string data type.\\n\\nAnswer:\\n\\nSaturday - 5, Sunday - 2\\nSaturday - 6, sunday - 7\\n\\n",
1311 "Saturday - 5, Sunday - 2\\nSaturday - 6, Sunday - 7",
1312 "1",
1313 "2",
1314 "96"
1315 ]
1316 },
1317 {
1318 "-name": "question078",
1319 "item": [
1320 "78",
1321 "16",
1322 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// converting double into int, double into String, double into float\\n\\t\\t// converting int into double, String into double, float into double\\n\\n\\t\\tdouble a = 1.55;\\n\\t\\tdouble b = 1.77;\\n\\t\\tdouble c = 1.88;\\n\\t\\tdouble d = 1.12345678901;\\n\\n\\t\\tSystem.out.println(a + \" \" + b + \" \" + c + \" \" + d);\\n\\n\\t\\tint ai = (int) a;\\n\\t\\tString bs = b + \"\";\\n\\t\\tString cs = Double.toString( c);\\n\\t\\tfloat df = (float) d;\\n\\n\\t\\tSystem.out.println(ai + \" \" + bs + \" \" + cs + \" \" + df);\\n\\n\\t\\ta = (double) ai;\\n\\t\\tb = Double.valueOf(bs);\\n\\t\\tc = Double.valueOf(cs);\\n\\t\\td = (double) df;\\n\\n\\t\\tSystem.out.println(a + \" \" + b + \" \" + c + \" \" + d);\\n\\t}\\n}\\n\\n",
1323 "The program converts double data type into string, integer and float data types, and then converts back.\\n\\nAnswer:\\n\\n1.55 1.77 1.88 1.12345678901\\n1 1.77 1.88 1.1234568\\n1.0 1.77 1.88 1.1234568357467651\\n\\n",
1324 "1.55 1.77 1.88 1.12345678901\\n1 1.77 1.88 1.1234568\\n1.0 1.77 1.88 1.1234568357467651",
1325 "1",
1326 "2",
1327 "125"
1328 ]
1329 },
1330 {
1331 "-name": "question079",
1332 "item": [
1333 "79",
1334 "16",
1335 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// converting boolean into String and back\\n\\n\\t\\tboolean a = true;\\n\\t\\tboolean b = false;\\n\\n\\t\\tSystem.out.println(a + \" \" + b);\\n\\n\\t\\tString as = a + \"\";\\n\\t\\tString bs = Boolean.toString(b);\\n\\n\\t\\tSystem.out.println(as + \" \" + bs);\\n\\n\\t\\ta = Boolean.parseBoolean(as);\\n\\t\\tb = Boolean.valueOf(bs);\\n\\n\\t\\tSystem.out.println(a + \" \" + b);\\n\\t}\\n}\\n\\n",
1336 "The program converts boolean type data into string type data and again converts into boolean type data.\\n\\nAnswer:\\n\\ntrue false\\ntrue false\\ntrue false\\n\\n",
1337 "true false\\ntrue false\\ntrue false",
1338 "1",
1339 "2",
1340 "33"
1341 ]
1342 },
1343 {
1344 "-name": "question080",
1345 "item": [
1346 "80",
1347 "16",
1348 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// converting long into int, long into String and back\\n\\n\\t\\tlong l = 214748364;\\n\\t\\tlong l2 = 3422222;\\n\\t\\tSystem.out.println(l + \" \" + l2);\\n\\n\\t\\tint li = (int) l;\\n\\t\\tString l2s = Long.toString(l2);\\n\\t\\tSystem.out.println(li + \" \" + l2s);\\n\\n\\t\\tl = (long) li;\\n\\t\\tl2 = Long.parseLong(l2s);\\n\\t\\tSystem.out.println(l + \" \" + l2);\\n\\t}\\n}\\n\\n",
1349 "The program converts long data type into integral data type and string data type.\\nThe program displays and converts back into data type long.\\n\\nAnswer:\\n\\n214748364 3422222\\n214748364 3422222\\n214748364 3422222\\n\\n",
1350 "214748364 3422222\\n214748364 3422222\\n214748364 3422222",
1351 "1",
1352 "2",
1353 "35"
1354 ]
1355 },
1356 {
1357 "-name": "question081",
1358 "item": [
1359 "81",
1360 "17",
1361 "import java.util.Scanner;\\n\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, square root\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a, c;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tc = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tdouble b;\\n\\t\\tdouble d;\\n\\t\\tb = Math.sqrt( a );\\n\\t\\td = Math.sqrt( c );\\n\\t\\tSystem.out.println(\"The square root of \" + a + \" is \" + b);\\n\\t\\tSystem.out.println(\"The square root of \" + c + \" is \" + d);\\n\\t}\\n}\\n\\n",
1362 "The program calculates square roots of two numbers entered by the user.\\n\\nPossible answer:\\n\\nThe square root of 4 is 2.0\\nThe square root of 8 is 2.8284271247461903\\n\\n",
1363 "Type a number:\\n4\\nType a number:\\n8\\nThe square root of 4 is 2.0\\nThe square root of 8 is 2.8284271247461903",
1364 "1",
1365 "1",
1366 "132"
1367 ]
1368 },
1369 {
1370 "-name": "question082",
1371 "item": [
1372 "82",
1373 "17",
1374 "import java.util.Scanner;\\npublic class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, cube root\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a, c;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tc = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tdouble b;\\n\\t\\tdouble d;\\n\\t\\tb = Math.cbrt( a);\\n\\t\\td = Math.cbrt( c);\\n\\t\\tSystem.out.println(\"The cube root of \" + a + \" is \" + b);\\n\\t\\tSystem.out.println(\"The cube root of \" + c + \" is \" + d);\\n\\t}\\n}\\n\\n",
1375 "The program calculates cube roots of two numbers entered by the user.\\n\\nPossible answer:\\n\\nThe cube root of 4 is 1.5874010519681996\\nThe cube root of 5 is 1.709975946676697\\n\\n",
1376 "Type a number:\\n4\\nType a number:\\n5\\nThe cube root of 4 is 1.5874010519681996\\nThe cube root of 5 is 1.709975946676697",
1377 "1",
1378 "1",
1379 "132"
1380 ]
1381 },
1382 {
1383 "-name": "question083",
1384 "item": [
1385 "83",
1386 "17",
1387 "public class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, rounding\\n\\t\\tdouble a = 1.4;\\n\\t\\tdouble b = 1.7;\\n\\t\\tdouble c, d, e, f, g, h;\\n\\t\\tc = Math.round(a);\\n\\t\\td = Math.round(b);\\n\\t\\tSystem.out.println(\"Rounding of \" + a + \" is \" + c);\\n\\t\\tSystem.out.println(\"Rounding of \" + b + \" is \" + d);\\n\\t\\te = Math.ceil(a);\\n\\t\\tf = Math.ceil(b);\\n\\t\\tSystem.out.println(\"Rounding up of\" + a + \" is \" + e);\\n\\t\\tSystem.out.println(\"Rounding up of \" + b + \" is \" + f);\\n\\t\\tg = Math.floor(a);\\n\\t\\th = Math.floor(b);\\n\\t\\tSystem.out.println(\"Rounding down of \" + a + \" is \" + g);\\n\\t\\tSystem.out.println(\"Rounding down of \" + b + \" is \" + h);\\n\\t}\\n}\\n\\n",
1388 "The program rounds numbers, rounds numbers up, rounds numbers down.\\n\\nAnswer:\\n\\nRounding of 1.4 is 1.0\\nRounding of 1.7 is 2.0\\nRounding up of 1.4 is 2.0\\nRounding up of 1.7 is 2.0\\nRounding down of 1.4 is 1.0\\nRounding down of 1.7 is 1.0\\n\\n",
1389 "Rounding of 1.4 is 1.0\\nRounding of 1.7 is 2.0\\nRounding up of 1.4 is 2.0\\nRounding up of 1.7 is 2.0\\nRounding down of 1.4 is 1.0\\nRounding down of 1.7 is 1.0",
1390 "1",
1391 "2",
1392 "64"
1393 ]
1394 },
1395 {
1396 "-name": "question084",
1397 "item": [
1398 "84",
1399 "17",
1400 "public class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, trigonometry\\n\\t\\tdouble a = 0.5;\\n\\t\\tdouble b, c, d, e, f, g;\\n\\t\\tb = Math.sin(a);\\n\\t\\tc = Math.cos(a);\\n\\t\\td = Math.tan(a);\\n\\t\\te = Math.asin(a);\\n\\t\\tf = Math.acos(a);\\n\\t\\tg = Math.atan(a);\\n\\t\\tSystem.out.println(\"sin \" + a + \" = \" + b);\\n\\t\\tSystem.out.println(\"cos \" + a + \" = \" + c);\\n\\t\\tSystem.out.println(\"tan \" + a + \" = \" + d);\\n\\t\\tSystem.out.println(\"asin \" + a + \" = \" + e);\\n\\t\\tSystem.out.println(\"acos \" + a + \" = \" + f);\\n\\t\\tSystem.out.println(\"atan \" + a + \" = \" + g);\\n\\t}\\n}\\n\\n",
1401 "The program calculates trigonometric functions of number a, given in radian.\\n\\nAnswer:\\n\\nsin 0.5 = 0.479425538604203\\ncos 0.5 = 0.8775825618903728\\ntan 0.5 = 0.5463024898437905\\nasin 0.5 = 0.5235987755982989\\nacos 0.5 = 1.0471975511965979\\natan 0.5 = 0.4636476090008061\\n\\n",
1402 "sin 0.5 = 0.479425538604203\\ncos 0.5 = 0.8775825618903728\\ntan 0.5 = 0.5463024898437905\\nasin 0.5 = 0.5235987755982989\\nacos 0.5 = 1.0471975511965979\\natan 0.5 = 0.4636476090008061",
1403 "1",
1404 "2",
1405 "54"
1406 ]
1407 },
1408 {
1409 "-name": "question085",
1410 "item": [
1411 "85",
1412 "17",
1413 "public class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, degrees, radian\\n\\t\\tdouble a = 1;\\n\\t\\tdouble b = 180;\\n\\t\\tdouble c, d;\\n\\t\\tc = Math.toDegrees(a);\\n\\t\\td = Math.toRadians(b);\\n\\n\\t\\tSystem.out.println(a + \" radian = \" + c + \" degrees \");\\n\\t\\tSystem.out.println(b + \" degrees = \" + d + \" radian \");\\n\\t}\\n}\\n\\n",
1414 "The program converts radian into degrees and degrees into radian.\\n\\nAnswer:\\n\\n1.0 radian = 57.29577951308232 degrees\\n180.0 degrees = 3.141592653589793 radian\\n\\n",
1415 "1.0 radian = 57.29577951308232 degrees\\n180.0 degrees = 3.141592653589793 radian",
1416 "1",
1417 "1",
1418 "54"
1419 ]
1420 },
1421 {
1422 "-name": "question086",
1423 "item": [
1424 "86",
1425 "18",
1426 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, the min method\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tint c;\\n\\t\\tint min;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tc = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tmin = Math.min(a, c);\\n\\t\\tSystem.out.println(\"Smallest number:\" + min);\\n\\t}\\n}\\n\\n",
1427 "The program determines the smallest of two numbers entered by the user.\\n\\nPossible answer:\\n\\nSmallest number:2\\n\\n",
1428 "Type a number:\\n7\\nType a number:\\n2\\nSmallest number:2",
1429 "1",
1430 "1",
1431 "130"
1432 ]
1433 },
1434 {
1435 "-name": "question087",
1436 "item": [
1437 "87",
1438 "18",
1439 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, the max method\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tint c;\\n\\t\\tint max;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tc = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tmax = Math.max(a, c);\\n\\t\\tSystem.out.println(\"Maximum number: \" + max);\\n\\t}\\n}\\n\\n",
1440 "The program determines the maximum value of two numbers entered by the user.\\n\\nPossible answer:\\n\\nMaximum number:8\\n\\n",
1441 "Type a number:\\n2\\nType a number:\\n8\\nMaximum number:8",
1442 "1",
1443 "1",
1444 "130"
1445 ]
1446 },
1447 {
1448 "-name": "question088",
1449 "item": [
1450 "88",
1451 "18",
1452 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, the method abs\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tint c;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tc = -a;\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"the number is \" + a + \", the opposite number is \" + c);\\n\\t\\tSystem.out.println(\"the absolute value of the number is \" + Math.abs( a)\\n\\t\\t\\t\\t+ \", the absolute value of the opposite number is \" + Math.abs( c));\\n\\t}\\n}\\n\\n",
1453 "The program defines the absolute value of the number entered by the user and the absolute value of the opposite number .\\n\\nPossible answer:\\n\\nthe number is 4, the opposite number is -4\\nthe absolute value of the number is 4, the absolute value of the opposite number is 4\\n\\n",
1454 "Type a number:\\n4\\nthe number is 4, the opposite number is -4\\nthe absolute value of the number is 4, the absolute value of the opposite number is 4",
1455 "1",
1456 "2",
1457 "107"
1458 ]
1459 },
1460 {
1461 "-name": "question089",
1462 "item": [
1463 "89",
1464 "18",
1465 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, PI\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tSystem.out.println(\"The circle length is \" + 2 * Math.PI * Math.abs( a));\\n\\t}\\n}\\n\\n",
1466 "The program considers a circle length. The constant PI is used.\\n\\nPossible answer:\\n\\nThe circle length is 25.132741228718345\\n\\n",
1467 "Type a number:\\n4\\nThe circle length is 25.132741228718345",
1468 "1",
1469 "1",
1470 "92"
1471 ]
1472 },
1473 {
1474 "-name": "question090",
1475 "item": [
1476 "90",
1477 "18",
1478 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// the MATH library, hypot\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tdouble a;\\n\\t\\tdouble b;\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\ta = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tb = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tdouble g = Math.hypot(a, b);\\n\\t\\tSystem.out.println(\"Legs of triangle are \" + a + \" and \" + b + \".\");\\n\\t\\tSystem.out.println(\"The hypotenuse is \" + g + \".\");\\n\\t}\\n}\\n\\n",
1479 "The program defines the hypotenuse of a triangle.\\n\\nPossible answer:\\n\\nLegs of triangle are 4.0 and 3.0. \\nThe hypotenuse is 5.0.\\n\\n",
1480 "Type a number:\\n4\\nType a number:\\n3\\nLegs of triangle are 4.0 and 3.0. \\nThe hypotenuse is 5.0.",
1481 "1",
1482 "1",
1483 "123"
1484 ]
1485 },
1486 {
1487 "-name": "question091",
1488 "item": [
1489 "91",
1490 "19",
1491 "import java.util.Scanner;\\n\\npublic class Task {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, length()\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString address;\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\taddress = sc.nextLine();\\n\\t\\tsc.close();\\n\\n\\t\\tint number = address.length();\\n\\t\\tSystem.out.println(\"The length of the string is\" + number);\\n\\t}\\n}\\n\\n",
1492 "The program displays the size of the string entered by the user.\\n\\nPossible answer:\\n\\nThe length of the string is 8\\n\\n",
1493 "Type a word:\\ncomputer\\nThe length of the string is 8",
1494 "1",
1495 "1",
1496 "96"
1497 ]
1498 },
1499 {
1500 "-name": "question092",
1501 "item": [
1502 "92",
1503 "19",
1504 "import java.util.Scanner;\\n\\npublic class Task {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, charAt()\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString name, surname;\\n\\t\\tSystem.out.println(\"Type a name:\");\\n\\t\\tname = sc.nextLine();\\n\\t\\tSystem.out.println(\"Type a surname:\");\\n\\t\\tsc.close();\\n\\t\\tchar ch = surname.charAt(0);\\n\\t\\tString n = \"\" + ch + \".\";\\n\\t\\tSystem.out.println(n + \" \" + surname);\\n\\t}\\n}\\n\\n",
1505 "The user enters a name and a surname. The program displays the first letter of the name and the surname.\\n\\nPossible answer:\\n\\nJ. Ford\\n\\n",
1506 "Type a name:\\nJulia\\nType a surname:\\nFord\\n\\nJ. Ford",
1507 "1",
1508 "1",
1509 "112"
1510 ]
1511 },
1512 {
1513 "-name": "question093",
1514 "item": [
1515 "93",
1516 "19",
1517 "import java.util.Scanner;\\n\\npublic class Task {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, equals\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString target = \"accumulator\";\\n\\t\\tSystem.out.println(\"There are some errors in the word 'acamulator'. Please correct these errors.\");\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\tString word = sc.nextLine();\\n\\t\\tsc.close();\\n\\n\\t\\tif (word.equals(target)) {\\n\\t\\t\\tSystem.out.println(word + \" correctly\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(word + \" wrong\");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1518 "The program checks the spelling of the word \"accumulator\". The word entered by the user.\\n\\nPossible answer:\\n\\nThere are some errors in the word 'acamulator'. Please correct these errors.\\nType a word:\\naccamulator\\naccamulator - wrong",
1519 "There are some errors in the word 'acamulator'. Please correct these errors.\\nType a word:\\naccamulator\\naccamulator - wrong",
1520 "1",
1521 "1",
1522 "122"
1523 ]
1524 },
1525 {
1526 "-name": "question094",
1527 "item": [
1528 "94",
1529 "19",
1530 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, compareTo\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString a[] = new String[3];\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\ta[0] = sc.nextLine();\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\ta[1] = sc.nextLine();\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\ta[2] = sc.nextLine();\\n\\t\\tsc.close();\\n\\t\\tfor (int j = 0; j < a.length; j++) {\\n\\t\\t\\tfor (int i = j + 1; i < a.length; i++) {\\n\\t\\t\\t\\tif (a[i].compareTo(a[j]) < 0) {\\n\\t\\t\\t\\t\\tString helper = a[j];\\n\\t\\t\\t\\t\\ta[j] = a[i];\\n\\t\\t\\t\\t\\ta[i] = helper;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(a[j]);\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1531 "The user enters three words, the program sorts them in alphabetical order.\\n\\nPossible answer:\\n\\ndaddy\\nmama\\nson\\n\\n",
1532 "Type a word:\\nmama\\nType a word:\\nson\\nType a word:\\ndaddy\\n\\ndaddy\\nmama\\nson",
1533 "1",
1534 "1",
1535 "205"
1536 ]
1537 },
1538 {
1539 "-name": "question095",
1540 "item": [
1541 "95",
1542 "19",
1543 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, valueOf\\n\\t\\tint a = 4;\\n\\t\\tdouble b = 1.45;\\n\\t\\tlong c = 1000000000;\\n\\t\\tchar d = 'f';\\n\\t\\tboolean e = true;\\n\\t\\tString f1 = String.valueOf( a);\\n\\t\\tString f2 = String.valueOf( b);\\n\\t\\tString f3 = String.valueOf( c);\\n\\t\\tString f4 = String.valueOf( d);\\n\\t\\tString f5 = String.valueOf( e);\\n\\n\\t\\tSystem.out.println(f1);\\n\\t\\tSystem.out.println(f2);\\n\\t\\tSystem.out.println(f3);\\n\\t\\tSystem.out.println(f4);\\n\\t\\tSystem.out.println(f5);\\n\\t}\\n}\\n\\n",
1544 "The program converts all types of variables into String variables.\\n\\nAnswer:\\n\\n4\\n1.45\\n1000000000\\nf\\ntrue\\n\\n",
1545 "4\\n1.45\\n1000000000\\nf\\ntrue",
1546 "1",
1547 "1",
1548 "74"
1549 ]
1550 },
1551 {
1552 "-name": "question096",
1553 "item": [
1554 "96",
1555 "20",
1556 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, isEmpty\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString a;\\n\\t\\tSystem.out.println(\"Type a word:\");\\n\\t\\ta = sc.nextLine();\\n\\t\\tsc.close();\\n\\t\\tif (a.isEmpty()) {\\n\\t\\t\\tSystem.out.println(\"It's empty\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(a);\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1557 "The program checks if the user entered any information or not.\\n\\nPossible answer:\\n\\nIt's empty\\n\\n",
1558 "Type a word:\\n\\nIt's empty",
1559 "1",
1560 "1",
1561 "94"
1562 ]
1563 },
1564 {
1565 "-name": "question097",
1566 "item": [
1567 "97",
1568 "20",
1569 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, substring\\n\\t\\tString stroka = \"My daddy is at home, my mom is at home, my son is at home, my daughter is at home\";\\n\\t\\tString dad = stroka.substring(3, 8);\\n\\t\\tString mom = stroka.substring(24, 27);\\n\\t\\tString son = stroka.substring(43, 46);\\n\\t\\tString daughter = stroka.substring(62, 70);\\n\\t\\tSystem.out.println(dad);\\n\\t\\tSystem.out.println(mom);\\n\\t\\tSystem.out.println(son);\\n\\t\\tSystem.out.println(daughter);\\n\\t}\\n}\\n\\n",
1570 "The program converts parts of the main string into separate strings.\\n\\nAnswer:\\n\\ndaddy\\nmom\\nson\\ndaughter\\n\\n",
1571 "daddy\\nmom\\nson\\ndaughter",
1572 "1",
1573 "2",
1574 "62"
1575 ]
1576 },
1577 {
1578 "-name": "question098",
1579 "item": [
1580 "98",
1581 "20",
1582 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class, indexOf\\n\\t\\tString stroka = \"My dad is at home, my mom is at home, my son is at home, my daughter is at home\";\\n\\t\\tint dad = stroka.indexOf(\"dad\");\\n\\t\\tint mom = stroka.indexOf(\"mom\");\\n\\t\\tint son = stroka.indexOf(\"son\");\\n\\t\\tint daughter = stroka.indexOf(\"daughter\");\\n\\t\\tSystem.out.println(dad);\\n\\t\\tSystem.out.println(mom);\\n\\t\\tSystem.out.println(son);\\n\\t\\tSystem.out.println(daughter);\\n\\t}\\n}\\n\\n",
1583 "The program displays the sequence number of the character from which begin words: dad, mom, son, daughter.\\n\\nAnswer:\\n\\n3\\n22\\n41\\n60\\n\\n",
1584 "3\\n22\\n41\\n60",
1585 "1",
1586 "1",
1587 "62"
1588 ]
1589 },
1590 {
1591 "-name": "question099",
1592 "item": [
1593 "99",
1594 "20",
1595 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// методы клаÑÑа String, replace\\n\\t\\tString stroka = \"My dad is at home, my mom is at home, my son is at home, my daughter is at home.\";\\n\\t\\tSystem.out.println(stroka);\\n\\t\\tString stroka1 = stroka.replace(\"home\", \"school\");\\n\\t\\tSystem.out.println(stroka1);\\n\\t\\tString stroka2 = stroka1.replace(\"my son\", \"John\");\\n\\t\\tSystem.out.println(stroka2);\\n\\t\\tString stroka3 = stroka2.replace(\"my daughter\", \"Bella\");\\n\\t\\tSystem.out.println(stroka3);\\n\\t}\\n}\\n\\n",
1596 "The program changes one sequences of symbols for others.\\n\\nAnswer:\\n\\nMy dad is at home, my mom is at home, my son is at home, my daughter is at home.\\nMy dad is at school, my mom is at school, my son is at school, my daughter is at school.\\nMy dad is at school, my mom is at school, John is at school, my daughter is at school.\\nMy dad is at school, my mom is at school, John is at school, Bella is at school.\\n\\n",
1597 "My dad is at home, my mom is at home, my son is at home, my daughter is at home.\\nMy dad is at school, my mom is at school, my son is at school, my daughter is at school.\\nMy dad is at school, my mom is at school, John is at school, my daughter is at school.\\nMy dad is at school, my mom is at school, John is at school, Bella is at school.",
1598 "1",
1599 "2",
1600 "62"
1601 ]
1602 },
1603 {
1604 "-name": "question100",
1605 "item": [
1606 "100",
1607 "20",
1608 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// methods of the String class,split\\n\\t\\tString stroka = \"dad is at home, mom is at home, son is at home, daughter is at home\";\\n\\t\\tSystem.out.println(stroka);\\n\\t\\tString str[] = stroka.split(\" \");\\n\\t\\tint l = str.length;\\n\\t\\tfor (int i = 0; i < l; i++) {\\n\\t\\t\\tSystem.out.println(\"str[\" + i + \"] = \" + str[i]);\\n\\t\\t}\\n\\t\\tfor (int i = (l - 1); i >= 0; i = i - 1) {\\n\\t\\t\\tSystem.out.print(str[i] + \" \");\\n\\t\\t}\\n\\t}\\n}\\n\\n",
1609 "The program splits the string into an array of strings. The separator is a space. The program prints each element of the array and returns the string in reverse order.\\n\\nAnswer:\\n\\ndad is at home, mom is at home, son is at home, daughter is at home\\nstr[0] = dad\\nstr[1] = is\\nstr[2] = at\\nstr[3] = home,\\nstr[4] = mom\\nstr[5] = is\\nstr[6] = at\\nstr[7] = home,\\nstr[8] = son\\nstr[9] = is\\nstr[10] = at\\nstr[11] = home,\\nstr[12] = daughter\\nstr[13] = is\\nstr[14] = at\\nstr[15] = home\\nhome at is daughter home, at is son home, at is mom home, at is dad",
1610 "dad is at home, mom is at home, son is at home, daughter is at home\\nstr[0] = dad\\nstr[1] = is\\nstr[2] = at\\nstr[3] = home,\\nstr[4] = mom\\nstr[5] = is\\nstr[6] = at\\nstr[7] = home,\\nstr[8] = son\\nstr[9] = is\\nstr[10] = at\\nstr[11] = home,\\nstr[12] = daughter\\nstr[13] = is\\nstr[14] = at\\nstr[15] = home\\nhome at is daughter home, at is son home, at is mom home, at is dad",
1611 "1",
1612 "3",
1613 "70"
1614 ]
1615 },
1616 {
1617 "-name": "question101",
1618 "item": [
1619 "101",
1620 "21",
1621 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box();\\n\\t\\tSystem.out.println(\"Box\");\\n\\t\\tSystem.out.println(\"Width:\" + box1.width + \" cm\");\\n\\t\\tSystem.out.println(\"Height:\" + box1.height + \" cm\");\\n\\t\\tSystem.out.println(\"Depth:\" + box1.depth + \" cm\");\\n\\t\\tSystem.out.println(\"Color:\" + box1.colors);\\n\\t}\\n}\\n",
1622 "public class Box {// the class is declared\\n\\tint width = 10;\\n\\tint height = 10;\\n\\tint depth = 10;\\n\\tString colors = \"blue\";\\n}\\n",
1623 "The program displays the size and the color of the box.\\n\\nAnswer:\\n\\nBox\\nWidth:10 cm\\nHeight:10 cm\\nDepth:10 cm\\nColor:blue\\n",
1624 "Box\\nWidth:10 cm\\nHeight:10 cm\\nDepth:10 cm\\nColor:blue\\n",
1625 "1",
1626 "2",
1627 "19"
1628 ]
1629 },
1630 {
1631 "-name": "question102",
1632 "item": [
1633 "102",
1634 "21",
1635 "public class Box {\\n\\tint width = 10;\\n\\tString colors = \"blue\";\\n}\\n",
1636 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box();\\n\\t\\tSystem.out.println(\"Box\");\\n\\t\\tSystem.out.println(\"Width:\" + box1.width + \" cm\");\\n\\t\\tSystem.out.println(\"Color:\" + box1.colors);\\n\\t}\\n}\\n",
1637 "The program displays the width and the color of the box.\\n\\nAnswer:\\n\\nBox\\nWidth:10 cm\\nColor:blue\\n",
1638 "Box\\nWidth:10 cm\\nColor:blue\\n",
1639 "1",
1640 "1",
1641 "1"
1642 ]
1643 },
1644 {
1645 "-name": "question103",
1646 "item": [
1647 "103",
1648 "21",
1649 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tMan man2 = new Man();\\n\\t\\tman1.name = \"Andrew\";\\n\\t\\tman1.surname = \"Adamson\";\\n\\t\\tman1.age = 20;\\n\\t\\tman1.height = 180;\\n\\t\\tman1.weight = 63;\\n\\t\\tman2.name = \"Alex\";\\n\\t\\tman2.surname = \"Barrington\";\\n\\t\\tman2.age = 19;\\n\\t\\tman2.height = 178;\\n\\t\\tman2.weight = 70;\\n\\t\\tSystem.out.println(\"Student â„–1\");\\n\\t\\tSystem.out.println(\"Name:\" + man1.name);\\n\\t\\tSystem.out.println(\"Surname:\" + man1.surname);\\n\\t\\tSystem.out.println(\"Age:\" + man1.age);\\n\\t\\tSystem.out.println(\"Height:\" + man1.height);\\n\\t\\tSystem.out.println(\"Weight:\" + man1.weight);\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(\"Student â„–2\");\\n\\t\\tSystem.out.println(\"Name:\" + man2.name);\\n\\t\\tSystem.out.println(\"Surname:\" + man2.surname);\\n\\t\\tSystem.out.println(\"Age:\" + man2.age);\\n\\t\\tSystem.out.println(\"Height:\" + man2.height);\\n\\t\\tSystem.out.println(\"Weight:\" + man2.weight);\\n\\t}\\n}\\n",
1650 "public class Man {\\n\\n\\tString name;\\n\\tString surname;\\n\\tint age;\\n\\tint height;\\n\\tint weight;\\n\\n}\\n",
1651 "The program displays information about students.\\n\\nAnswer:\\n\\nStudent â„–1\\nName:Andrew\\nSurname:Adamson\\nAge:20\\nHeight:180\\nWeight:63\\n\\nStudent â„–2\\nName:Alex\\nSurname:Barrington\\nAge:19\\nHeight:178\\nWeight:70\\n",
1652 "Student â„–1\\nName:Andrew\\nSurname:Adamson\\nAge:20\\nHeight:180\\nWeight:63\\n\\nStudent â„–2\\nName:Alex\\nSurname:Barrington\\nAge:19\\nHeight:178\\nWeight:70\\n",
1653 "2",
1654 "4",
1655 "19"
1656 ]
1657 },
1658 {
1659 "-name": "question104",
1660 "item": [
1661 "104",
1662 "21",
1663 "public class Man {\\n\\tString name;\\n\\tString surname;\\n\\tint age;\\n\\tint height;\\n\\tint weight;\\n}\\n",
1664 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tMan man2 = new Man();\\n\\n\\t\\tman1.name = \"Andrew\";\\n\\t\\tman1.surname = \"Adamson\";\\n\\t\\tman1.age = 20;\\n\\t\\tman1.height = 180;\\n\\t\\tman1.weight = 63;\\n\\n\\t\\tman2.name = \"Alex\";\\n\\t\\tman2.surname = \"Barrington\";\\n\\t\\tman2.age = 19;\\n\\t\\tman2.height = 178;\\n\\t\\tman2.weight = 70;\\n\\n\\t\\tSystem.out.println(\"Student â„–1\");\\n\\t\\tSystem.out.println(\"Name:\" + man1.name);\\n\\t\\tSystem.out.println(\"Surname:\" + man1.surname);\\n\\t\\tSystem.out.println(\"Age:\" + man1.age);\\n\\t\\tSystem.out.println(\"Height:\" + man1.height);\\n\\t\\tSystem.out.println(\"Weight:\" + man1.weight);\\n\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tSystem.out.println(\"Student â„–2\");\\n\\t\\tSystem.out.println(\"Name:\" + man2.name);\\n\\t\\tSystem.out.println(\"Surname:\" + man2.surname);\\n\\t\\tSystem.out.println(\"Age:\" + man2.age);\\n\\t\\tSystem.out.println(\"Height:\" + man2.height);\\n\\t\\tSystem.out.println(\"Weight:\" + man2.weight);\\n\\t}\\n}\\n",
1665 "The program displays information about students.\\n\\nAnswer:\\n\\nStudent â„–1\\nName:Andrew\\nSurname:Adamson\\nAge:20\\nHeight:180\\nWeight:63\\n\\nStudent â„–2\\nName:Alex\\nSurname:Barrington\\nAge:19\\nHeight:178\\nWeight:70\\n",
1666 "Student â„–1\\nName:Andrew\\nSurname:Adamson\\nAge:20\\nHeight:180\\nWeight:63\\n\\nStudent â„–2\\nName:Alex\\nSurname:Barrington\\nAge:19\\nHeight:178\\nWeight:70\\n",
1667 "1",
1668 "1",
1669 "1"
1670 ]
1671 },
1672 {
1673 "-name": "question105",
1674 "item": [
1675 "105",
1676 "21",
1677 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tAnim anim1 = new Anim();\\n\\t\\tAnim anim2 = new Anim();\\n\\t\\tAnim anim3 = new Anim();\\n\\n\\t\\tanim1.animal = \"the goat\";\\n\\t\\tanim1.name = \"Tutti\";\\n\\t\\tanim1.age = 3;\\n\\n\\t\\tanim2.animal = \"the cow\";\\n\\t\\tanim2.name = \"Luna\";\\n\\t\\tanim2.age = 4;\\n\\n\\t\\tanim3.animal = \"the piggy\";\\n\\t\\tanim3.name = \"Petra\";\\n\\t\\tanim3.age = 2;\\n\\n\\t\\tSystem.out.println(\"The grandmother has:\");\\n\\t\\tSystem.out.println(anim1.animal + \" \" + anim1.name + \" \" + anim1.age\\n\\t\\t\\t\\t+ \" years\");\\n\\t\\tSystem.out.println(anim2.animal + \" \" + anim2.name + \" \" + anim2.age\\n\\t\\t\\t\\t+ \" years\");\\n\\t\\tSystem.out.println(anim3.animal + \" \" + anim3.name + \" \" + anim3.age\\n\\t\\t\\t\\t+ \" years\");\\n\\n\\t}\\n}\\n",
1678 "public class Anim {\\n\\tString animal;\\n\\tString name;\\n\\tint age;\\n}\\n",
1679 "The program displays information about grandmother's animals.\\n\\nAnswer:\\n\\nThe grandmother has:\\nthe goat Tutti 3 years\\nthe cow Luna 4 years\\nthe piggy Petra 2 years\\n",
1680 "The grandmother has:\\nthe goat Tutti 3 years\\nthe cow Luna 4 years\\nthe piggy Petra 2 years\\n",
1681 "1",
1682 "3",
1683 "20"
1684 ]
1685 },
1686 {
1687 "-name": "question106",
1688 "item": [
1689 "106",
1690 "22",
1691 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint mark1 = (int) (Math.random() * 10) + 1;\\n\\t\\tint mark2 = (int) (Math.random() * 10) + 1;\\n\\t\\tint mark3 = (int) (Math.random() * 10) + 1;\\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.name = \"Peter \";\\n\\t\\tstudent1.mark = mark1;\\n\\t\\tif (student1.mark > 5) {\\n\\t\\t\\tstudent1.result = \" passed\";\\n\\t\\t} else {\\n\\t\\t\\tstudent1.result = \" did not pass\";\\n\\t\\t}\\n\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.name = \"John \";\\n\\t\\tstudent2.mark = mark2;\\n\\t\\tif (student2.mark > 5) {\\n\\t\\t\\tstudent2.result = \" passed\";\\n\\t\\t} else {\\n\\t\\t\\tstudent2.result = \" did not pass\";\\n\\t\\t}\\n\\n\\t\\tStud student3 = new Stud();\\n\\t\\tstudent3.name = \"Bill \";\\n\\t\\tstudent3.mark = mark3;\\n\\t\\tif (student3.mark > 5) {\\n\\t\\t\\tstudent3.result = \" passed\";\\n\\t\\t} else {\\n\\t\\t\\tstudent3.result = \" did not pass\";\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(student1.name + student1.mark + student1.result);\\n\\t\\tSystem.out.println(student2.name + student2.mark + student2.result);\\n\\t\\tSystem.out.println(student3.name + student3.mark + student3.result);\\n\\t\\t}\\n}\\n",
1692 "public class Stud {\\n\\tString name;\\n\\tint mark;\\n\\tString result;\\n}\\n",
1693 "The program displays estimates of students and the results, estimates are generated randomly.\\n\\nPossible answer:\\n\\nPeter 2 did not pass\\nJohn 6 passed\\nBill 3 did not pass\\n",
1694 "Peter 2 did not pass\\nJohn 6 passed\\nBill 3 did not pass\\n",
1695 "1",
1696 "3",
1697 "83"
1698 ]
1699 },
1700 {
1701 "-name": "question107",
1702 "item": [
1703 "107",
1704 "22",
1705 "public class Mark {\\n\\tpublic static void main(String[] args) {\\n\\t\\tint mark1 = (int) (Math.random() * 10) + 1;\\n\\t\\tint mark2 = (int) (Math.random() * 10) + 1;\\n\\t\\tint mark3 = (int) (Math.random() * 10) + 1;\\n\\t\\tdouble mediumMarks;// when you calculate mediumMarks \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// you must to declare double type \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// it is necessary \\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.name = \"Peter \";\\n\\t\\tstudent1.mark = mark1;\\n\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.name = \"John \";\\n\\t\\tstudent2.mark = mark2;\\n\\n\\t\\tStud student3 = new Stud();\\n\\t\\tstudent3.name = \"Bill \";\\n\\t\\tstudent3.mark = mark3;\\n\\n\\t\\tmediumMarks = (double) (student1.mark + student2.mark + student3.mark) / 3;\\n\\n\\t\\tSystem.out.println(student1.name + student1.mark);\\n\\t\\tSystem.out.println(student2.name + student2.mark);\\n\\t\\tSystem.out.println(student3.name + student3.mark);\\n\\t\\tSystem.out.println(\"Average grade:\" + mediumMarks);\\n\\t}\\n}\\n",
1706 "public class Stud {\\n\\tString name;\\n\\tint mark;\\n}\\n",
1707 "The program displays grades of students and an average grade of students, grades generated randomly.\\n\\nPossible answer:\\n\\nPeter 4\\nJohn 1\\nBill 10\\nAverage grade:5.0\\n",
1708 "Peter 4\\nJohn 1\\nBill 10\\nAverage grade:5.0\\n",
1709 "1",
1710 "2",
1711 "131"
1712 ]
1713 },
1714 {
1715 "-name": "question108",
1716 "item": [
1717 "108",
1718 "22",
1719 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint side1w = (int) (Math.random() * 100) + 1;\\n\\t\\tint side1h = (int) (Math.random() * 100) + 1;\\n\\t\\tint side2w = (int) (Math.random() * 100) + 1;\\n\\t\\tint side2h = (int) (Math.random() * 100) + 1;\\n\\n\\t\\tBox box1 = new Box();\\n\\t\\tbox1.width = side1w;\\n\\t\\tbox1.height = side1h;\\n\\t\\tbox1.colors = \"Red\";\\n\\n\\t\\tBox box2 = new Box();\\n\\t\\tbox2.width = side2w;\\n\\t\\tbox2.height = side2h;\\n\\t\\tbox2.colors = \"Blue\";\\n\\n\\t\\tint perimeter = (box1.width + box1.height) * 2;\\n\\t\\tSystem.out.println(\"Rectangle \" + box1.colors);\\n\\t\\tSystem.out.println(\"sides \" + box1.width + \" and \" + box1.height);\\n\\t\\tSystem.out.println(\"perimeter \" + perimeter);\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tperimeter = (box2.width + box2.height) * 2;\\n\\t\\tSystem.out.println(\"Rectangle \" + box2.colors);\\n\\t\\tSystem.out.println(\"sides \" + box2.width + \" and \" + box2.height);\\n\\t\\tSystem.out.println(\"perimeter \" + perimeter);\\n\\t}\\n}\\n",
1720 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tString colors;\\n}\\n",
1721 "The program displays colors of the rectangles and its perimeters, the sides are formed randomly.\\n\\nPossible answer:\\n\\nRectangle Red\\nsides 86 and 69\\nperimeter 310\\n\\nRectangle Blue\\nsides 36 and 100\\nperimeter 272\\n",
1722 "Rectangle Red\\nsides 86 and 69\\nperimeter 310\\n\\nRectangle Blue\\nsides 36 and 100\\nperimeter 272\\n",
1723 "1",
1724 "3",
1725 "104"
1726 ]
1727 },
1728 {
1729 "-name": "question109",
1730 "item": [
1731 "109",
1732 "22",
1733 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tint sidew = (int) (Math.random() * 100) + 1;\\n\\t\\tint sideh = (int) (Math.random() * 100) + 1;\\n\\t\\tint sidel = (int) (Math.random() * 100) + 1;\\n\\n\\t\\tBox box1 = new Box();\\n\\t\\tbox1.width = sidew;\\n\\t\\tbox1.height = sideh;\\n\\t\\tbox1.length = sidel;\\n\\n\\t\\tint valueOfBox = (box1.width * box1.height * box1.length);\\n\\t\\tSystem.out.println(\"The box with sides: \");\\n\\t\\tSystem.out.println(box1.width + \", \" + box1.height + \", \" + box1.length\\n\\t\\t\\t\\t+ \".\");\\n\\t\\tSystem.out.println(\"Volume = \" + valueOfBox);\\n\\t}\\n}\\n",
1734 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n}\\n",
1735 "The program displays the volume of the box, the sides are formed randomly.\\n\\nPossible answer:\\n\\nThe box with sides:\\n80, 1, 38.\\nVolume = 3040\\n",
1736 "The box with sides:\\n80, 1, 38.\\nVolume = 3040\\n",
1737 "1",
1738 "2",
1739 "83"
1740 ]
1741 },
1742 {
1743 "-name": "question110",
1744 "item": [
1745 "110",
1746 "22",
1747 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box();\\n\\t\\tint valueOfBox = (box1.width * box1.height * box1.length);\\n\\t\\tSystem.out.println(\"The box has sides: \");\\n\\t\\tSystem.out.println(box1.width + \", \" + box1.height + \", \" + box1.length\\n\\t\\t\\t\\t+ \".\");\\n\\t\\tSystem.out.println(\"Volume = \" + valueOfBox);\\n\\t}\\n}\\n",
1748 "public class Box {\\n\\tint width = 10;\\n\\tint height = 10;\\n\\tint length = 10;\\n}\\n",
1749 "The program displays the volume of the box.\\n\\nAnswer:\\n\\nThe box has sides:\\n10, 10, 10.\\nVolume = 1000\\n",
1750 "The box has sides:\\n 10, 10, 10.\\nVolume = 1000\\n",
1751 "1",
1752 "2",
1753 "19"
1754 ]
1755 },
1756 {
1757 "-name": "question111",
1758 "item": [
1759 "111",
1760 "23",
1761 "import java.util.Scanner;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tBox box1 = new Box();\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter the sides of the box\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.width = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.height = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.length = sc.nextInt();\\n\\n\\t\\tbox1.valueOfBox();\\n\\t\\tbox1.lengthOfSides();\\n\\n\\t\\tsc.close();\\n\\t}\\n}\\n",
1762 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\n\\tpublic void valueOfBox() {\\n\\t\\tSystem.out.println(\"Volume = \" + width * height * length);\\n\\t}\\n\\n\\tpublic void lenghtOfSides() {\\n\\t\\tSystem.out.println(\"Length of the sides = \" + (width + height + length) * 4);\\n\\t}\\n}\\n",
1763 "The user enters the size of the box, the program displays the volume of the box and the length of all sides of the box.\\n\\nPossible answer:\\n\\nEnter the sides of the box\\nType a number:\\n5\\nType a number:\\n5\\nType a number:\\n2\\nVolume = 50\\nLength of the sides = 48\\n",
1764 "Enter the sides of the box\\nType a number:\\n5\\nType a number:\\n5\\nType a number:\\n2\\nVolume = 50\\nLength of the sides = 48\\n",
1765 "1",
1766 "2",
1767 "29"
1768 ]
1769 },
1770 {
1771 "-name": "question112",
1772 "item": [
1773 "112",
1774 "23",
1775 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\n\\tpublic void valueOfBox() {\\n\\t\\tSystem.out.println(\"Volume = \" + width * height * length);\\n\\t}\\n\\n\\tpublic void lengthOfSides() {\\n\\t\\tSystem.out.println(\"Length of the sides = \" + (width + height + length) * 4);\\n\\t}\\n}\\n",
1776 "import java.util.Scanner;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tBox box1 = new Box();\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter the sides of the box\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.width = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.height = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tbox1.length = sc.nextInt();\\n\\n\\t\\tbox1.valueOfBox();\\n\\t\\tbox1.lengthOfSides();\\n\\n\\t\\tsc.close();\\n\\t}\\n}\\n",
1777 "The user enters the size of the box, the program displays the volume of the box and the length of all sides of the box.\\n\\nPossible answer:\\n\\nEnter the sides of the box\\nType a number:\\n5\\nType a number:\\n5\\nType a number:\\n2\\nVolume = 50\\nLength of the sides = 48\\n",
1778 "Enter the sides of the box\\nType a number:\\n5\\nType a number:\\n5\\nType a number:\\n2\\nVolume = 50\\nLength of the sides = 48\\n",
1779 "1",
1780 "2",
1781 "1"
1782 ]
1783 },
1784 {
1785 "-name": "question113",
1786 "item": [
1787 "113",
1788 "23",
1789 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box();\\n\\t\\tSystem.out.println(\"Enter the sides of the box\");\\n\\t\\tbox1.inputSides();\\n\\t\\tbox1.valueOfBox();\\n\\t\\tbox1.lengthOfSides();\\n\\n\\t}\\n}\\n",
1790 "import java.util.Scanner;\\n\\npublic class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\n\\tpublic void valueOfBox() {\\n\\t\\tSystem.out.println(\"Volume = \" + width * height * length);\\n\\t}\\n\\n\\tpublic void lengthOfSides() {\\n\\t\\tSystem.out.println(\"Length of the sides = \" + (width + height + length) * 4);\\n\\t}\\n\\n\\tpublic void inputSides() {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\twidth = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\theight = sc.nextInt();\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tlength = sc.nextInt();\\n\\t\\tSystem.out.println(\"width:\" + width + \" height:\" + height\\n\\t\\t\\t\\t+ \" length:\" + length);\\n\\t\\tsc.close();\\n\\t}\\n}\\n",
1791 "The user enters the dimensions of the box, the program displays the dimensions, the volume of the box and the length of all sides of the box.\\n\\nPossible answer:\\n\\nEnter the sides of the box\\nType a number:\\n2\\nType a number:\\n2\\nType a number:\\n5\\nwidth:2 height:2 length:5\\nVolume = 20\\nLength of the sides = 36\\n",
1792 "Enter the sides of the box\\nType a number:\\n2\\nType a number:\\n2\\nType a number:\\n5\\nwidth:2 height:2 length:5\\nVolume = 20\\nLength of the sides = 36\\n",
1793 "1",
1794 "1",
1795 "19"
1796 ]
1797 },
1798 {
1799 "-name": "question114",
1800 "item": [
1801 "114",
1802 "23",
1803 "public class Mark {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.mathematics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.english = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.physics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.name = \"Peter\";\\n\\n\\t\\tstudent1.greeting();\\n\\t\\tstudent1.medium();\\n\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.mathematics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.english = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.physics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.name = \"Alice\";\\n\\n\\t\\tstudent2.greeting();\\n\\t\\tstudent2.medium();\\n\\t}\\n}\\n",
1804 "public class Stud {\\n\\t// It is necessary to convert to double, because the result is double\\n\\tString name;\\n\\tint mathematics;\\n\\tint english;\\n\\tint physics;\\n\\n\\tpublic void medium() {\\n\\t\\tdouble m = ((double) mathematics + (double) english + (double) physics) / 3;\\n\\t\\tSystem.out.println(\"Average grade \" + m);\\n\\t}\\n\\n\\tpublic void greeting() {\\n\\t\\tSystem.out.println(\"Congratulations, \" + name + \", with exams\");\\n\\t}\\n}\\n",
1805 "Peter and Alice pass three exams, the program displays the congratulations and the average grade of each student.\\n\\nPossible answer:\\n\\nCongratulations, Peter, with exams\\nAverage grade 7.333333333333333\\nCongratulations, Alice, with exams\\nAverage grade 7.0\\n",
1806 "Congratulations, Peter, with exams\\nAverage grade 7.333333333333333\\nCongratulations, Alice, with exams\\nAverage grade 7.0\\n",
1807 "1",
1808 "2",
1809 "20"
1810 ]
1811 },
1812 {
1813 "-name": "question115",
1814 "item": [
1815 "115",
1816 "23",
1817 "public class Stud {\\n\\t// It is necessary to convert to double, because the result is double\\n\\tString name;\\n\\tint mathematics;\\n\\tint english;\\n\\tint physics;\\n\\n\\tpublic void medium() {\\n\\t\\tdouble m = ((double) mathematics + (double) english + (double) physics) / 3;\\n\\t\\tSystem.out.println(\"Average grade \" + m);\\n\\t}\\n\\n\\tpublic void greeting() {\\n\\t\\tSystem.out.println(\"Congratulations, \" + name + \", with exams\");\\n\\t}\\n}\\n",
1818 "public class Mark {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.mathematics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.english = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.physics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent1.name = \"Peter\";\\n\\n\\t\\tstudent1.greeting();\\n\\t\\tstudent1.medium();\\n\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.mathematics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.english = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.physics = (int) (Math.random() * 10) + 1;\\n\\t\\tstudent2.name = \"Alice\";\\n\\n\\t\\tstudent2.greeting();\\n\\t\\tstudent2.medium();\\n\\t}\\n}\\n",
1819 "Peter and Alice pass three exams, the program displays the congratulations and the average grade of each student.\\n\\nPossible answer:\\n\\nCongratulations, Peter, with exams\\nAverage grade 7.333333333333333\\nCongratulations, Alice, with exams\\nAverage grade 7.0\\n",
1820 "Congratulations, Peter, with exams\\nAverage grade 7.333333333333333\\nCongratulations, Alice, with exams\\nAverage grade 7.0\\n",
1821 "1",
1822 "3",
1823 "23"
1824 ]
1825 },
1826 {
1827 "-name": "question116",
1828 "item": [
1829 "116",
1830 "24",
1831 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCircl circl1 = new Circl();\\n\\t\\tcircl1.radius = (int) (Math.random() * 100 + 1);\\n\\n\\t\\tSystem.out.println(\"Circle \" + circl1.color);\\n\\t\\tSystem.out.println(\"Radius \" + circl1.radius);\\n\\t\\tSystem.out.println(\"Area of circle \" + circl1.areaOfCircle());\\n\\t\\tSystem.out.println(\"Circumference \" + circl1.lengthOfCircle());\\n\\t}\\n}\\n",
1832 "public class Circl {\\n\\n\\tint radius;\\n\\tString color = \"Red\";\\n\\n\\tpublic double areaOfCircle() {\\n\\t\\tdouble area = Math.PI * radius * radius;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double lengthOfCircle() {\\n\\t\\tdouble lengthOf = 2 * Math.PI * radius;\\n\\t\\treturn lengthOf;\\n\\t}\\n}\\n",
1833 "The program displays the radius, the color, the area of the circle and the circumference, the radius is set randomly.\\n\\nPossible answer:\\n\\nCircle Red\\nRadius 19\\nArea of circle 1134.1149479459152\\nCircumference 119.38052083641213\\n",
1834 "Circle Red\\nRadius 19\\nArea of circle 1134.1149479459152\\nCircumference 119.38052083641213\\n",
1835 "1",
1836 "1",
1837 "53"
1838 ]
1839 },
1840 {
1841 "-name": "question117",
1842 "item": [
1843 "117",
1844 "24",
1845 "public class Circl {\\n\\n\\tint radius;\\n\\tString color = \"Red\";\\n\\n\\tpublic double areaOfCircle() {\\n\\t\\tdouble area = Math.PI * radius * radius;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double lengthOfCircle() {\\n\\t\\tdouble lengthOf = 2 * Math.PI * radius;\\n\\t\\treturn lengthOf;\\n\\t}\\n}\\n",
1846 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCircl circl1 = new Circl();\\n\\t\\tcircl1.radius = (int) (Math.random() * 100 + 1);\\n\\n\\t\\tSystem.out.println(\"Circle \" + circl1.color);\\n\\t\\tSystem.out.println(\"Radius \" + circl1.radius);\\n\\t\\tSystem.out.println(\"Area of circle \" + circl1.areaOfCircle());\\n\\t\\tSystem.out.println(\"Circumference \" + circl1.lengthOfCircle());\\n\\t}\\n}\\n",
1847 "The program displays the radius, the color, the area of the circle and the circumference, the radius is set randomly.\\n\\nPossible answer:\\n\\nCircle Red\\nRadius 19\\nArea of circle 1134.1149479459152\\nCircumference 119.38052083641213\\n",
1848 "Circle Red\\nRadius 19\\nArea of circle 1134.1149479459152\\nCircumference 119.38052083641213\\n",
1849 "1",
1850 "2",
1851 "18"
1852 ]
1853 },
1854 {
1855 "-name": "question118",
1856 "item": [
1857 "118",
1858 "24",
1859 "public class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan student1 = new Man();\\n\\t\\tMan student2 = new Man();\\n\\t\\tstudent1.name = \"Liza\";\\n\\t\\tstudent2.name = \"Bob\";\\n\\t\\tstudent1.mathematics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent1.physics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent1.english = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.mathematics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.physics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.english = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tSystem.out.println(student1.greeting());\\n\\t\\tSystem.out.println(student2.greeting());\\n\\n\\t\\tSystem.out.println(\"The average grade, \" + student1.name + \" - \"\\n\\t\\t\\t\\t+ student1.midleMark());\\n\\t\\tSystem.out.println(\"The average grade, \" + student2.name + \" - \"\\n\\t\\t\\t\\t+ student2.midleMark());\\n\\n\\t}\\n}\\n",
1860 "public class Man {\\n\\tString name;\\n\\tint mathematics;\\n\\tint physics;\\n\\tint english;\\n\\n\\tpublic String greeting() {\\n\\t\\tString stroka = name + \", our congratulations, you passed the exams\";\\n\\t\\treturn stroka;\\n\\t}\\n\\n\\tpublic double midleMark() {\\n\\t\\tdouble d = ((double) mathematics + (double) physics + (double) english) / 3;\\n\\t\\treturn d;\\n\\t}\\n}\\n",
1861 "The program displays congratulations Lisa and Bob that they passed examinatios and considers their average grades, grades are given randomly.\\n\\nPossible answer:\\n\\nLiza, our congratulations, you passed the exams\\nBob, our congratulations, you passed the exams\\nThe average grade, Liza - 4.333333333333333\\nThe average grade, Bob - 3.0\\n",
1862 "Liza, our congratulations, you passed the exams\\nBob, our congratulations, you passed the exams\\nThe average grade, Liza - 4.333333333333333\\nThe average grade, Bob - 3.0\\n",
1863 "1",
1864 "2",
1865 "191"
1866 ]
1867 },
1868 {
1869 "-name": "question119",
1870 "item": [
1871 "119",
1872 "24",
1873 "public class Man {\\n\\tString name;\\n\\tint mathematics;\\n\\tint physics;\\n\\tint english;\\n\\n\\tpublic String greeting() {\\n\\t\\tString stroka = name + \", our congratulations, you passed the exams\";\\n\\t\\treturn stroka;\\n\\t}\\n\\n\\tpublic double midleMark() {\\n\\t\\tdouble d = ((double) mathematics + (double) physics + (double) english) / 3;\\n\\t\\treturn d;\\n\\t}\\n}\\n",
1874 "public class Test {\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan student1 = new Man();\\n\\t\\tMan student2 = new Man();\\n\\t\\tstudent1.name = \"Liza\";\\n\\t\\tstudent2.name = \"Bob\";\\n\\t\\tstudent1.mathematics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent1.physics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent1.english = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.mathematics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.physics = (int) (Math.random() * 10 + 1);\\n\\t\\tstudent2.english = (int) (Math.random() * 10 + 1);\\n\\n\\t\\tSystem.out.println(student1.greeting());\\n\\t\\tSystem.out.println(student2.greeting());\\n\\n\\t\\tSystem.out.println(\"The average grade, \" + student1.name + \" - \"\\n\\t\\t\\t\\t+ student1.midleMark());\\n\\t\\tSystem.out.println(\"The average grade, \" + student2.name + \" - \"\\n\\t\\t\\t\\t+ student2.midleMark());\\n\\n\\t}\\n}\\n",
1875 "The program displays congratulations Lisa and Bob that they passed examinatios and considers their average grades, grades are given randomly.\\n\\nPossible answer:\\n\\nLiza, our congratulations, you passed the exams\\nBob, our congratulations, you passed the exams\\nThe average grade, Liza - 4.333333333333333\\nThe average grade, Bob - 3.0\\n",
1876 "Liza, our congratulations, you passed the exams\\nBob, our congratulations, you passed the exams\\nThe average grade, Liza - 4.333333333333333\\nThe average grade, Bob - 3.0\\n",
1877 "1",
1878 "2",
1879 "25"
1880 ]
1881 },
1882 {
1883 "-name": "question120",
1884 "item": [
1885 "120",
1886 "24",
1887 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTri tri1 = new Tri();\\n\\t\\ttri1.base = (int) (Math.random() * 100 + 1);\\n\\t\\ttri1.height = (int) (Math.random() * 100 + 1);\\n\\n\\t\\tTri tri2 = new Tri();\\n\\t\\ttri2.base = (int) (Math.random() * 100 + 1);\\n\\t\\ttri2.height = (int) (Math.random() * 100 + 1);\\n\\n\\t\\tSystem.out.println(tri1.triangle());\\n\\t\\tSystem.out.println(\"The area of the triangle is \" + tri1.areaOfTriangle());\\n\\n\\t\\tSystem.out.println(tri2.triangle());\\n\\t\\tSystem.out.println(\"The area of the triangle is \" + tri2.areaOfTriangle());\\n\\t}\\n}\\n",
1888 "public class Tri {\\n\\n\\tint base;\\n\\tint height;\\n\\tString color = \"Red\";\\n\\n\\tpublic double areaOfTriangle() {\\n\\t\\tdouble area = base * height / 2;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic String triangle() {\\n\\t\\tString str = (color + \" triangle with height \" + height\\n\\t\\t\\t\\t+ \" and base \" + base);\\n\\t\\treturn str;\\n\\t}\\n}\\n",
1889 "The program displays the height and base of the triangle, and then calculates the area and also displays its.\\n\\nPossible answer:\\n\\nRed triangle with height 18 and base 22\\nThe area of the triangle is 198.0\\nRed triangle with height 10 and base 57\\nThe area of the triangle is 285.0\\n",
1890 "Red triangle with height 18 and base 22\\nThe area of the triangle is 198.0\\nRed triangle with height 10 and base 57\\nThe area of the triangle is 285.0\\n",
1891 "1",
1892 "1",
1893 "131"
1894 ]
1895 },
1896 {
1897 "-name": "question121",
1898 "item": [
1899 "121",
1900 "25",
1901 "import java.util.Scanner;\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.name = \"BMW\";\\n\\t\\tcar1.fuelConsumption = 9.7;\\n\\t\\tcar1.valueFuel = 60;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.name = \"Hummer\";\\n\\t\\tcar2.fuelConsumption = 27;\\n\\t\\tcar2.valueFuel = 120;\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.name = \"Toyota\";\\n\\t\\tcar3.fuelConsumption = 5.7;\\n\\t\\tcar3.valueFuel = 50;\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter the distance between two cities\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tcar1.distance(a);\\n\\t\\tcar2.distance(a);\\n\\t\\tcar3.distance(a);\\n\\t}\\n}\\n",
1902 "public class Car {\\n\\n\\tString name;\\n\\tint valueFuel;\\n\\tdouble fuelConsumption;\\n\\n\\tpublic void distance(int distances) {\\n\\t\\tif (valueFuel / fuelConsumption * 100 < distances) {\\n\\t\\t\\tSystem.out.println(name + \" will not reach\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" will reach\");\\n\\t\\t}\\n\\t}\\n}\\n",
1903 "The user enters the distance between two cities. The program determines if cars can reach one city from another with full tanks of fuel. The program displays a message.\\n\\nPossible answer:\\n\\nEnter the distance between two cities\\nType a number:\\n600\\nBMW will reach\\nHummer will not reach\\nToyota will reach\\n",
1904 "Enter the distance between two cities\\nType a number:\\n600\\nBMW will reach\\nHummer will not reach\\nToyota will reach\\n",
1905 "1",
1906 "1",
1907 "214"
1908 ]
1909 },
1910 {
1911 "-name": "question122",
1912 "item": [
1913 "122",
1914 "25",
1915 "public class Car {\\n\\n\\tString name;\\n\\tint valueFuel;\\n\\tdouble fuelConsumption;\\n\\n\\tpublic void distance(int distances) {\\n\\t\\tif (valueFuel / fuelConsumption * 100 < distances) {\\n\\t\\t\\tSystem.out.println(name + \" will not reach\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" will reach\");\\n\\t\\t}\\n\\t}\\n}\\n",
1916 "import java.util.Scanner;\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.name = \"BMW\";\\n\\t\\tcar1.fuelConsumption = 9.7;\\n\\t\\tcar1.valueFuel = 60;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.name = \"Hummer\";\\n\\t\\tcar2.fuelConsumption = 27;\\n\\t\\tcar2.valueFuel = 120;\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.name = \"Toyota\";\\n\\t\\tcar3.fuelConsumption = 5.7;\\n\\t\\tcar3.valueFuel = 50;\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter the distance between two cities\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tcar1.distance(a);\\n\\t\\tcar2.distance(a);\\n\\t\\tcar3.distance(a);\\n\\t}\\n}\\n",
1917 "The user enters the distance between two cities. The program determines if cars can reach one city from another with full tanks of fuel. The program displays a message.\\n\\nPossible answer:\\n\\nEnter the distance between two cities\\nType a number:\\n600\\nBMW will reach\\nHummer will not reach\\nToyota will reach\\n",
1918 "Enter the distance between two cities\\nType a number:\\n600\\nBMW will reach\\nHummer will not reach\\nToyota will reach\\n",
1919 "1",
1920 "2",
1921 "21"
1922 ]
1923 },
1924 {
1925 "-name": "question123",
1926 "item": [
1927 "123",
1928 "25",
1929 "public class Man {\\n\\n\\tString name;\\n\\tint age;\\n\\tint weight;\\n\\n\\tpublic void reach(int speed) {\\n\\t\\tif ((10 / speed) < 2) {\\n\\t\\t\\tSystem.out.println(name + \" will take the train\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" will not take the train\");\\n\\t\\t}\\n\\t}\\n}\\n",
1930 "import java.util.Scanner;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Peter\";\\n\\t\\tman1.age = 19;\\n\\t\\tman1.weight = 60;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Grandfather John\";\\n\\t\\tman2.age = 75;\\n\\t\\tman2.weight = 65;\\n\\n\\t\\tMan man3 = new Man();\\n\\t\\tman3.name = \"Bill\";\\n\\t\\tman3.age = 20;\\n\\t\\tman3.weight = 110;\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tString s = \"Enter the walking speed of the pedestrian\";\\n\\t\\tSystem.out.println(s);\\n\\t\\tSystem.out.println(man1.name + \", \" + man1.age + \" years old, weight - \"\\n\\t\\t\\t\\t+ man1.weight + \" kg\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a1 = sc.nextInt();\\n\\t\\tSystem.out.println(s);\\n\\t\\tSystem.out.println(man2.name + \", \" + man2.age + \" years old, weight - \"\\n\\t\\t\\t\\t+ man2.weight + \" kg\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a2 = sc.nextInt();\\n\\t\\tSystem.out.println(s);\\n\\t\\tSystem.out.println(man3.name + \", \" + man3.age + \" years old, weight - \"\\n\\t\\t\\t\\t+ man3.weight + \" kg\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a3 = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tman1.reach(a1);\\n\\t\\tman2.reach(a2);\\n\\t\\tman3.reach(a3);\\n\\t}\\n}\\n",
1931 "The distance from the village to the station is 10 km. Three pedestrians leave the village to take the train. The train is departing in 2 hours. The user enters the speed of walking of pedestrians, the program defines, if pedestrians can take the train , and displays the message.\\n\\nPossible answer:\\n\\nEnter the walking speed of the pedestrian\\nPeter, 19 years old, weight - 60 kg\\nType a number:\\n6\\nEnter the walking speed of the pedestrian\\nGrandfather John, 75 years old, weight - 65 kg\\nType a number:\\n4\\nEnter the walking speed of the pedestrian\\nBill, 20 years old, weight - 110 kg\\nType a number:\\n3\\nPeter will take the train\\nGrandfather John will not take the train\\nBill will not take the train\\n",
1932 "Enter the walking speed of the pedestrian\\nPeter, 19 years old, weight - 60 kg\\nType a number:\\n6\\nEnter the walking speed of the pedestrian\\nGrandfather John, 75 years old, weight - 65 kg\\nType a number:\\n4\\nEnter the walking speed of the pedestrian\\nBill, 20 years old, weight 110 kg\\nType a number:\\n3\\nPeter will take the train\\nGrandfather will not take the train\\nBill will not take the train\\n",
1933 "1",
1934 "2",
1935 "21"
1936 ]
1937 },
1938 {
1939 "-name": "question124",
1940 "item": [
1941 "124",
1942 "25",
1943 "public class Stud {\\n\\n\\tString name;\\n\\n\\tpublic String gratter(int mark) {\\n\\t\\tString a = \"The student \" + name + \" got \" + mark;\\n\\t\\tif (mark < 5) {\\n\\t\\t\\ta = a + \", bad result.\";\\n\\t\\t} else {\\n\\t\\t\\ta = a + \", good result.\";\\n\\t\\t}\\n\\t\\treturn a;\\n\\t}\\n}\\n",
1944 "import java.util.Scanner;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.name = \"Peter\";\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.name = \"Bella\";\\n\\t\\tStud student3 = new Stud();\\n\\t\\tstudent3.name = \"Alice\";\\n\\t\\tStud student4 = new Stud();\\n\\t\\tstudent4.name = \"John\";\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student1.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark1 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student2.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark2 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student3.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark3 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student4.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark4 = sc.nextInt();\\n\\t\\tsc.close()\\n\\n\\t\\tSystem.out.println(student1.gratter(mark1));\\n\\t\\tSystem.out.println(student2.gratter(mark2));\\n\\t\\tSystem.out.println(student3.gratter(mark3));\\n\\t\\tSystem.out.println(student4.gratter(mark4));\\n\\n\\t}\\n}\\n",
1945 "The user enters grades of students, the program displays the message, depending on the grades.\\n\\nPossible answer:\\n\\nEnter an grade to the student Peter\\nType a number:\\n4\\nEnter an grade to the student Bella\\nType a number:\\n6\\nEnter an grade to the student Alice\\nType a number:\\n8\\nEnter an grade to the student John\\nType a number:\\n1\\nThe student Peter got 4, bad result.\\nThe student Bella got 6, good result.\\nThe student Alice got 8, good result.\\nThe student John got 1, bad result.\\n",
1946 "Enter an grade to the student Peter\\nType a number:\\n4\\nEnter an grade to the student Bella\\nType a number:\\n6\\nEnter an grade to the student Alice\\nType a number:\\n8\\nEnter an grade to the student John\\nType a number:\\n1\\nThe student Peter got 4, bad result.\\nThe student Bella got 6, good result.\\nThe student Alice got 8, good result.\\nThe student John got 1, bad result.\\n",
1947 "1",
1948 "2",
1949 "11"
1950 ]
1951 },
1952 {
1953 "-name": "question125",
1954 "item": [
1955 "125",
1956 "25",
1957 "import java.util.Scanner;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tStud student1 = new Stud();\\n\\t\\tstudent1.name = \"Peter\";\\n\\t\\tStud student2 = new Stud();\\n\\t\\tstudent2.name = \"Bella\";\\n\\t\\tStud student3 = new Stud();\\n\\t\\tstudent3.name = \"Alice\";\\n\\t\\tStud student4 = new Stud();\\n\\t\\tstudent4.name = \"John\";\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student1.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\n\\t\\tint mark1 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student2.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark2 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student3.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark3 = sc.nextInt();\\n\\n\\t\\tSystem.out.println(\"Enter an grade to the student \" + student4.name);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint mark4 = sc.nextInt();\\n\\t\\tsc.close()\\n\\n\\t\\tSystem.out.println(student1.gratter(mark1));\\n\\t\\tSystem.out.println(student2.gratter(mark2));\\n\\t\\tSystem.out.println(student3.gratter(mark3));\\n\\t\\tSystem.out.println(student4.gratter(mark4));\\n\\n\\t}\\n}\\n",
1958 "public class Stud {\\n\\n\\tString name;\\n\\n\\tpublic String gratter(int mark) {\\n\\t\\tString a = \"The student \" + name + \" got \" + mark;\\n\\t\\tif (mark < 5) {\\n\\t\\t\\ta = a + \", bad result.\";\\n\\t\\t} else {\\n\\t\\t\\ta = a + \", good result.\";\\n\\t\\t}\\n\\t\\treturn a;\\n\\t}\\n}\\n",
1959 "The user enters grades to students, the program displays the message, depending on the grades.\\n\\nPossible answer:\\n\\nEnter an grade to the student Peter\\nType a number:\\n4\\nEnter an grade to the student Bella\\nType a number:\\n6\\nEnter an grade to the student Alice\\nType a number:\\n8\\nEnter an grade to the student John\\nType a number:\\n1\\nThe student Peter got 4, bad result.\\nThe student Bella got 6, good result.\\nThe student Alice got 8, good result.\\nThe student John got 1, bad result.\\n",
1960 "Enter an grade to the student Peter\\nType a number:\\n4\\nEnter an grade to the student Bella\\nType a number:\\n6\\nEnter an grade to the student Alice\\nType a number:\\n8\\nEnter an grade to the student John\\nType a number:\\n1\\nThe student Peter got 4, bad result.\\nThe student Bella got 6, good result.\\nThe student Alice got 8, good result.\\nThe student John got 1, bad result.\\n",
1961 "1",
1962 "1",
1963 "329"
1964 ]
1965 },
1966 {
1967 "-name": "question126",
1968 "item": [
1969 "126",
1970 "26",
1971 "public class Trip {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Alex\";\\n\\t\\tman1.surname = \"Adamson\";\\n\\t\\tman1.age = 19;\\n\\t\\tman1.student = true;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Mike\";\\n\\t\\tman2.surname = \"Davidson\";\\n\\t\\tman2.age = 27;\\n\\t\\tman2.student = false;\\n\\n\\t\\tString town = \"Paris\";\\n\\t\\tint cost = 1500;\\n\\n\\t\\tman1.getTicket(town, cost);\\n\\t\\tman2.getTicket(town, cost);\\n\\t}\\n}\\n",
1972 "public class Man {\\n\\n\\tString name;\\n\\tString surname;\\n\\tint age;\\n\\tboolean student;\\n\\n\\tpublic void getTicket(String town, int cost) {\\n\\t\\tString exemption = \"0 percent\";\\n\\t\\tif (student == true) {\\n\\t\\t\\texemption = \"50 percent\";\\n\\t\\t\\tcost = cost / 2;\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(\"----------------------------\");\\n\\t\\tSystem.out.println(\"******A ticket to \" + town + \"******\");\\n\\t\\tSystem.out.println(name + \", \" + surname + \", \" + age + \"years old\");\\n\\t\\tSystem.out.println(\"*****rebate-\" + exemption + \"*****\");\\n\\t\\tSystem.out.println(\"*******Cost-\" + cost + \"dol.*******\");\\n\\t\\tSystem.out.println(\"*****Pleasant journey******\");\\n\\t\\tSystem.out.println(\"----------------------------\");\\n\\n\\t}\\n}\\n",
1973 "The program displays two tickets for Alex and Mike to Paris, the ticket price depends on the availability of rebates.\\n\\nAnswer:\\n\\n----------------------------\\n******A ticket to Paris******\\nAlex, Adamson, 19 years old\\n*****rebate-50 percent*****\\n*******Cost-750dol.*******\\n*****Pleasant journey******\\n----------------------------\\n----------------------------\\n******A ticket to Paris******\\nMike, Davidson, 27years old\\n*****rebate-0 percent*****\\n*******Cost-1500dol.*******\\n*****Pleasant journey******\\n----------------------------\\n",
1974 "----------------------------\\n******A ticket to Paris******\\nAlex, Adamson, 19 years old\\n*****rebate-50 percent*****\\n*******Cost-750dol.*******\\n*****Pleasant journey******\\n----------------------------\\n----------------------------\\n******A ticket to Paris******\\nMike, Davidson, 27years old\\n*****rebate-0 percent*****\\n*******Cost-1500dol.*******\\n*****Pleasant journey******\\n----------------------------\\n",
1975 "1",
1976 "1",
1977 "116"
1978 ]
1979 },
1980 {
1981 "-name": "question127",
1982 "item": [
1983 "127",
1984 "26",
1985 "public class Man {\\n\\n\\tString name;\\n\\tString surname;\\n\\tint age;\\n\\tboolean student;\\n\\n\\tpublic void getTicket(String town, int cost) {\\n\\t\\tString exemption = \"0 percent\";\\n\\t\\tif (student == true) {\\n\\t\\t\\texemption = \"50 percent\";\\n\\t\\t\\tcost = cost / 2;\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(\"----------------------------\");\\n\\t\\tSystem.out.println(\"******A ticket to \" + town + \"******\");\\n\\t\\tSystem.out.println(name + \", \" + surname + \", \" + age + \"years old\");\\n\\t\\tSystem.out.println(\"*****rebate-\" + exemption + \"*****\");\\n\\t\\tSystem.out.println(\"*******Cost-\" + cost + \"dol.*******\");\\n\\t\\tSystem.out.println(\"*****Pleasant journey******\");\\n\\t\\tSystem.out.println(\"----------------------------\");\\n\\n\\t}\\n}\\n",
1986 "public class Trip {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Alex\";\\n\\t\\tman1.surname = \"Adamson\";\\n\\t\\tman1.age = 19;\\n\\t\\tman1.student = true;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Mike\";\\n\\t\\tman2.surname = \"Davidson\";\\n\\t\\tman2.age = 27;\\n\\t\\tman2.student = false;\\n\\n\\t\\tString town = \"Paris\";\\n\\t\\tint cost = 1500;\\n\\n\\t\\tman1.getTicket(town, cost);\\n\\t\\tman2.getTicket(town, cost);\\n\\t}\\n}\\n",
1987 "The program displays two tickets for Alex and Mike to Paris, the ticket price depends on the availability of rebates.\\n\\nAnswer:\\n\\n----------------------------\\n******A ticket to Paris******\\nAlex, Adamson, 19 years old\\n*****rebate-50 percent*****\\n*******Cost-750dol.*******\\n*****Pleasant journey******\\n----------------------------\\n----------------------------\\n******A ticket to Paris******\\nMike, Davidson, 27years old\\n*****rebate-0 percent*****\\n*******Cost-1500dol.*******\\n*****Pleasant journey******\\n----------------------------\\n",
1988 "----------------------------\\n******A ticket to Paris******\\nAlex, Adamson, 19 years old\\n*****rebate-50 percent*****\\n*******Cost-750dol.*******\\n*****Pleasant journey******\\n----------------------------\\n----------------------------\\n******A ticket to Paris******\\nMike, Davidson, 27years old\\n*****rebate-0 percent*****\\n*******Cost-1500dol.*******\\n*****Pleasant journey******\\n----------------------------\\n",
1989 "1",
1990 "3",
1991 "26"
1992 ]
1993 },
1994 {
1995 "-name": "question128",
1996 "item": [
1997 "128",
1998 "26",
1999 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ();\\n\\t\\tcircle1.color = \"Red\";\\n\\t\\tcircle1.radius = 10;\\n\\n\\t\\tCirc circle2 = new Circ();\\n\\t\\tcircle2.color = \"Blue\";\\n\\t\\tcircle2.radius = 5;\\n\\n\\t\\tint angleA = (int) (Math.random() * 360) + 1;\\n\\t\\tint angleB = (int) (Math.random() * 360) + 1;\\n\\n\\t\\tSystem.out.println(circle1.color + \" circle\");\\n\\t\\tSystem.out.println(\"Ragius \" + circle1.radius);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + circle1.areaS(angleA, angleB));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + circle1.lengthOfark(angleA, angleB));\\n\\t\\tSystem.out.println(\"--------------------------\");\\n\\n\\t\\tSystem.out.println(circle2.color + \" circle\");\\n\\t\\tSystem.out.println(\"Radius \" + circle2.radius);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + circle2.areaS(angleA, angleB));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + circle2.lengthOfark(angleA, angleB));\\n\\n\\t}\\n}\\n",
2000 "public class Circ {\\n\\t// circle sector = PI*r*r*n/360\\n\\t// circle arc length = 2*PI*r*n/360,\\n\\t// where PI-PI, r is the radius, n is the sector angle in degrees\\n\\n\\tString color;\\n\\tint radius;\\n\\n\\tpublic double areaS(int a, int b) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = Math.PI * radius * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double lengthOfark(int a, int b) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = 2 * Math.PI * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
2001 "The program displays the area of the sector and the length of the arc length of circle from angle a to angle b, the angles are formed randomly.\\n\\nPossible answer:\\n\\nRed circle\\nRadius 10\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=75.92182246175334\\nARC LENGTH=15.184364492350667\\n--------------------------\\nBlue circle\\nRadius 5\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=18.980455615438334\\nARC LENGTH=7.592182246175334\\n",
2002 "Red circle\\nRadius 10\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=75.92182246175334\\nARC LENGTH=15.184364492350667\\n--------------------------\\nBlue circle\\nRadius 5\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=18.980455615438334\\nARC LENGTH=7.592182246175334\\n",
2003 "1",
2004 "2",
2005 "121"
2006 ]
2007 },
2008 {
2009 "-name": "question129",
2010 "item": [
2011 "129",
2012 "26",
2013 "public class Circ {\\n\\t// area of the circle sector = PI*r*r*n/360\\n\\t// circle arc length= 2*PI*r*n/360\\n\\t// Where PI-PI, r is the radius, n is the sector angle in degrees\\n\\n\\tString color;\\n\\tint radius;\\n\\n\\tpublic double areaS(int a, int b) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = Math.PI * radius * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double lengthOfark(int a, int b) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = 2 * Math.PI * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
2014 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ();\\n\\t\\tcircle1.color = \"Red\";\\n\\t\\tcircle1.radius = 10;\\n\\n\\t\\tCirc circle2 = new Circ();\\n\\t\\tcircle2.color = \"Blue\";\\n\\t\\tcircle2.radius = 5;\\n\\n\\t\\tint angleA = (int) (Math.random() * 360) + 1;\\n\\t\\tint angleB = (int) (Math.random() * 360) + 1;\\n\\n\\t\\tSystem.out.println(circle1.color + \" circle\");\\n\\t\\tSystem.out.println(\"Radius \" + circle1.radius);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + circle1.areaS(angleA, angleB));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + circle1.lengthOfark(angleA, angleB));\\n\\t\\tSystem.out.println(\"--------------------------\");\\n\\n\\t\\tSystem.out.println(circle2.color + circle);\\n\\t\\tSystem.out.println(\"Radius \" + circle2.radius);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + circle2.areaS(angleA, angleB));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + circle2.lengthOfark(angleA, angleB));\\n\\n\\t}\\n}\\n",
2015 "am displays the area of the sector and the length of the arc length of circle from angle a to angle b, the angles are formed randomly.\\n\\nPossible answer:\\n\\nRed circle\\nRadius 10\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=75.92182246175334\\nARC LENGTH=15.184364492350667\\n--------------------------\\nBlue circle\\nRadius 5\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=18.980455615438334\\nARC LENGTH=7.592182246175334\\n",
2016 "Red circle\\nRadius 10\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=75.92182246175334\\nARC LENGTH=15.184364492350667\\n--------------------------\\nBlue circle\\nRadius 5\\nBetween angles 69 and 156\\nAREA OF THE SECTOR=18.980455615438334\\nARC LENGTH=7.592182246175334\\n",
2017 "1",
2018 "2",
2019 "57"
2020 ]
2021 },
2022 {
2023 "-name": "question130",
2024 "item": [
2025 "130",
2026 "26",
2027 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tSfer sfera1 = new Sfer();\\n\\t\\tsfera1.color = \"Red\";\\n\\n\\t\\tint rad = (int) (Math.random() * 10) + 1;\\n\\t\\tint h = (int) (Math.random() * rad * 2) + 1;\\n\\n\\t\\tSystem.out.println(sfera1.color + \" sphere\");\\n\\t\\tSystem.out.println(\"Radius \" + rad);\\n\\t\\tSystem.out.println(\"Height of the segment\" + h);\\n\\t\\tSystem.out.println(\"Volume of the ball=\" + sfera1.valueSf(rad));\\n\\t\\tSystem.out.println(\"Volume of the ball sector=\" + sfera1.valueSec(h, rad));\\n\\t\\tSystem.out.println(\"Volume of the ball segment=\" + sfera1.valueSig(h, rad));\\n\\t}\\n}\\n",
2028 "public class Sfer {\\n\\t// to work with fractional numbers,\\n\\t// you must first variables of type int to convert into fractional type\\n\\tString color;\\n\\n\\tpublic double valueSec(int h, int radius) {\\n\\t\\tdouble hd = (double) h;\\n\\t\\tdouble radiusd = (double) radius;\\n\\t\\tdouble valueSector = 2.0 / 3.0 * (double) (Math.PI * radiusd * radiusd * hd);\\n\\t\\treturn valueSector;\\n\\t}\\n\\n\\tpublic double valueSig(int h, int radius) {\\n\\t\\tdouble hd = (double) h;\\n\\t\\tdouble radiusd = (double) radius;\\n\\t\\tdouble valueSigment = Math.PI * hd * hd * (radiusd - hd / 3);\\n\\t\\treturn valueSigment;\\n\\t}\\n\\n\\tpublic double valueSf(int radius) {\\n\\t\\tdouble radiusd = (double) radius;\\n\\t\\tdouble valueSfera = 4.0 / 3.0 * (Math.PI * radiusd * radiusd * radiusd);\\n\\t\\treturn valueSfera;\\n\\t}\\n}\\n",
2029 "The program displays the volume of the ball, the ball sector and the ball segment. The radius and the height of the segment are formed randomly.\\n\\nPossible answer:\\n\\nRed sphere\\nRadius 5\\nHeight of the segment 5\\nVolume of the ball=523.5987755982989\\nVolume of the ball sector=261.79938779914943\\nVolume of the ball segment=261.79938779914943\\n",
2030 "Red sphere\\nRadius 5\\nHeight of the segment 5\\nVolume of the ball=523.5987755982989\\nVolume of the ball sector=261.79938779914943\\nVolume of the ball segment=261.79938779914943\\n",
2031 "1",
2032 "1",
2033 "84"
2034 ]
2035 },
2036 {
2037 "-name": "question131",
2038 "item": [
2039 "131",
2040 "27",
2041 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString strSpeedOfLights = \"Light covers the distance from the Sun to the Earth for \";\\n\\t\\tString straOfGravity = \"acceleration of free fall = \";\\n\\t\\tlong timeFromEarthToSun;\\n\\t\\ttimeFromEarthToSun = Cosm.distanceFromEarthToSun / Cosm.speedOfLights;\\n\\t\\tSystem.out.println(strSpeedOfLights + timeFromEarthToSun + \" sec,\");\\n\\t\\tSystem.out.println(straOfGravity + Cosm.aOfGravity + \" m/sec^2.\");\\n\\t}\\n}\\n",
2042 "public class Cosm {\\n\\n\\tstatic long speedOfLights = 300000;\\n\\tstatic double aOfGravity = 9.81;\\n\\tstatic long distanceFromEarthToSun = 150000000;\\n}\\n",
2043 "The program displays a message about the speed of light and the acceleration of free fall.\\n\\nAnswer:\\n\\nLight covers the distance from the Sun to the Earth for 500 sec,\\nacceleration of free fall = 9.81 m/sec^2.\\n",
2044 "Light covers the distance from the Sun to the Earth for 500 sec,\\nacceleration of free fall = 9.81 m/sec^2.\\n",
2045 "1",
2046 "2",
2047 "57"
2048 ]
2049 },
2050 {
2051 "-name": "question132",
2052 "item": [
2053 "132",
2054 "27",
2055 "public class Cosm {\\n\\n\\tstatic long speedOfLights = 300000;\\n\\tstatic double aOfGravity = 9.81;\\n\\tstatic long distanceFromEarthToSun = 150000000;\\n}\\n",
2056 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString strSpeedOfLights = \"Light covers the distance from the Sun to the Earth for \";\\n\\t\\tString straOfGravity = \"acceleration of free fall = \";\\n\\t\\tlong timeFromEarthToSun;\\n\\t\\ttimeFromEarthToSun = Cosm.distanceFromEarthToSun / Cosm.speedOfLights;\\n\\t\\tSystem.out.println(strSpeedOfLights + timeFromEarthToSun + \" sec,\");\\n\\t\\tSystem.out.println(straOfGravity + Cosm.aOfGravity + \" m/sec^2.\");\\n\\t}\\n}\\n",
2057 "The program displays a message about the speed of light and the acceleration of free fall.\\n\\nAnswer:\\n\\nLight covers the distance from the Sun to the Earth for 500 sec,\\nacceleration of free fall = 9.81 m/sec^2.\\n",
2058 "Light covers the distance from the Sun to the Earth for 500 sec,\\nacceleration of free fall = 9.81 m/sec^2.\\n",
2059 "1",
2060 "1",
2061 "1"
2062 ]
2063 },
2064 {
2065 "-name": "question133",
2066 "item": [
2067 "133",
2068 "27",
2069 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString st = \"the difference between the boiling point and the freezing point is \";\\n\\t\\tString g = \" degrees \";\\n\\t\\tSystem.out.println(\"Water:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfWater - Temp.freezOfWater + g));\\n\\t\\tSystem.out.println(\"Oxygen:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfOxygen - Temp.freezOfOxygen + g));\\n\\t\\tSystem.out.println(\"Hydrogen:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfHydrog - Temp.freezOfHydrog + g));\\n\\n\\t}\\n}\\n",
2070 "public class Temp {\\n\\n\\tstatic int absoluteZero = -271;\\n\\tstatic int boilOfWater = 100;\\n\\tstatic int freezOfWater = 0;\\n\\tstatic int freezOfOxygen = -218;\\n\\tstatic int boilOfOxygen = -183;\\n\\tstatic int freezOfHydrog = -259;\\n\\tstatic int boilOfHydrog = -253;\\n}\\n",
2071 "The program calculates differences between temperature of boiling and freezing of substances.\\n\\nAnswer:\\n\\nWater:\\nthe difference between the boiling point and the freezing point is 100 degrees\\nOxygen:\\nthe difference between the boiling point and the freezing point is 35 degrees\\nHydrogen:\\nthe difference between the boiling point and the freezing point is 6 degrees\\n",
2072 "Water:\\nthe difference between the boiling point and the freezing point is 100 degrees\\nOxygen:\\nthe difference between the boiling point and the freezing point is 35 degrees\\nHydrogen:\\nthe difference between the boiling point and the freezing point is 6 degrees\\n",
2073 "1",
2074 "1",
2075 "61"
2076 ]
2077 },
2078 {
2079 "-name": "question134",
2080 "item": [
2081 "134",
2082 "27",
2083 "public class Temp {\\n\\n\\tstatic int absoluteZero = -271;\\n\\tstatic int boilOfWater = 100;\\n\\tstatic int freezOfWater = 0;\\n\\tstatic int freezOfOxygen = -218;\\n\\tstatic int boilOfOxygen = -183;\\n\\tstatic int freezOfHydrog = -259;\\n\\tstatic int boilOfHydrog = -253;\\n}\\n",
2084 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString st = \"the difference between the boiling point and the freezing point is \";\\n\\t\\tString g = \" degrees \";\\n\\t\\tSystem.out.println(\"Water:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfWater - Temp.freezOfWater + g));\\n\\t\\tSystem.out.println(\"Oxygen:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfOxygen - Temp.freezOfOxygen + g));\\n\\t\\tSystem.out.println(\"Hydrogen:\");\\n\\t\\tSystem.out.println(st + (Temp.boilOfHydrog - Temp.freezOfHydrog + g));\\n\\n\\t}\\n}\\n",
2085 "The program calculates differences between temperature of boiling and freezing of substances.\\n\\nAnswer:\\n\\nWater:\\nthe difference between the boiling point and the freezing point is 100 degrees\\nOxygen:\\nthe difference between the boiling point and the freezing point is 35 degrees\\nHydrogen:\\nthe difference between the boiling point and the freezing point is 6 degrees\\n",
2086 "Water:\\nthe difference between the boiling point and the freezing point is 100 degrees\\nOxygen:\\nthe difference between the boiling point and the freezing point is 35 degrees\\nHydrogen:\\nthe difference between the boiling point and the freezing point is 6 degrees\\n",
2087 "1",
2088 "2",
2089 "1"
2090 ]
2091 },
2092 {
2093 "-name": "question135",
2094 "item": [
2095 "135",
2096 "27",
2097 "import java.util.Scanner;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tSystem.out.println(\"Select verses:\");\\n\\t\\tSystem.out.println(\"1 - if Shakespeare\");\\n\\t\\tSystem.out.println(\"2 - if Byron\");\\n\\t\\tSystem.out.println(\"3 - if Tennyson\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\t\\tswitch (a) {\\n\\t\\tcase 1:\\n\\t\\t\\tSystem.out.println(Vers.shakespeare);\\n\\t\\t\\tbreak;\\n\\t\\tcase 2:\\n\\t\\t\\tSystem.out.println(Vers.byron);\\n\\t\\t\\tbreak;\\n\\t\\tcase 3:\\n\\t\\t\\tSystem.out.println(Vers.tennyson);\\n\\t\\t\\tbreak;\\n\\t\\tdefault:\\n\\t\\t\\tSystem.out.println(Vers.whatElse);\\n\\t\\t\\tbreak;\\n\\t\\t}\\n\\t}\\n}\\n",
2098 "public class Vers {\\n\\n\\tstatic String shakespeare = \"From the besieged Ardea all in post\";\\n\\n\\tstatic String byron = \"I want a hero : an uncommon want\";\\n\\n\\tstatic String tennyson = \"Dear, near and true - no Truer Time himself\";\\n\\n\\tstatic String whatElse = \"Who else do you want?\";\\n\\n}\\n",
2099 "The user selects the author, the program displays the beginning verse of this author.\\n\\nPossible answer:\\n\\nSelect verses:\\n1 - if Shakespeare\\n2 - if Byron\\n3 - if Tennyson\\nType a number:\\n2\\nI want a hero: an uncommon want\\n",
2100 "Select verses:\\n1 - if Shakespeare\\n2 - if Byron\\n3 - if Tennyson\\nType a number:\\n2\\nI want a hero: an uncommon want\\n",
2101 "1",
2102 "1",
2103 "148"
2104 ]
2105 },
2106 {
2107 "-name": "question136",
2108 "item": [
2109 "136",
2110 "28",
2111 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint angleA = (int) (Math.random() * 360) + 1;\\n\\t\\tint angleB = (int) (Math.random() * 360) + 1;\\n\\t\\tint r = (int) (Math.random() * 10) + 1;\\n\\n\\t\\tSystem.out.println(Circ.nameOfCircle);\\n\\t\\tSystem.out.println(\"Radius \" + r);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE CIRCLE=\" + Circ.areaOfC(r));\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + Circ.areaS(angleA, angleB, r));\\n\\t\\tSystem.out.println(\"CIRCUMFERENCE=\" + Circ.lengthOfCircle(r));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + Circ.lengthOfark(angleA, angleB, r));\\n\\n\\t}\\n}\\n",
2112 "public class Circ {\\n\\t// circle sector = PI*r*r*n/360\\n\\t// circle arc length = 2*PI*r*n/360,\\n\\t// where PI-PI, r is the radius, n is the sector angle in degrees\\n\\n\\tstatic String nameOfCircle = \"Circle\";\\n\\n\\tstatic public double areaS(int a, int b, int radius) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = Math.PI * radius * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double lengthOfark(int a, int b, int radius) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = 2 * Math.PI * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double lengthOfCircle(int radius) {\\n\\t\\tdouble area = 2 * Math.PI * radius;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double areaOfC(int radius) {\\n\\t\\tdouble area = Math.PI * radius * radius;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
2113 "The program displays the area of the circle, the area of the sector, the circumference and the arc length. The radius and angles are formed randomly.\\n\\nPossible answer:\\n\\nCircle\\nRadius 5\\nBetween angles 168 and 79\\nAREA OF THE CIRCLE=78.53981633974483\\nAREA PF THE SECTOR=19.416787928436918\\nCIRCUMFERENCE=31.41592653589793\\nARC LENGTH=7.7667151713747655\\n",
2114 "Circle\\nRadius 5\\nBetween angles 168 and 79\\nAREA OF THE CIRCLE=78.53981633974483\\nAREA PF THE SECTOR=19.416787928436918\\nCIRCUMFERENCE=31.41592653589793\\nARC LENGTH=7.7667151713747655\\n",
2115 "1",
2116 "2",
2117 "135"
2118 ]
2119 },
2120 {
2121 "-name": "question137",
2122 "item": [
2123 "137",
2124 "28",
2125 "public class Circ {\\n\\t// circle sector = PI*r*r*n/360\\n\\t// circle arc length = 2*PI*r*n/360,\\n\\t// where PI-PI, r is the radius, n is the sector angle in degrees\\n\\n\\tstatic String nameOfCircle = \"Circle\";\\n\\n\\tstatic public double areaS(int a, int b, int radius) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = Math.PI * radius * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double lengthOfark(int a, int b, int radius) {\\n\\t\\tint angle = Math.abs(a - b);\\n\\t\\tdouble area = 2 * Math.PI * radius * angle / 360;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double lengthOfCircle(int radius) {\\n\\t\\tdouble area = 2 * Math.PI * radius;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public double areaOfC(int radius) {\\n\\t\\tdouble area = Math.PI * radius * radius;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
2126 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint angleA = (int) (Math.random() * 360) + 1;\\n\\t\\tint angleB = (int) (Math.random() * 360) + 1;\\n\\t\\tint r = (int) (Math.random() * 10) + 1;\\n\\n\\t\\tSystem.out.println(Circ.nameOfCircle);\\n\\t\\tSystem.out.println(\"Radius \" + r);\\n\\t\\tSystem.out.println(\"Between angles \" + angleA + \" and \" + angleB);\\n\\t\\tSystem.out.println(\"AREA OF THE CIRCLE=\" + Circ.areaOfC(r));\\n\\t\\tSystem.out.println(\"AREA OF THE SECTOR=\" + Circ.areaS(angleA, angleB, r));\\n\\t\\tSystem.out.println(\"CIRCUMFERENCE=\" + Circ.lengthOfCircle(r));\\n\\t\\tSystem.out.println(\"ARC LENGTH=\" + Circ.lengthOfark(angleA, angleB, r));\\n\\n\\t}\\n}\\n",
2127 "The program displays the area of the circle, the area of the sector, the circumference and the arc length. The radius and angles are formed randomly.\\n\\nPossible answer:\\n\\nCircle\\nRadius 5\\nBetween angles 168 and 79\\nAREA OF THE CIRCLE=78.53981633974483\\nAREA PF THE SECTOR=19.416787928436918\\nCIRCUMFERENCE=31.41592653589793\\nARC LENGTH=7.7667151713747655\\n",
2128 "Circle\\nRadius 5\\nBetween angles 168 and 79\\nAREA OF THE CIRCLE=78.53981633974483\\nAREA PF THE SECTOR=19.416787928436918\\nCIRCUMFERENCE=31.41592653589793\\nARC LENGTH=7.7667151713747655\\n",
2129 "1",
2130 "3",
2131 "45"
2132 ]
2133 },
2134 {
2135 "-name": "question138",
2136 "item": [
2137 "138",
2138 "28",
2139 "public class Car {\\n\\tString name;\\n\\tint maxSpeed;\\n\\tstatic int speedInCity = 60;\\n\\n\\tpublic void distanceOnHighway(int hour) {\\n\\t\\tSystem.out.println(\"distance = \" + maxSpeed * hour + \" km\");\\n\\t}\\n\\n\\tstatic public void distanceInCity(int hour) {\\n\\t\\tSystem.out.println(\"distance = \" + speedInCity * hour + \" km\");\\n\\t}\\n}\\n",
2140 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString strHighway = \" will pass on a highway \";\\n\\t\\tString strCity = \" will pass through a city \";\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.name = \"BMW\";\\n\\t\\tcar1.maxSpeed = 220;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.name = \"Prius\";\\n\\t\\tcar2.maxSpeed = 140;\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.name = \"Hummer\";\\n\\t\\tcar3.maxSpeed = 120;\\n\\n\\t\\tint hours = 3;\\n\\t\\tSystem.out.println(\"The time is 3 hours.\");\\n\\n\\t\\tSystem.out.println(car1.name + strHighway);\\n\\t\\tcar1.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car1.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t\\tSystem.out.println(car2.name + strHighway);\\n\\t\\tcar2.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car2.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t\\tSystem.out.println(car3.name + strHighway);\\n\\t\\tcar3.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car3.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t}\\n}\\n",
2141 "The program displays distances that passing cars in 3 hours on a highway without speed limit and in a city.\\n\\nAnswer:\\n\\nThe time is 3 hours.\\nBMW will pass on a highway\\ndistance = 660 km\\nBMW will pass through a city\\ndistance = 180 km\\nPrius will pass on a highway\\ndistance = 420 km\\nPrius will pass through a city\\ndistance = 180 km\\nHummer will pass on a highway\\ndistance = 360 km\\nHummer will pass through a city\\ndistance = 180 km\\n",
2142 "The time is 3 hours.\\nBMW will pass on a highway\\ndistance = 660 km\\nBMW will pass through a city\\ndistance = 180 km\\nPrius will pass on a highway\\ndistance = 420 km\\nPrius will pass through a city\\ndistance = 180 km\\nHummer will pass on a highway\\ndistance = 360 km\\nHummer will pass through a city\\ndistance = 180 km\\n",
2143 "1",
2144 "2",
2145 "14"
2146 ]
2147 },
2148 {
2149 "-name": "question139",
2150 "item": [
2151 "139",
2152 "28",
2153 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString strHighway = \" will pass on a highway \";\\n\\t\\tString strCity = \" will pass through a city \";\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.name = \"BMW\";\\n\\t\\tcar1.maxSpeed = 220;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.name = \"Prius\";\\n\\t\\tcar2.maxSpeed = 140;\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.name = \"Hummer\";\\n\\t\\tcar3.maxSpeed = 120;\\n\\n\\t\\tint hours = 3;\\n\\t\\tSystem.out.println(\"The time is 3 hours.\");\\n\\n\\t\\tSystem.out.println(car1.name + strHighway);\\n\\t\\tcar1.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car1.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t\\tSystem.out.println(car2.name + strHighway);\\n\\t\\tcar2.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car2.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t\\tSystem.out.println(car3.name + strHighway);\\n\\t\\tcar3.distanceOnHighway(hours);\\n\\t\\tSystem.out.println(car3.name + strCity);\\n\\t\\tCar.distanceInCity(hours);\\n\\n\\t}\\n}\\n",
2154 "public class Car {\\n\\tString name;\\n\\tint maxSpeed;\\n\\tstatic int speedInCity = 60;\\n\\n\\tpublic void distanceOnHighway(int hour) {\\n\\t\\tSystem.out.println(\"distance = \" + maxSpeed * hour + \" km\");\\n\\t}\\n\\n\\tstatic public void distanceInCity(int hour) {\\n\\t\\tSystem.out.println(\"distance = \" + speedInCity * hour + \" km\");\\n\\t}\\n}\\n",
2155 "The program displays distances that passing cars in 3 hours on a highway without speed limit and in a city.\\n\\nAnswer:\\n\\nThe time is 3 hours.\\nBMW will pass on a highway\\ndistance = 660 km\\nBMW will pass through a city\\ndistance = 180 km\\nPrius will pass on a highway\\ndistance = 420 km\\nPrius will pass through a city\\ndistance = 180 km\\nHummer will pass on a highway\\ndistance = 360 km\\nHummer will pass through a city\\ndistance = 180 km\\n",
2156 "The time is 3 hours.\\nBMW will pass on a highway\\ndistance = 660 km\\nBMW will pass through a city\\ndistance = 180 km\\nPrius will pass on a highway\\ndistance = 420 km\\nPrius will pass through a city\\ndistance = 180 km\\nHummer will pass on a highway\\ndistance = 360 km\\nHummer will pass through a city\\ndistance = 180 km\\n",
2157 "1",
2158 "1",
2159 "207"
2160 ]
2161 },
2162 {
2163 "-name": "question140",
2164 "item": [
2165 "140",
2166 "28",
2167 "import java.util.Scanner;\\n\\npublic class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tint a = sc.nextInt();\\n\\t\\tsc.close();\\n\\n\\t\\tUra.ura(a);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tSystem.out.println(\"-----------------\");\\n\\t\\tUra.java(a);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tSystem.out.println(\"-----------------\");\\n\\t\\tUra.iam(a);\\n\\t}\\n}\\n",
2168 "public class Ura {\\n\\tstatic void ura(int n) {\\n\\t\\tfor (int i = 0; i < n; i++) {\\n\\t\\t\\tSystem.out.print(\"Hurray! \");\\n\\t\\t}\\n\\t}\\n\\n\\tstatic void java(int n) {\\n\\t\\tfor (int i = 0; i < n; i++) {\\n\\t\\t\\tSystem.out.print(\"I know Java! \");\\n\\t\\t}\\n\\t}\\n\\n\\tstatic void iam(int n) {\\n\\t\\tfor (int i = 0; i < n; i++) {\\n\\t\\t\\tSystem.out.print(\"I am a good fellow! \");\\n\\t\\t}\\n\\t}\\n}\\n",
2169 "The user enters the number, the program displays the inscription as many times as the user enters.\\n\\nPossible answer:\\n\\nType a number:\\n3\\nHurray! Hurray! Hurray!\\n-----------------\\nI know Java! I know Java! I know Java!\\n-----------------\\nI am a good fellow! I am a good fellow! I am a good fellow!\\n",
2170 "Type a number:\\n3\\nHurray! Hurray! Hurray!\\n-----------------\\nI know Java! I know Java! I know Java!\\n-----------------\\nI am a good fellow! I am a good fellow! I am a good fellow!\\n",
2171 "1",
2172 "1",
2173 "77"
2174 ]
2175 },
2176 {
2177 "-name": "question141",
2178 "item": [
2179 "141",
2180 "29",
2181 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// short - short data type\\n\\t\\tint ai = 5;\\n\\t\\tString as = \"5\";\\n\\t\\tlong al = 5;\\n\\t\\tshort ash = 5;\\n\\t\\tchar ac = '5';\\n\\n\\t\\tClas.degree(ai);\\n\\t\\tClas.degree(as);\\n\\t\\tClas.degree(al);\\n\\t\\tClas.degree(ash);\\n\\t\\tClas.degree(ac);\\n\\n\\t}\\n}\\n",
2182 "public class Clas {\\n\\n\\tpublic static void degree(int a) {\\n\\t\\tSystem.out.println(\"Square of 5 = \" + a * a);\\n\\t}\\n\\n\\tpublic static void degree(String a) {\\n\\t\\tint b = Integer.parseInt(a);\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(long a) {\\n\\t\\tint b = (int) a;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(short a) {\\n\\t\\tint b = (int) a;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(char a) {\\n\\t\\tint b = a - 48;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n}\\n",
2183 "The program displays the square of 5, regardless of types of incoming data.\\n\\nAnswer:\\n\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\n",
2184 "Square of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\n",
2185 "1",
2186 "2",
2187 "30"
2188 ]
2189 },
2190 {
2191 "-name": "question142",
2192 "item": [
2193 "142",
2194 "29",
2195 "public class Clas {\\n\\n\\tpublic static void degree(int a) {\\n\\t\\tSystem.out.println(\"Square of 5 = \" + a * a);\\n\\t}\\n\\n\\tpublic static void degree(String a) {\\n\\t\\tint b = Integer.parseInt(a);\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(long a) {\\n\\t\\tint b = (int) a;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(short a) {\\n\\t\\tint b = (int) a;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n\\n\\tpublic static void degree(char a) {\\n\\t\\tint b = a - 48;\\n\\t\\tSystem.out.println(\"Square of 5 = \" + b * b);\\n\\t}\\n}\\n",
2196 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\t// short - short data type\\n\\t\\tint ai = 5;\\n\\t\\tString as = \"5\";\\n\\t\\tlong al = 5;\\n\\t\\tshort ash = 5;\\n\\t\\tchar ac = '5';\\n\\n\\t\\tClas.degree(ai);\\n\\t\\tClas.degree(as);\\n\\t\\tClas.degree(al);\\n\\t\\tClas.degree(ash);\\n\\t\\tClas.degree(ac);\\n\\n\\t}\\n}\\n",
2197 "The program displays the square of 5, regardless of types of incoming data.\\n\\nAnswer:\\n\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\n",
2198 "Square of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\nSquare of 5 = 25\\n",
2199 "1",
2200 "2",
2201 "5"
2202 ]
2203 },
2204 {
2205 "-name": "question143",
2206 "item": [
2207 "143",
2208 "29",
2209 "public class Man {\\n\\tString name;\\n\\tString town;\\n\\tString street;\\n\\tint house;\\n\\tint korpus;\\n\\tint flat;\\n\\n\\tpublic void address(String t, String st, int h, int k, int fl) {\\n\\t\\tSystem.out.println( h + \" -\" + k + \" \" + st + \" \" + fl + \",\");\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n\\n\\tpublic void address(String t, String st, int h, int fl) {\\n\\t\\tSystem.out.println( h + \" \" + st + \" \" + fl + \",\");\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n\\n\\tpublic void address(String t, String st, int h) {\\n\\t\\tSystem.out.println( h + \" \" + st + \",\" );\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n}\\n",
2210 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Bella\";\\n\\t\\tman1.town = \"Brooklyn\";\\n\\t\\tman1.street = \"Westminster Avenue\";\\n\\t\\tman1.house = 68;\\n\\t\\tman1.korpus = 3;\\n\\t\\tman1.flat = 10;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Peter\";\\n\\t\\tman2.town = \"Los Angeles\";\\n\\t\\tman2.street = \"West Olympic Boulevard\";\\n\\t\\tman2.house = 22;\\n\\t\\tman2.flat = 8;\\n\\n\\t\\tMan man3 = new Man();\\n\\t\\tman3.name = \"Bill\";\\n\\t\\tman3.town = \"Moscow\";\\n\\t\\tman3.street = \"Lenin St.\";\\n\\t\\tman3.house = 111;\\n\\n\\t\\tSystem.out.println(man1.name);\\n\\t\\tman1.address(man1.town, man1.street, man1.house, man1.korpus, man1.flat);\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(man2.name);\\n\\t\\tman2.address(man2.town, man2.street, man2.house, man2.flat);\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(man3.name);\\n\\t\\tman3.address(man3.town, man3.street, man3.house);\\n\\n\\t}\\n}\\n",
2211 "The program displays Bella's address, Peter's address and Bill's address. There is a different number of parts in each address.\\n\\nOutput:\\n\\nBella\\n68 -3 Westminster Avenue 10,\\nBrooklyn.\\n\\nPeter\\n22 West Olympic Boulevard 8,\\nLos Angeles.\\n\\nBill\\n111 Lenin St.,\\nMoscow.\\n",
2212 "Bella\\n68 -3 Westminster Avenue 10,\\nBrooklyn.\\n\\nPeter\\n22 West Olympic Boulevard 8,\\nLos Angeles.\\n\\nBill\\n111 Lenin St.,\\nMoscow.\\n",
2213 "1",
2214 "3",
2215 "36"
2216 ]
2217 },
2218 {
2219 "-name": "question144",
2220 "item": [
2221 "144",
2222 "29",
2223 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Bella\";\\n\\t\\tman1.town = \"Brooklyn\";\\n\\t\\tman1.street = \"Westminster Avenue\";\\n\\t\\tman1.house = 68;\\n\\t\\tman1.korpus = 3;\\n\\t\\tman1.flat = 10;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Peter\";\\n\\t\\tman2.town = \"Los Angeles\";\\n\\t\\tman2.street = \"West Olympic Boulevard\";\\n\\t\\tman2.house = 22;\\n\\t\\tman2.flat = 8;\\n\\n\\t\\tMan man3 = new Man();\\n\\t\\tman3.name = \"Bill\";\\n\\t\\tman3.town = \"Moscow\";\\n\\t\\tman3.street = \"Lenin St.\";\\n\\t\\tman3.house = 111;\\n\\n\\t\\tSystem.out.println(man1.name);\\n\\t\\tman1.address(man1.town, man1.street, man1.house, man1.korpus, man1.flat);\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(man2.name);\\n\\t\\tman2.address(man2.town, man2.street, man2.house, man2.flat);\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(man3.name);\\n\\t\\tman3.address(man3.town, man3.street, man3.house);\\n\\n\\t}\\n}\\n",
2224 "public class Man {\\n\\tString name;\\n\\tString town;\\n\\tString street;\\n\\tint house;\\n\\tint korpus;\\n\\tint flat;\\n\\n\\tpublic void address(String t, String st, int h, int k, int fl) {\\n\\t\\tSystem.out.println( h + \" -\" + k + \" \" + st + \" \" + fl + \",\");\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n\\n\\tpublic void address(String t, String st, int h, int fl) {\\n\\t\\tSystem.out.println( h + \" \" + st + \" \" + fl + \",\");\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n\\n\\tpublic void address(String t, String st, int h) {\\n\\t\\tSystem.out.println( h + \" \" + st + \",\" );\\n\\t\\tSystem.out.println(t + \".\");\\n\\t}\\n}\\n",
2225 "The program displays Bella's address, Peter's address and Bill's address. There is a different number of parts in each address.\\n\\nOutput:\\n\\nBella\\n68 -3 Westminster Avenue 10,\\nBrooklyn.\\n\\nPeter\\n22 West Olympic Boulevard 8,\\nLos Angeles.\\n\\nBill\\n111 Lenin St.,\\nMoscow.\\n",
2226 "Bella\\n68 -3 Westminster Avenue 10,\\nBrooklyn.\\n\\nPeter\\n22 West Olympic Boulevard 8,\\nLos Angeles.\\n\\nBill\\n111 Lenin St.,\\nMoscow.\\n",
2227 "1",
2228 "1",
2229 "198"
2230 ]
2231 },
2232 {
2233 "-name": "question145",
2234 "item": [
2235 "145",
2236 "29",
2237 "public class Circ {\\n\\n\\tString color;\\n\\n\\tpublic double areaOfCircle(int radius) {\\n\\t\\tdouble area = Math.PI * radius * radius;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double areaOfCircle(String radius) {\\n\\t\\tint r = Integer.parseInt(radius);\\n\\t\\tdouble area = Math.PI * r * r;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
2238 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ();\\n\\t\\tcircle1.color = \"Red\";\\n\\t\\tCirc circle2 = new Circ();\\n\\t\\tcircle2.color = \"Yellow\";\\n\\n\\t\\tint radiusInt = 5;\\n\\t\\tString radiusString = \"5\";\\n\\n\\t\\tSystem.out.println(circle1.color + \" circle with an area of\"\\n\\t\\t\\t\\t+ circle1.areaOfCircle(radiusInt) + \" sq cm\");\\n\\t\\tSystem.out.println(circle1.color + \" circle with an area of \"\\n\\t\\t\\t\\t+ circle1.areaOfCircle(radiusString) + \" sq cm\");\\n\\n\\t\\tSystem.out.println(circle2.color + \" circle with an area of \"\\n\\t\\t\\t\\t+ circle2.areaOfCircle(radiusInt) + \" sq cm\");\\n\\t\\tSystem.out.println(circle2.color + \" circle with an area of \"\\n\\t\\t\\t\\t+ circle2.areaOfCircle(radiusString) + \" sq cm\");\\n\\t\\t}\\n}\\n",
2239 "The program displays areas of red and yellow circles with radiuses of 5 cm. Incoming data types are String and int.\\n\\nAnswer:\\n\\nRed circle with an area of 78.53981633974483 sq cm\\nRed circle with an area of 78.53981633974483 sq cm\\nYellow circle with an area of 78.53981633974483 sq cm\\nYellow circle with an area of 78.53981633974483 sq cm\\n",
2240 "Red circle with an area of 78.53981633974483 sq cm\\nRed circle with an area of 78.53981633974483 sq cm\\nYellow circle with an area of 78.53981633974483 sq cm\\nYellow circle with an area of 78.53981633974483 sq cm\\n",
2241 "1",
2242 "2",
2243 "11"
2244 ]
2245 },
2246 {
2247 "-name": "question146",
2248 "item": [
2249 "146",
2250 "30",
2251 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Bella\";\\n\\t\\tHome homeBella = new Home();\\n\\t\\thomeBella.town = \"Brooklyn\";\\n\\t\\thomeBella.str = \"Westminster Avenue\";\\n\\t\\thomeBella.house = 68;\\n\\t\\thomeAndrey.apartment = 10;\\n\\t\\tman1.home = homeBella;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Peter\";\\n\\t\\tHome homePeter = new Home();\\n\\t\\thomePeter.town = \"Los Angeles\";\\n\\t\\thomePeter.str = \"West Olympic Boulevard\";\\n\\t\\thomePeter.house = 22;\\n\\t\\thomePeter.apartment = 8;\\n\\t\\tman2.home = homePeter;\\n\\n\\t\\tSystem.out.println(man1.name + \"'s address is:\");\\n\\t\\tSystem.out.println(man1.home.house + \" \" + man1.home.str + \" \" + man1.home.apartment + \",\");\\n\\t\\tSystem.out.println(man1.home.town);\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(man2.name + \"'s address is:\");\\n\\t\\tSystem.out.println(man2.home.house + \" \" + man2.home.str + \" \" + man2.home.apartment + \",\");\\n\\t\\tSystem.out.println(man2.home.town);\\n",
2252 "public class Home {\\n\\tString town;\\n\\tString str;\\n\\tint house;\\n\\tint apartment;\\n}\\n",
2253 "public class Man {\\n\\tString name;\\n\\tHome home;\\n}\\n",
2254 "The program displays names and addresses.\\n\\nOutput:\\n\\nBella's adress is:\\n68 Westminster Avenue 10,\\nBrooklyn\\n\\nPeter's adress is:\\n22 West Olympic Boulevard 8,\\nLos Angeles\\n",
2255 "Bella's adress is:\\n68 Westminster Avenue 10,\\nBrooklyn\\n\\nPeter's adress is:\\n22 West Olympic Boulevard 8,\\nLos Angeles\\n",
2256 "1",
2257 "3",
2258 "19"
2259 ]
2260 },
2261 {
2262 "-name": "question147",
2263 "item": [
2264 "147",
2265 "30",
2266 "public class Home {\\n\\tString town;\\n\\tString str;\\n\\tint house;\\n\\tint apartment;\\n}\\n",
2267 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Bella\";\\n\\t\\tHome homeBella = new Home();\\n\\t\\thomeBella.town = \"Brooklyn\";\\n\\t\\thomeBella.str = \"Westminster Avenue\";\\n\\t\\thomeBella.house = 68;\\n\\t\\thomeAndrey.apartment = 10;\\n\\t\\tman1.home = homeBella;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Peter\";\\n\\t\\tHome homePeter = new Home();\\n\\t\\thomePeter.town = \"Los Angeles\";\\n\\t\\thomePeter.str = \"West Olympic Boulevard\";\\n\\t\\thomePeter.house = 22;\\n\\t\\thomePeter.apartment = 8;\\n\\t\\tman2.home = homePeter;\\n\\n\\t\\tSystem.out.println(man1.name + \"'s address is:\");\\n\\t\\tSystem.out.println(man1.home.house + \" \" + man1.home.str + \" \" + man1.home.apartment + \",\");\\n\\t\\tSystem.out.println(man1.home.town);\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(man2.name + \"'s address is:\");\\n\\t\\tSystem.out.println(man2.home.house + \" \" + man2.home.str + \" \" + man2.home.apartment + \",\");\\n\\t\\tSystem.out.println(man2.home.town);\\n",
2268 "public class Man {\\n\\tString name;\\n\\tHome home;\\n}\\n",
2269 "The program displays names and addresses.\\n\\nOutput:\\n\\nBella's adress is:\\n68 Westminster Avenue 10,\\nBrooklyn\\n\\nPeter's adress is:\\n22 West Olympic Boulevard 8,\\nLos Angeles\\n",
2270 "Bella's adress is:\\n68 Westminster Avenue 10,\\nBrooklyn\\n\\nPeter's adress is:\\n22 West Olympic Boulevard 8,\\nLos Angeles\\n",
2271 "1",
2272 "1",
2273 "1"
2274 ]
2275 },
2276 {
2277 "-name": "question148",
2278 "item": [
2279 "148",
2280 "30",
2281 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.marka = \"BMW\";\\n\\t\\tcar1.cost = 90000;\\n\\t\\tcar1.maxSpeed = 220;\\n\\t\\tPolicy policy1 = new Policy();\\n\\t\\tpolicy1.ser = \"HK\";\\n\\t\\tpolicy1.nom = 2587413;\\n\\t\\tcar1.policy = policy1;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.marka = \"Toyota\";\\n\\t\\tcar2.cost = 40000;\\n\\t\\tcar2.maxSpeed = 160;\\n\\t\\tPolicy policy2 = new Policy();\\n\\t\\tpolicy2.ser = \"HO\";\\n\\t\\tpolicy2.nom = 6547892;\\n\\t\\tcar2.policy = policy2;\\n\\n\\t\\tSystem.out.println(\"Car \" + car1.marka + \", price \" + car1.cost + \"$,\");\\n\\t\\tSystem.out.println(\"speed \" + car1.maxSpeed + \" km per hour, policy\");\\n\\t\\tSystem.out.println(\"series \" + car1.policy.ser + â„– + car1.policy.nom);\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"Car \" + car2.marka + \", price \" + car2.cost + \"$,\");\\n\\t\\tSystem.out.println(\"speed \" + car2.maxSpeed + \" km per hour, policy\");\\n\\t\\tSystem.out.println(\"series \" + car2.policy.ser + \" â„–\" + car2.policy.nom);\\n\\n\\t}\\n}\\n",
2282 "public class Car {\\n\\tString marka;\\n\\tint maxSpeed;\\n\\tint cost;\\n\\tPolicy policy;\\n}\\n",
2283 "public class Policy {\\n\\tString ser;\\n\\tint nom;\\n}\\n",
2284 "The program displays the model name, price, maximum speed and data about the insurance policy.\\n\\nAnswer:\\n\\nCar BMW, price 90000$,\\nspeed 220 km per hour, policy\\nseries HK â„–2587413\\n\\nCar Toyota, price 40000$,\\nspeed 160 km per hour, policy\\nseries HO â„–6547892\\n",
2285 "Car BMW, price 90000$,\\nspeed 220 km per hour, policy\\nseries HK â„–2587413\\n\\nCar Toyota, price 40000$,\\nspeed 160 km per hour, policy\\nseries HO â„–6547892\\n",
2286 "1",
2287 "3",
2288 "19"
2289 ]
2290 },
2291 {
2292 "-name": "question149",
2293 "item": [
2294 "149",
2295 "30",
2296 "public class Car {\\n\\tString marka;\\n\\tint maxSpeed;\\n\\tint cost;\\n\\tPolicy policy;\\n}\\n",
2297 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.marka = \"BMW\";\\n\\t\\tcar1.cost = 90000;\\n\\t\\tcar1.maxSpeed = 220;\\n\\t\\tPolicy policy1 = new Policy();\\n\\t\\tpolicy1.ser = \"HK\";\\n\\t\\tpolicy1.nom = 2587413;\\n\\t\\tcar1.policy = policy1;\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.marka = \"Toyota\";\\n\\t\\tcar2.cost = 40000;\\n\\t\\tcar2.maxSpeed = 160;\\n\\t\\tPolicy policy2 = new Policy();\\n\\t\\tpolicy2.ser = \"HO\";\\n\\t\\tpolicy2.nom = 6547892;\\n\\t\\tcar2.policy = policy2;\\n\\n\\t\\tSystem.out.println(\"Car \" + car1.marka + \", price \" + car1.cost + \"$,\");\\n\\t\\tSystem.out.println(\"speed \" + car1.maxSpeed + \" km per hour, policy\");\\n\\t\\tSystem.out.println(\"series \" + car1.policy.ser + â„– + car1.policy.nom);\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"Car \" + car2.marka + \", price \" + car2.cost + \"$,\");\\n\\t\\tSystem.out.println(\"speed \" + car2.maxSpeed + \" km per hour, policy\");\\n\\t\\tSystem.out.println(\"series \" + car2.policy.ser + \" â„–\" + car2.policy.nom);\\n\\n\\t}\\n}\\n",
2298 "public class Policy {\\n\\tString ser;\\n\\tint nom;\\n}\\n",
2299 "The program displays the model name, price, maximum speed and data about the insurance policy.\\n\\nAnswer:\\n\\nCar BMW, price 90000$,\\nspeed 220 km per hour, policy\\nseries HK â„–2587413\\n\\nCar Toyota, price 40000$,\\nspeed 160 km per hour, policy\\nseries HO â„–6547892\\n",
2300 "Car BMW, price 90000$,\\nspeed 220 km per hour, policy\\nseries HK â„–2587413\\n\\nCar Toyota, price 40000$,\\nspeed 160 km per hour, policy\\nseries HO â„–6547892\\n",
2301 "1",
2302 "1",
2303 "1"
2304 ]
2305 },
2306 {
2307 "-name": "question150",
2308 "item": [
2309 "150",
2310 "30",
2311 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man();\\n\\t\\tman1.name = \"Andrew\";\\n\\t\\tman1.surname = \"Adamson\";\\n\\t\\tPass passport1 = new Pass();\\n\\t\\tpassport1.nom = 254878;\\n\\t\\tpassport1.ser = \"HK\";\\n\\t\\tman1.pass = passport1;\\n\\n\\t\\tMan man2 = new Man();\\n\\t\\tman2.name = \"Peter\";\\n\\t\\tman2.surname = \"Harrison\";\\n\\t\\tPass passport2 = new Pass();\\n\\t\\tpassport2.nom = 654856;\\n\\t\\tpassport2.ser = \"BC\";\\n\\t\\tman2.pass = passport2;\\n\\n\\t\\tSystem.out.println(man1.name + \" \" + man1.surname + \" passport series\");\\n\\t\\tSystem.out.println(man1.pass.ser + \" â„–\" + man1.pass.nom + \".\");\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tSystem.out.println(man2.name + \" \" + man2.surname + \" passport series\");\\n\\t\\tSystem.out.println(man2.pass.ser + \" â„–\" + man2.pass.nom + \".\");\\n\\t}\\n}\\n",
2312 "public class Man {\\n\\tString name;\\n\\tString surname;\\n\\tPass pass;\\n}\\n",
2313 "public class Pass {\\n\\tString ser;\\n\\tint nom;\\n}\\n",
2314 "The program displays the name and passport details of 2 people.\\n\\nAnswer:\\n\\nAndrew Adamson passport series\\nHK â„–254878.\\n\\nPeter Harrison passport series\\nBC â„–654856.\\n",
2315 "Andrew Adamson passport series\\nHK â„–254878.\\n\\nPeter Harrison passport series\\nBC â„–654856.\\n",
2316 "1",
2317 "3",
2318 "19"
2319 ]
2320 },
2321 {
2322 "-name": "question151",
2323 "item": [
2324 "151",
2325 "31",
2326 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCam camera1 = new Cam();\\n\\t\\tcamera1.location = \"the 31st mile of highway US1,\";\\n\\t\\tcamera1.model = \"Video recording camera Lumia-3000,\";\\n\\t\\tcamera1.permittedSpeed = 90;\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.model = \"Toyota\";\\n\\t\\tcar1.num = \"2376\";\\n\\t\\tcar1.speed = 88;\\n\\t\\tcamera1.violation(car1);\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.model = \"BMW\";\\n\\t\\tcar2.num = \"8788\";\\n\\t\\tcar2.speed = 120;\\n\\t\\tcamera1.violation(car2);\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.model = \"Hummer\";\\n\\t\\tcar3.num = \"0054\";\\n\\t\\tcar3.speed = 101;\\n\\t\\tcamera1.violation(car3);\\n\\n\\t}\\n}\\n",
2327 "public class Cam {\\n\\tString location;\\n\\tString model;\\n\\tint permittedSpeed;\\n\\n\\tpublic void violation(Car car) {\\n\\t\\tif (car.speed > permittedSpeed) {\\n\\t\\t\\tSystem.out.println(\"-----------\");\\n\\t\\t\\tSystem.out.println(model);\\n\\t\\t\\tSystem.out.println(\"set on \" + location);\\n\\t\\t\\tSystem.out.println(\"established speeding-\" + car.model);\\n\\t\\t\\tSystem.out.println(\"state number \" + car.num);\\n\\t\\t\\tSystem.out.println(\"speed \" + car.speed + \".\");\\n\\t\\t\\tSystem.out.println(\"-----------\");\\n\\t\\t\\tSystem.out.println(\" \");\\n\\t\\t}\\n\\t}\\n}\\n",
2328 "public class Car {\\n\\tString model;\\n\\tString num;\\n\\tint speed;\\n}\\n",
2329 "The program displays a message in case of exceeding the speed of the car.\\n\\nAnswer:\\n\\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-BMW\\nstate number 8788\\nspeed 120.\\n-----------\\n \\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-Hummer\\nstate number 0054\\nspeed 101.\\n-----------\\n",
2330 "-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-BMW\\nstate number 8788\\nspeed 120.\\n-----------\\n \\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-Hummer\\nstate number 0054\\nspeed 101.\\n-----------\\n",
2331 "1",
2332 "3",
2333 "19"
2334 ]
2335 },
2336 {
2337 "-name": "question152",
2338 "item": [
2339 "152",
2340 "31",
2341 "public class Cam {\\n\\tString location;\\n\\tString model;\\n\\tint permittedSpeed;\\n\\n\\tpublic void violation(Car car) {\\n\\t\\tif (car.speed > permittedSpeed) {\\n\\t\\t\\tSystem.out.println(\"-----------\");\\n\\t\\t\\tSystem.out.println(model);\\n\\t\\t\\tSystem.out.println(\"set on \" + location);\\n\\t\\t\\tSystem.out.println(\"established speeding-\" + car.model);\\n\\t\\t\\tSystem.out.println(\"state number \" + car.num);\\n\\t\\t\\tSystem.out.println(\"speed \" + car.speed + \".\");\\n\\t\\t\\tSystem.out.println(\"-----------\");\\n\\t\\t\\tSystem.out.println(\" \");\\n\\t\\t}\\n\\t}\\n}\\n",
2342 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCam camera1 = new Cam();\\n\\t\\tcamera1.location = \"the 31st mile of highway US1,\";\\n\\t\\tcamera1.model = \"Video recording camera Lumia-3000,\";\\n\\t\\tcamera1.permittedSpeed = 90;\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.model = \"Toyota\";\\n\\t\\tcar1.num = \"2376\";\\n\\t\\tcar1.speed = 88;\\n\\t\\tcamera1.violation(car1);\\n\\n\\t\\tCar car2 = new Car();\\n\\t\\tcar2.model = \"BMW\";\\n\\t\\tcar2.num = \"8788\";\\n\\t\\tcar2.speed = 120;\\n\\t\\tcamera1.violation(car2);\\n\\n\\t\\tCar car3 = new Car();\\n\\t\\tcar3.model = \"Hummer\";\\n\\t\\tcar3.num = \"0054\";\\n\\t\\tcar3.speed = 101;\\n\\t\\tcamera1.violation(car3);\\n\\n\\t}\\n}\\n",
2343 "public class Car {\\n\\tString model;\\n\\tString num;\\n\\tint speed;\\n}\\n",
2344 "The program displays a message in case of exceeding the speed of the car.\\n\\nAnswer:\\n\\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-BMW\\nstate number 8788\\nspeed 120.\\n-----------\\n \\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-Hummer\\nstate number 0054\\nspeed 101.\\n-----------\\n",
2345 "-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-BMW\\nstate number 8788\\nspeed 120.\\n-----------\\n \\n-----------\\nVideo recording camera Lumia-3000,\\nset on the 31st mile of highway US1,\\nestablished speeding-Hummer\\nstate number 0054\\nspeed 101.\\n-----------\\n",
2346 "1",
2347 "3",
2348 "20"
2349 ]
2350 },
2351 {
2352 "-name": "question153",
2353 "item": [
2354 "153",
2355 "31",
2356 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tValid validator1 = new Valid();\\n\\t\\tvalidator1.location = \"The underground station 'Circular' \";\\n\\t\\tvalidator1.name = \"Validator â„–1\";\\n\\n\\t\\tTick ticket1 = new Tick();\\n\\t\\tticket1.count = 2;\\n\\t\\tvalidator1.open(ticket1);\\n\\n\\t\\tTick ticket2 = new Tick();\\n\\t\\tticket2.count = 10;\\n\\t\\tvalidator1.open(ticket2);\\n\\n\\t\\tvalidator1.open(ticket1);\\n\\n\\t\\tvalidator1.open(ticket1);\\n\\t}\\n}\\n",
2357 "public class Valid {\\n\\n\\tString name;\\n\\tString location;\\n\\n\\tpublic void open(Tick ticket) {\\n\\t\\tif (ticket.count > 0) {\\n\\t\\t\\tSystem.out.println(location + name);\\n\\t\\t\\tSystem.out.println(\"DOORS OPEN\");\\n\\t\\t\\tticket.count = ticket.count - 1;\\n\\t\\t\\tSystem.out.println(\"The remaining number of trips is \" + ticket.count);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(Tick.nameOfTicket + \" NOT VALID\");\\n\\t\\t\\tSystem.out.println(\"The number of trips is \" + ticket.count);\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
2358 "public class Tick {\\n\\tstatic String nameOfTicket = \"Ticket \";\\n\\tint count;\\n}\\n",
2359 "The program imitates the operation of the validator in underground: skips if travel was paid, and does not skip, when travel was not paid. After each pass the validator writes off 1 trip.\\n\\nAnswer:\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 1\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 9\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 0\\n\\nTicket is NOT VALID\\nThe number of trips is 0\\n",
2360 "The underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 1\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 9\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 0\\n\\nTicket is NOT VALID\\nThe number of trips is 0\\n",
2361 "1",
2362 "1",
2363 "73"
2364 ]
2365 },
2366 {
2367 "-name": "question154",
2368 "item": [
2369 "154",
2370 "31",
2371 "public class Valid {\\n\\n\\tString name;\\n\\tString location;\\n\\n\\tpublic void open(Tick ticket) {\\n\\t\\tif (ticket.count > 0) {\\n\\t\\t\\tSystem.out.println(location + name);\\n\\t\\t\\tSystem.out.println(\"DOORS OPEN\");\\n\\t\\t\\tticket.count = ticket.count - 1;\\n\\t\\t\\tSystem.out.println(\"The remaining number of trips is \" + ticket.count);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(Tick.nameOfTicket + \" NOT VALID\");\\n\\t\\t\\tSystem.out.println(\"The number of trips is \" + ticket.count);\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
2372 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tValid validator1 = new Valid();\\n\\t\\tvalidator1.location = \"The underground station 'Circular' \";\\n\\t\\tvalidator1.name = \"Validator â„–1\";\\n\\n\\t\\tTick ticket1 = new Tick();\\n\\t\\tticket1.count = 2;\\n\\t\\tvalidator1.open(ticket1);\\n\\n\\t\\tTick ticket2 = new Tick();\\n\\t\\tticket2.count = 10;\\n\\t\\tvalidator1.open(ticket2);\\n\\n\\t\\tvalidator1.open(ticket1);\\n\\n\\t\\tvalidator1.open(ticket1);\\n\\t}\\n}\\n",
2373 "public class Tick {\\n\\tstatic String nameOfTicket = \"Ticket \";\\n\\tint count;\\n}\\n",
2374 "The program imitates the operation of the validator in underground: skips if travel was paid, and does not skip, when travel was not paid. After each pass the validator writes off 1 trip.\\n\\nAnswer:\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 1\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 9\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 0\\n\\nTicket is NOT VALID\\nThe number of trips is 0\\n",
2375 "The underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 1\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 9\\n\\nThe underground station 'Circular' Validator â„–1\\nDOORS OPEN\\nThe remaining number of trips is 0\\n\\nTicket is NOT VALID\\nThe number of trips is 0\\n",
2376 "1",
2377 "3",
2378 "16"
2379 ]
2380 },
2381 {
2382 "-name": "question155",
2383 "item": [
2384 "155",
2385 "31",
2386 "public class Rob {\\n\\tstatic String nameOfCola = \"Vending machine Cola \";\\n\\tstatic int costOfCola = 40;\\n\\tint count = 0;\\n\\n\\tpublic void selling(Bill bill) {\\n\\t\\tSystem.out.println(\"You paid \" + bill.cost + \" cents\");\\n\\t\\tcount = count + bill.cost;\\n\\t\\tif (count >= costOfCola) {\\n\\t\\t\\tSystem.out.println(nameOfCola + \"gives one bottle of cola\");\\n\\t\\t\\tSystem.out.println(nameOfCola + \"gives change \" + (count - costOfCola) + \" cents\");\\n\\t\\t\\tcount = 0;\\n\\t\\t\\tSystem.out.println(\" \");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Not enough money, add more.\");\\n\\t\\t}\\n\\t}\\n}\\n",
2387 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tRob robot1 = new Rob();\\n\\n\\t\\tBill bill1 = new Bill();\\n\\t\\tbill1.cost = 20;\\n\\t\\trobot1.selling(bill1);\\n\\n\\t\\tBill bill2 = new Bill();\\n\\t\\tbill2.cost = 30;\\n\\t\\trobot1.selling(bill2);\\n\\n\\t\\tBill bill3 = new Bill();\\n\\t\\tbill3.cost = 50;\\n\\t\\trobot1.selling(bill3);\\n\\n\\t\\tBill bill4 = new Bill();\\n\\t\\tbill4.cost = 40;\\n\\t\\trobot1.selling(bill4);\\n\\t}\\n}\\n",
2388 "public class Bill {\\n\\tint cost;\\n}\\n",
2389 "The program simulates the operation of vending machine Cola. Machine takes money, gives change and cola, or reports that not enough money.\\n\\nAnswer:\\n\\nYou paid 20 cents\\nNot enough money, add more.\\nYou paid 30 cents.\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 10 cents\\n\\nYou paid 50 cents\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 10 cents\\n\\nYou paid 40 cents\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 0 cents\\n",
2390 "You paid 20 cents\\nNot enough money, add more.\\nYou paid 30 cents.\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 10 cents\\n\\nYou paid 50 cents\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 10 cents\\n\\nYou paid 40 cents\\nVending machine Cola gives one bottle of cola\\nVending machine Cola gives change 0 cents\\n",
2391 "1",
2392 "3",
2393 "31"
2394 ]
2395 },
2396 {
2397 "-name": "question156",
2398 "item": [
2399 "156",
2400 "32",
2401 "public class Cube {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\tString color;\\n\\n\\tCube() {\\n\\t\\twidth = 10;\\n\\t\\theight = 10;\\n\\t\\tlength = 10;\\n\\t\\tcolor = \"Red\";\\n\\t}\\n\\n\\tpublic void outCube() {\\n\\t\\tSystem.out.println(\"Width:\" + width);\\n\\t\\tSystem.out.println(\"Height:\" + height);\\n\\t\\tSystem.out.println(\"Length:\" + length);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2402 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCube cube1 = new Cube();\\n\\t\\tCube cube2 = new Cube();\\n\\t\\tCube cube3 = new Cube();\\n\\n\\t\\tcube1.outCube();\\n\\t\\tcube2.outCube();\\n\\t\\tcube3.outCube();\\n\\t}\\n}\\n",
2403 "The program prints three identical objects. The characteristics are given in the constructor.\\n\\nAnswer:\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n",
2404 "Width:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n",
2405 "1",
2406 "2",
2407 "25"
2408 ]
2409 },
2410 {
2411 "-name": "question157",
2412 "item": [
2413 "157",
2414 "32",
2415 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCube cube1 = new Cube();\\n\\t\\tCube cube2 = new Cube();\\n\\t\\tCube cube3 = new Cube();\\n\\n\\t\\tcube1.outCube();\\n\\t\\tcube2.outCube();\\n\\t\\tcube3.outCube();\\n\\t}\\n}\\n",
2416 "public class Cube {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\tString color;\\n\\n\\tCube() {\\n\\t\\twidth = 10;\\n\\t\\theight = 10;\\n\\t\\tlength = 10;\\n\\t\\tcolor = \"Red\";\\n\\t}\\n\\n\\tpublic void outCube() {\\n\\t\\tSystem.out.println(\"Width:\" + width);\\n\\t\\tSystem.out.println(\"Height:\" + height);\\n\\t\\tSystem.out.println(\"Length:\" + length);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2417 "The program prints three identical objects. The characteristics are given in the constructor.\\n\\nAnswer:\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n",
2418 "Width:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n\\nWidth:10\\nHeight:10\\nLength:10\\nColor:Red\\n",
2419 "1",
2420 "1",
2421 "18"
2422 ]
2423 },
2424 {
2425 "-name": "question158",
2426 "item": [
2427 "158",
2428 "32",
2429 "public class Cube {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\tString color;\\n\\n\\tCube() {\\n\\t\\twidth = 10;\\n\\t\\theight = 20;\\n\\t}\\n\\n\\tpublic void outCube() {\\n\\t\\tSystem.out.println(\"Width:\" + width);\\n\\t\\tSystem.out.println(\"Height:\" + height);\\n\\t\\tSystem.out.println(\"Length:\" + length);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2430 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCube cube1 = new Cube();\\n\\t\\tCube cube2 = new Cube();\\n\\t\\tCube cube3 = new Cube();\\n\\n\\t\\tcube1.outCube();\\n\\t\\tcube2.outCube();\\n\\t\\tcube3.outCube();\\n\\t}\\n}\\n",
2431 "The program prints three identical objects. Characteristics are given in the constructor. If int variables are not specified in the constructor , the default constructor assigns 0. If String variables are not specified , the default constructor assigns null.\\n\\nAnswer:\\n\\nWidth:10\\nHeight:20\\nLength:0\\nColor:null\\n\\nWidth:10\\nHeight:20\\nLength:0\\nColor:null\\n\\nWidth:10\\nHeight:20\\nLength:0\\nColor:null\\n",
2432 "Width:10\\nHeight:20\\nLength:0\\nColor:null\\n\\nWidth:10\\nHeight:20\\nLength:0\\nColor:null\\n\\nWidth:10\\nHeight:20\\nLength:0\\nColor:null\\n",
2433 "1",
2434 "2",
2435 "25"
2436 ]
2437 },
2438 {
2439 "-name": "question159",
2440 "item": [
2441 "159",
2442 "32",
2443 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tCar car2 = new Car();\\n\\t\\tCar car3 = new Car();\\n\\n\\t\\tcar1.outCar();\\n\\t\\tcar2.outCar();\\n\\t\\tcar3.outCar();\\n\\t}\\n}\\n",
2444 "public class Car {\\n\\tString name;\\n\\tint speed;\\n\\tint cost;\\n\\tdouble fuelConsumption;\\n\\tString color;\\n\\n\\tCar() {\\n\\t\\tfuelConsumption = 9.7;\\n\\t\\tname = \"BMW\";\\n\\t\\tspeed = 220;\\n\\t}\\n\\n\\tpublic void outCar() {\\n\\t\\tSystem.out.println(\"Brand:\" + name);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + speed);\\n\\t\\tSystem.out.println(\"Price:\" + cost);\\n\\t\\tSystem.out.println(\"Fuel consumption:\" + fuelConsumption);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2445 "The program displays characteristics of the three identical cars that have arrived in the salon. If specifications are not set, the int variables are assigned 0, String variables are assigned null.\\n\\nAnswer:\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n",
2446 "Brand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n",
2447 "1",
2448 "1",
2449 "20"
2450 ]
2451 },
2452 {
2453 "-name": "question160",
2454 "item": [
2455 "160",
2456 "32",
2457 "public class Car {\\n\\tString name;\\n\\tint speed;\\n\\tint cost;\\n\\tdouble fuelConsumption;\\n\\tString color;\\n\\n\\tCar() {\\n\\t\\tfuelConsumption = 9.7;\\n\\t\\tname = \"BMW\";\\n\\t\\tspeed = 220;\\n\\t}\\n\\n\\tpublic void outCar() {\\n\\t\\tSystem.out.println(\"Brand:\" + name);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + speed);\\n\\t\\tSystem.out.println(\"Price:\" + cost);\\n\\t\\tSystem.out.println(\"Fuel consumption:\" + fuelConsumption);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2458 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tCar car2 = new Car();\\n\\t\\tCar car3 = new Car();\\n\\n\\t\\tcar1.outCar();\\n\\t\\tcar2.outCar();\\n\\t\\tcar3.outCar();\\n\\t}\\n}\\n",
2459 "The program displays characteristics of the three identical cars that have arrived in the salon. If specifications are not set, the int variables are assigned 0, String variables are assigned null.\\n\\nAnswer:\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n",
2460 "Brand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n\\nBrand:BMW\\nMaximum speed:220\\nPrice:0\\nFuel consumption:9.7\\nColor:null\\n",
2461 "1",
2462 "2",
2463 "46"
2464 ]
2465 },
2466 {
2467 "-name": "question161",
2468 "item": [
2469 "161",
2470 "33",
2471 "public class Cube {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\tString color;\\n\\n\\tCube(int w, int h, int l, String c) {\\n\\t\\twidth = w;\\n\\t\\theight = h;\\n\\t\\tlength = l;\\n\\t\\tcolor = c;\\n\\t}\\n\\n\\tpublic void outCube() {\\n\\t\\tSystem.out.println(\"Width:\" + width);\\n\\t\\tSystem.out.println(\"Height:\" + height);\\n\\t\\tSystem.out.println(\"Length:\" + length);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2472 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCube cube1 = new Cube(10, 20, 30, \"Red\");\\n\\t\\tCube cube2 = new Cube(100, 100, 100, \"Blue\");\\n\\t\\tCube cube3 = new Cube(2, 1, 1, \"Green\");\\n\\n\\t\\tcube1.outCube();\\n\\t\\tcube2.outCube();\\n\\t\\tcube3.outCube();\\n\\t}\\n}\\n",
2473 "The program displays three objects with different characteristics, specified in the constructor.\\n\\nAnswer:\\n\\nWidth:10\\nHeight:20\\nLength:30\\nColor:Red\\n\\nWidth:100\\nHeight:100\\nLength:100\\nColor:Blue\\n\\nWidth:2\\nHeight:1\\nLength:1\\nColor:Green\\n",
2474 "Width:10\\nHeight:20\\nLength:30\\nColor:Red\\n\\nWidth:100\\nHeight:100\\nLength:100\\nColor:Blue\\n\\nWidth:2\\nHeight:1\\nLength:1\\nColor:Green\\n",
2475 "1",
2476 "2",
2477 "25"
2478 ]
2479 },
2480 {
2481 "-name": "question162",
2482 "item": [
2483 "162",
2484 "33",
2485 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCube cube1 = new Cube(10, 20, 30, \"Red\");\\n\\t\\tCube cube2 = new Cube(100, 100, 100, \"Blue\");\\n\\t\\tCube cube3 = new Cube(2, 1, 1, \"Green\");\\n\\n\\t\\tcube1.outCube();\\n\\t\\tcube2.outCube();\\n\\t\\tcube3.outCube();\\n\\t}\\n}\\n",
2486 "public class Cube {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\tString color;\\n\\n\\tCube(int w, int h, int l, String c) {\\n\\t\\twidth = w;\\n\\t\\theight = h;\\n\\t\\tlength = l;\\n\\t\\tcolor = c;\\n\\t}\\n\\n\\tpublic void outCube() {\\n\\t\\tSystem.out.println(\"Width:\" + width);\\n\\t\\tSystem.out.println(\"Height:\" + height);\\n\\t\\tSystem.out.println(\"Length:\" + length);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2487 "The program displays three objects with different characteristics, specified in the constructor.\\n\\nAnswer:\\n\\nWidth:10\\nHeight:20\\nLength:30\\nColor:Red\\n\\nWidth:100\\nHeight:100\\nLength:100\\nColor:Blue\\n\\nWidth:2\\nHeight:1\\nLength:1\\nColor:Green\\n",
2488 "Width:10\\nHeight:20\\nLength:30\\nColor:Red\\n\\nWidth:100\\nHeight:100\\nLength:100\\nColor:Blue\\n\\nWidth:2\\nHeight:1\\nLength:1\\nColor:Green\\n",
2489 "1",
2490 "2",
2491 "18"
2492 ]
2493 },
2494 {
2495 "-name": "question163",
2496 "item": [
2497 "163",
2498 "33",
2499 "public class Car {\\n\\tString name;\\n\\tint speed;\\n\\tint cost;\\n\\tint fuelConsumption;\\n\\tString color;\\n\\n\\tCar(String name, int speed, int cost, int fuelConsumption, String color) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.cost = cost;\\n\\t\\tthis.fuelConsumption = fuelConsumption;\\n\\t\\tthis.color = color;\\n\\t}\\n\\n\\tpublic void outCar() {\\n\\t\\tSystem.out.println(\"Brand:\" + name);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + speed);\\n\\t\\tSystem.out.println(\"Price:\" + cost);\\n\\t\\tSystem.out.println(\"Fuel consumption:\" + fuelConsumption);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2500 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car(\"BMW-5\", 240, 110000, 9, \"Black\");\\n\\t\\tCar car2 = new Car(\"BMW-3\", 180, 40000, 7, \"Red\");\\n\\t\\tCar car3 = new Car(\"BMW-6\", 243, 140000, 11, \"Black\");\\n\\n\\t\\tcar1.outCar();\\n\\t\\tcar2.outCar();\\n\\t\\tcar3.outCar();\\n\\t}\\n}\\n",
2501 "The program displays characteristics of three different cars that have arrived in the salon. Information about vehicles is specified in the constructor.\\n\\nAnswer:\\n\\nBrand:BMW-5\\nMaximum speed:240\\nPrice:110000\\nFuel consumption:9\\nColor:Black\\n\\nBrand:BMW-3\\nMaximum speed:180\\nPrice:40000\\nFuel consumption:7\\nColor:Red\\n\\nBrand:BMW-6\\nMaximum speed:243\\nPrice:140000\\nFuel consumption:11\\nColor:Black\\n",
2502 "Brand:BMW-5\\nMaximum speed:240\\nPrice:110000\\nFuel consumption:9\\nColor:Black\\n\\nBrand:BMW-3\\nMaximum speed:180\\nPrice:40000\\nFuel consumption:7\\nColor:Red\\n\\nBrand:BMW-6\\nMaximum speed:243\\nPrice:140000\\nFuel consumption:11\\nColor:Black\\n",
2503 "1",
2504 "3",
2505 "30"
2506 ]
2507 },
2508 {
2509 "-name": "question164",
2510 "item": [
2511 "164",
2512 "33",
2513 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car(\"BMW-5\", 240, 110000, 9, \"Black\");\\n\\t\\tCar car2 = new Car(\"BMW-3\", 180, 40000, 7, \"Red\");\\n\\t\\tCar car3 = new Car(\"BMW-6\", 243, 140000, 11, \"Black\");\\n\\n\\t\\tcar1.outCar();\\n\\t\\tcar2.outCar();\\n\\t\\tcar3.outCar();\\n\\t}\\n}\\n",
2514 "public class Car {\\n\\tString name;\\n\\tint speed;\\n\\tint cost;\\n\\tint fuelConsumption;\\n\\tString color;\\n\\n\\tCar(String name, int speed, int cost, int fuelConsumption, String color) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.cost = cost;\\n\\t\\tthis.fuelConsumption = fuelConsumption;\\n\\t\\tthis.color = color;\\n\\t}\\n\\n\\tpublic void outCar() {\\n\\t\\tSystem.out.println(\"Brand:\" + name);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + speed);\\n\\t\\tSystem.out.println(\"Price:\" + cost);\\n\\t\\tSystem.out.println(\"Fuel consumption:\" + fuelConsumption);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2515 "The program displays characteristics of three different cars that have arrived in the salon.Information about vehicles is specified in the constructor.\\n\\nAnswer:\\n\\nBrand:BMW-5\\nMaximum speed:240\\nPrice:110000\\nFuel consumption:9\\nColor:Black\\n\\nBrand:BMW-3\\nMaximum speed:180\\nPrice:40000\\nFuel consumption:7\\nColor:Red\\n\\nBrand:BMW-6\\nMaximum speed:243\\nPrice:140000\\nFuel consumption:11\\nColor:Black\\n",
2516 "Brand:BMW-5\\nMaximum speed:240\\nPrice:110000\\nFuel consumption:9\\nColor:Black\\n\\nBrand:BMW-3\\nMaximum speed:180\\nPrice:40000\\nFuel consumption:7\\nColor:Red\\n\\nBrand:BMW-6\\nMaximum speed:243\\nPrice:140000\\nFuel consumption:11\\nColor:Black\\n",
2517 "1",
2518 "2",
2519 "20"
2520 ]
2521 },
2522 {
2523 "-name": "question165",
2524 "item": [
2525 "165",
2526 "33",
2527 "public class Car {\\n\\tString name;\\n\\tint speed;\\n\\tint cost;\\n\\tint fuelConsumption;\\n\\tString color;\\n\\n\\tCar(String name, int speed, int cost, int fuelConsumption, String color) {\\n\\t\\tname = name;\\n\\t\\tspeed = speed;\\n\\t\\tcost = cost;\\n\\t\\tfuelConsumption = fuelConsumption;\\n\\t\\tcolor = color;\\n\\t}\\n\\n\\tpublic void outCar() {\\n\\t\\tSystem.out.println(\"Brand:\" + name);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + speed);\\n\\t\\tSystem.out.println(\"Price:\" + cost);\\n\\t\\tSystem.out.println(\"Fuel consumption:\" + fuelConsumption);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2528 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car(\"BMW-5\", 240, 110000, 9, \"Black\");\\n\\t\\tCar car2 = new Car(\"BMW-3\", 180, 40000, 7, \"Red\");\\n\\t\\tCar car3 = new Car(\"BMW-6\", 243, 140000, 11, \"Black\");\\n\\n\\t\\tcar1.outCar();\\n\\t\\tcar2.outCar();\\n\\t\\tcar3.outCar();\\n\\t}\\n}\\n",
2529 "The program tries to output characteristics of three different cars admitted to the salon. However, it is not possible, because the keyword 'this' is not used in the constructor.\\n\\nAnswer:\\n\\nBrand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n\\nBrand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n\\nbrand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n",
2530 "Brand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n\\nBrand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n\\nbrand:null\\nMaximum speed:0\\nPrice:0\\nFuel consumption:0\\nColor:null\\n",
2531 "1",
2532 "2",
2533 "30"
2534 ]
2535 },
2536 {
2537 "-name": "question166",
2538 "item": [
2539 "166",
2540 "34",
2541 "public class License {\\n\\n\\tString name;\\n\\tString surname;\\n\\tString serie;\\n\\tint numer;\\n\\n\\tLicense(String name, String surname, String serie, int numer) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.serie = serie;\\n\\t\\tthis.numer = numer;\\n\\t}\\n\\n\\tLicense(String name, String surname, int numer) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.numer = numer;\\n\\t}\\n\\n\\tLicense(String name, String surname) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t}\\n\\tpublic void passOut() {\\n\\t\\tSystem.out.println(\"Driver's license\");\\n\\t\\tSystem.out.println(\"Name: \" + name);\\n\\t\\tSystem.out.println(\"Surname: \" + surname);\\n\\t\\tSystem.out.println(\"Serie: \" + serie);\\n\\t\\tSystem.out.println(\"â„–: \" + numer);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n\\n",
2542 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tLicense license1 = new License(\"Peter\", \"Kirk\", \"MH\", 258741);\\n\\t\\tlicense1.passOut();\\n\\t\\tLicense license2 = new License(\"Bill\", \"Harrison\", 654128);\\n\\t\\tlicense2.passOut();\\n\\t\\tLicense license3 = new License(\"Bella\", \"Davidson\");\\n\\t\\tlicense3.passOut();\\n\\t}\\n}\\n",
2543 "The program displays information about driver's licenses. Some information is absent.\\n\\nOutput:\\n\\nDriver's license\\nName: Peter\\nSurname: Kirk\\nSerie: MH\\nâ„–: 258741\\n\\nDriver's license\\nName: Bill\\nSurname: Harrison\\nSerie: null\\nâ„–: 654128\\n\\nDriver's license\\nName: Bella\\nSurname: Davidson\\nSerie: null\\nâ„–: 0\\n",
2544 "Driver's license\\nName: Peter\\nSurname: Kirk\\nSerie: MH\\nâ„–: 258741\\n\\nDriver's license\\nName: Bill\\nSurname: Harrison\\nSerie: null\\nâ„–: 654128\\n\\nDriver's license\\nName: Bella\\nSurname: Davidson\\nSerie: null\\nâ„–: 0\\n",
2545 "1",
2546 "3",
2547 "25"
2548 ]
2549 },
2550 {
2551 "-name": "question167",
2552 "item": [
2553 "167",
2554 "34",
2555 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tLicense license1 = new License(\"Peter\", \"Kirk\", \"MH\", 258741);\\n\\t\\tlicense1.passOut();\\n\\t\\tLicense license2 = new License(\"Bill\", \"Harrison\", 654128);\\n\\t\\tlicense2.passOut();\\n\\t\\tLicense license3 = new License(\"Bella\", \"Davidson\");\\n\\t\\tlicense3.passOut();\\n\\t\\t}\\n}\\n",
2556 "public class License {\\n\\n\\tString name;\\n\\tString surname;\\n\\tString serie;\\n\\tint numer;\\n\\n\\tLicense(String name, String surname, String serie, int numer) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.serie = serie;\\n\\t\\tthis.numer = numer;\\n\\t}\\n\\n\\tLicense(String name, String surname, int numer) {\\n\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.numer = numer;\\n\\t}\\n\\n\\tLicense(String name, String surname) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.surname = surname;\\n\\t}\\n\\tpublic void passOut() {\\n\\t\\tSystem.out.println(\"Driver's license\");\\n\\t\\tSystem.out.println(\"Name: \" + name);\\n\\t\\tSystem.out.println(\"Surname: \" + surname);\\n\\t\\tSystem.out.println(\"Serie: \" + serie);\\n\\t\\tSystem.out.println(\"â„–: \" + numer);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n\\n",
2557 "The program displays information about driver's licenses. Some information is absent.\\n\\nOutput:\\n\\nDriver's license\\nName: Peter\\nSurname: Kirk\\nSerie: MH\\nâ„–: 258741\\n\\nDriver's license\\nName: Bill\\nSurname: Harrison\\nSerie: null\\nâ„–: 654128\\n\\nDriver's license\\nName: Bella\\nSurname: Davidson\\nSerie: null\\nâ„–: 0\\n",
2558 "Driver's license\\nName: Peter\\nSurname: Kirk\\nSerie: MH\\nâ„–: 258741\\n\\nDriver's license\\nName: Bill\\nSurname: Harrison\\nSerie: null\\nâ„–: 654128\\n\\nDriver's license\\nName: Bella\\nSurname: Davidson\\nSerie: null\\nâ„–: 0\\n",
2559 "1",
2560 "2",
2561 "19"
2562 ]
2563 },
2564 {
2565 "-name": "question168",
2566 "item": [
2567 "168",
2568 "34",
2569 "public class Trip {\\n\\tint bus;\\n\\tint hotel;\\n\\tint breakfast;\\n\\tint tour1;\\n\\tint tour2;\\n\\tint shopping;\\n\\n\\tTrip(int bus, int hotel, int breakfast, int tour1, int tour2, int shopping) {\\n\\t\\tthis.bus = bus;\\n\\t\\tthis.hotel = hotel;\\n\\t\\tthis.breakfast = breakfast;\\n\\t\\tthis.tour1 = tour1;\\n\\t\\tthis.tour2 = tour2;\\n\\t\\tthis.shopping = shopping;\\n\\t}\\n\\n\\tTrip(int bus, int hotel, int breakfast, int tour1, int shopping) {\\n\\t\\tthis.bus = bus;\\n\\t\\tthis.hotel = hotel;\\n\\t\\tthis.breakfast = breakfast;\\n\\t\\tthis.tour1 = tour1;\\n\\t\\tthis.shopping = shopping;\\n\\t}\\n\\n\\tTrip(int bus, int hotel, int breakfast, int shopping) {\\n\\t\\tthis.bus = bus;\\n\\t\\tthis.hotel = hotel;\\n\\t\\tthis.breakfast = breakfast;\\n\\t\\tthis.shopping = shopping;\\n\\t}\\n\\n\\tTrip(int bus, int hotel, int shopping) {\\n\\t\\tthis.bus = bus;\\n\\t\\tthis.hotel = hotel;\\n\\t\\tthis.shopping = shopping;\\n\\t}\\n\\n\\tpublic void costOftrip() {\\n\\t\\tSystem.out.println(\"Travel:\" + bus + \" dol.\");\\n\\t\\tSystem.out.println(\"Hotel:\" + hotel + \" dol.\");\\n\\t\\tSystem.out.println(\"Breakfast:\" + breakfast + \" dol.\");\\n\\t\\tSystem.out.println(\"Excursion1:\" + tour1 + \" dol.\");\\n\\t\\tSystem.out.println(\"Excursion2:\" + tour2 + \" dol.\");\\n\\t\\tSystem.out.println(\"Shopping:\" + shopping + \" dol.\");\\n\\t\\tSystem.out.println(\"THE TOTAL COST:\" + (shopping + hotel+ breakfast+ tour1+ tour2+bus)+ \" dol.\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2570 "public class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTrip trip1 = new Trip(150, 220, 45, 40, 35, 0);\\n\\t\\tTrip trip2 = new Trip(150, 220, 45, 40, 0);\\n\\t\\tTrip trip3 = new Trip(150, 220, 45, 0);\\n\\t\\tTrip trip4 = new Trip(150, 220, 0);\\n\\n\\t\\ttrip1.costOftrip();\\n\\t\\ttrip2.costOftrip();\\n\\t\\ttrip3.costOftrip();\\n\\t\\ttrip4.costOftrip();\\n\\t}\\n}\\n",
2571 "The program displays options of the trip and the total cost of the trip. During the trip, you can abandon breakfast and excursions.\\n\\nOutput:\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:40 dol.\\nExcursion2:35 dol.\\nShopping:0 руб.\\nTHE TOTAL COST:490 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:40 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:455 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:0 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:415 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:0 dol.\\nExcursion1:0 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:370 dol.\\n",
2572 "Travel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:40 dol.\\nExcursion2:35 dol.\\nShopping:0 руб.\\nTHE TOTAL COST:490 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:40 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:455 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:45 dol.\\nExcursion1:0 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:415 dol.\\n\\nTravel:150 dol.\\nHotel:220 dol.\\nBreakfast:0 dol.\\nExcursion1:0 dol.\\nExcursion2:0 dol.\\nShopping:0 dol.\\nTHE TOTAL COST:370 dol.\\n",
2573 "1",
2574 "3",
2575 "35"
2576 ]
2577 },
2578 {
2579 "-name": "question169",
2580 "item": [
2581 "169",
2582 "34",
2583 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tAdre address1 = new Adre(\"Alice\", \"Brooklyn\", \"Milk St.\", 68, 10);\\n\\t\\taddress1.address();\\n\\t\\tAdre address2 = new Adre(\"Mike\", \"Washington\", \"Federal St.\", 22);\\n\\t\\taddress2.address();\\n\\t\\tAdre address3 = new Adre(\"Alex\", \"Atlantic Avenue\", 111);\\n\\t\\taddress3.address();\\n\\t}\\n}\\n",
2584 "public class Adre {\\n\\tString name;\\n\\tString town;\\n\\tString street;\\n\\tint house;\\n\\tint apartment;\\n\\n\\tAdre(String n, String t, String st, int h, int ap) {\\n\\t\\tname = n;\\n\\t\\ttown = t;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t\\tapartment = ap;\\n\\t}\\n\\n\\tAdre(String n, String t, String st, int h) {\\n\\t\\tname = n;\\n\\t\\ttown = t;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t}\\n\\n\\tAdre(String n, String st, int h) {\\n\\t\\tname = n;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t}\\n\\n\\tpublic void address() {\\n\\t\\tSystem.out.println(name);\\n\\t\\tSystem.out.println(house + \" \" + street + \" \" + apartment);\\n\\t\\tSystem.out.println(town + \".\");\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
2585 "The program displays information about people and their addresses. Some addresses are not full.\\n\\nOutput:\\n\\nAlice\\n68 Milk St. 10\\nBrooklyn.\\n\\nMike\\n22 Federal St. 0\\nWashington.\\n\\nAlex\\n111 Atlantic Avenue 0\\nnull.\\n",
2586 "Alice\\n68 Milk St. 10\\nBrooklyn.\\n\\nMike\\n22 Federal St. 0\\nWashington.\\n\\nAlex\\n111 Atlantic Avenue 0\\nnull.\\n",
2587 "1",
2588 "2",
2589 "19"
2590 ]
2591 },
2592 {
2593 "-name": "question170",
2594 "item": [
2595 "170",
2596 "34",
2597 "public class Adre {\\n\\tString name;\\n\\tString town;\\n\\tString street;\\n\\tint house;\\n\\tint apartment;\\n\\n\\tAdre(String n, String t, String st, int h, int ap) {\\n\\t\\tname = n;\\n\\t\\ttown = t;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t\\tapartment = ap;\\n\\t}\\n\\n\\tAdre(String n, String t, String st, int h) {\\n\\t\\tname = n;\\n\\t\\ttown = t;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t}\\n\\n\\tAdre(String n, String st, int h) {\\n\\t\\tname = n;\\n\\t\\tstreet = st;\\n\\t\\thouse = h;\\n\\t}\\n\\n\\tpublic void address() {\\n\\t\\tSystem.out.println(name);\\n\\t\\tSystem.out.println(house + \" \" + street + \" \" + apartment);\\n\\t\\tSystem.out.println(town + \".\");\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
2598 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tAdre address1 = new Adre(\"Alice\", \"Brooklyn\", \"Milk St.\", 68, 10);\\n\\t\\taddress1.address();\\n\\t\\tAdre address2 = new Adre(\"Mike\", \"Washington\", \"Federal St.\", 22);\\n\\t\\taddress2.address();\\n\\t\\tAdre address3 = new Adre(\"Alex\", \"Atlantic Avenue\", 111);\\n\\t\\taddress3.address();\\n\\t}\\n}\\n",
2599 "The program displays information about people and their addresses. Some addresses are not full.\\n\\nOutput:\\n\\nAlice\\n68 Milk St. 10\\nBrooklyn.\\n\\nMike\\n22 Federal St. 0\\nWashington.\\n\\nAlex\\n111 Atlantic Avenue 0\\nnull.\\n",
2600 "Alice\\n68 Milk St. 10\\nBrooklyn.\\n\\nMike\\n22 Federal St. 0\\nWashington.\\n\\nAlex\\n111 Atlantic Avenue 0\\nnull.\\n",
2601 "1",
2602 "3",
2603 "30"
2604 ]
2605 },
2606 {
2607 "-name": "question171",
2608 "item": [
2609 "171",
2610 "35",
2611 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\n\\tBox(int width, int height, int length) {\\n\\t\\tthis.width = width;\\n\\t\\tthis.height = height;\\n\\t\\tthis.length = length;\\n\\t}\\n\\n\\tpublic void increase1(int width, int height, int length) {\\n\\t\\tSystem.out.println(\"\");\\n\\t\\twidth = width * 2;\\n\\t\\theight = height * 2;\\n\\t\\tlength = length * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by value:\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n\\n\\tpublic void increase2(Box box) {\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tbox.width = box.width * 2;\\n\\t\\tbox.height = box.height * 2;\\n\\t\\tbox.length = box.length * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by reference:\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2612 "public class Task {\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box(10, 20, 30);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\n\\t\\tbox1.increase1(box1.width, box1.height, box1.length);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\n\\t\\tbox1.increase2(box1);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\t}\\n}\\n",
2613 "The program uses two methods (increase1 and increase2) to increase the size of the box. In the first case, the argument is passed by value, in the second case the argument is passed by reference.\\nIn the first case, the original object is not changed, in the second case the original object is changed.\\n\\n\\nOutput:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by value:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by reference:\\n\\nWidth:20\\nHeight:40\\nLength:60\\n",
2614 "Width:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by value:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by reference:\\n\\nWidth:20\\nHeight:40\\nLength:60\\n",
2615 "1",
2616 "2",
2617 "65"
2618 ]
2619 },
2620 {
2621 "-name": "question172",
2622 "item": [
2623 "172",
2624 "35",
2625 "public class Task {\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box(10, 20, 30);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\n\\t\\tbox1.increase1(box1.width, box1.height, box1.length);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\n\\t\\tbox1.increase2(box1);\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.width);\\n\\t\\tSystem.out.println(\"Height:\" + box1.height);\\n\\t\\tSystem.out.println(\"Length:\" + box1.length);\\n\\t}\\n}\\n",
2626 "public class Box {\\n\\tint width;\\n\\tint height;\\n\\tint length;\\n\\n\\tBox(int width, int height, int length) {\\n\\t\\tthis.width = width;\\n\\t\\tthis.height = height;\\n\\t\\tthis.length = length;\\n\\t}\\n\\n\\tpublic void increase1(int width, int height, int length) {\\n\\t\\tSystem.out.println(\"\");\\n\\t\\twidth = width * 2;\\n\\t\\theight = height * 2;\\n\\t\\tlength = length * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by value:\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n\\n\\tpublic void increase2(Box box) {\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tbox.width = box.width * 2;\\n\\t\\tbox.height = box.height * 2;\\n\\t\\tbox.lenght = box.length * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by reference:\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2627 "The program uses two methods (increase1 and increase2) to increase the size of the box. In the first case, the argument is passed by value, in the second case the argument is passed by reference.\\nIn the first case, the original object is not changed, in the second case the original object is changed.\\n\\n\\nOutput:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by value:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by reference:\\n\\nWidth:20\\nHeight:40\\nLength:60\\n",
2628 "Width:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by value:\\n\\nWidth:10\\nHeight:20\\nLength:30\\n\\nThe argument is passed by reference:\\n\\nWidth:20\\nHeight:40\\nLength:60\\n",
2629 "1",
2630 "1",
2631 "84"
2632 ]
2633 },
2634 {
2635 "-name": "question173",
2636 "item": [
2637 "173",
2638 "35",
2639 "public class Car {\\n\\tString name;\\n\\tdouble cost;\\n\\tint speed;\\n\\tint wheel;\\n\\n\\tCar(String name, double cost, int speed, int wheel) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.wheel = wheel;\\n\\n\\t}\\n\\n\\tpublic void carDreem1(String name, double cost, int speed, int wheel) {\\n\\t\\tname = \"DreemCar\";\\n\\t\\tcost = cost / 2;\\n\\t\\tspeed = speed * 2;\\n\\t\\twheel = 6;\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The argument is passed by value:\");\\n\\t}\\n\\n\\tpublic void carDreem2(Car car) {\\n\\t\\tcar.name = \"DreemCar\";\\n\\t\\tcar.cost = cost / 2;\\n\\t\\tcar.speed = speed * 2;\\n\\t\\tcar.wheel = 6;\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The argument is passed by reference:\");\\n\\t}\\n}\\n",
2640 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car(\"BMW\", 80000.0, 220, 4);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\n\\t\\tcar1.carDreem1(car1.name, car1.cost, car1.speed, car1.wheel);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\n\\t\\tcar1.carDreem2(car1);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\t}\\n}\\n",
2641 "The program uses 2 methods (carDreem1 and carDreem2) to change settings of cars. In the first case, the argument is passed by value, in the second case the argument is passed by reference.\\nIn the first case, original characteristics of cars are not changed, in the second case original characteristics of cars are changed.\\n\\n\\nOutput:\\n\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by value:\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by reference:\\nBrand:DreemCar\\nPrice:40000.0\\nSpeed:440\\nThe number of wheels:6\\n",
2642 "Brand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by value:\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by reference:\\nBrand:DreemCar\\nPrice:40000.0\\nSpeed:440\\nThe number of wheels:6\\n",
2643 "1",
2644 "3",
2645 "83"
2646 ]
2647 },
2648 {
2649 "-name": "question174",
2650 "item": [
2651 "174",
2652 "35",
2653 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car(\"BMW\", 80000.0, 220, 4);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\n\\t\\tcar1.carDreem1(car1.name, car1.cost, car1.speed, car1.wheel);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\n\\t\\tcar1.carDreem2(car1);\\n\\n\\t\\tSystem.out.println(\"Brand:\" + car1.name);\\n\\t\\tSystem.out.println(\"Price:\" + car1.cost);\\n\\t\\tSystem.out.println(\"Speed:\" + car1.speed);\\n\\t\\tSystem.out.println(\"The number of wheels:\" + car1.wheel);\\n\\t}\\n}\\n",
2654 "public class Car {\\n\\tString name;\\n\\tdouble cost;\\n\\tint speed;\\n\\tint wheel;\\n\\n\\tCar(String name, double cost, int speed, int wheel) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.wheel = wheel;\\n\\n\\t}\\n\\n\\tpublic void carDreem1(String name, double cost, int speed, int wheel) {\\n\\t\\tname = \"DreemCar\";\\n\\t\\tcost = cost / 2;\\n\\t\\tspeed = speed * 2;\\n\\t\\twheel = 6;\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The argument is passed by value:\");\\n\\t}\\n\\n\\tpublic void carDreem2(Car car) {\\n\\t\\tcar.name = \"DreemCar\";\\n\\t\\tcar.cost = cost / 2;\\n\\t\\tcar.speed = speed * 2;\\n\\t\\tcar.wheel = 6;\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The argument is passed by reference:\");\\n\\t}\\n}\\n",
2655 "The program uses 2 methods (carDreem1 and carDreem2) to change settings of cars. In the first case, the argument is passed by value, in the second case the argument is passed by reference.\\nIn the first case, original characteristics of cars are not changed, in the second case original characteristics of cars are changed.\\n\\n\\nOutput:\\n\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by value:\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by reference:\\nBrand:DreemCar\\nPrice:40000.0\\nSpeed:440\\nThe number of wheels:6\\n",
2656 "Brand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by value:\\nBrand:BMW\\nPrice:80000.0\\nSpeed:220\\nThe number of wheels:4\\n\\nThe argument is passed by reference:\\nBrand:DreemCar\\nPrice:40000.0\\nSpeed:440\\nThe number of wheels:6\\n",
2657 "1",
2658 "2",
2659 "108"
2660 ]
2661 },
2662 {
2663 "-name": "question175",
2664 "item": [
2665 "175",
2666 "35",
2667 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint[] a = { 1, 2, 3 };\\n\\t\\tSystem.out.println(\"\" + a[0] + a[1] + a[2]);\\n\\t\\tMain.increase1(a[0], a[1], a[2]);\\n\\t\\tSystem.out.println(\"\" + a[0] + a[1] + a[2]);\\n\\t\\tMain.increase2(a);\\n\\t\\tSystem.out.println(\"\" + a[0] + a[1] + a[2]);\\n\\t}\\n\\n\\tpublic static void increase1(int a0, int a1, int a2) {\\n\\t\\ta0 = a0 * 2;\\n\\t\\ta1 = a1 * 2;\\n\\t\\ta2 = a2 * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by value: \" + a0 + a1 + a2);\\n\\t}\\n\\n\\tpublic static void increase2(int[] a) {\\n\\t\\ta[0] = a[0] * 2;\\n\\t\\ta[1] = a[1] * 2;\\n\\t\\ta[2] = a[2] * 2;\\n\\t\\tSystem.out.println(\"The argument is passed by reference: \" + a[0] + a[1] + a[2]);\\n\\t}\\n}\\n",
2668 "The program uses two methods (increase1 and increase2) for work with data. In the first case, the argument is passed by value, in the second case the argument is passed by reference. In the first case, the array is not changed, in the second case the array is changed.\\n\\nOutput:\\n\\n123\\nThe argument is passed by value: 246\\n123\\nThe argument is passed by reference: 246\\n246\\n",
2669 "123\\nThe argument is passed by value: 246\\n123\\nThe argument is passed by reference: 246\\n246\\n",
2670 "1",
2671 "3",
2672 "36"
2673 ]
2674 },
2675 {
2676 "-name": "question176",
2677 "item": [
2678 "176",
2679 "36",
2680 "public class Home {\\n\\n\\tprivate String town;\\n\\tprivate String street;\\n\\tprivate int house;\\n\\tprivate int flat;\\n\\n\\tpublic void setTown(String t) {\\n\\t\\tthis.town = t;\\n\\t}\\n\\n\\tpublic String getTown() {\\n\\t\\treturn town;\\n\\t}\\n\\n\\tpublic void setStreet(String s) {\\n\\t\\tthis.street = s;\\n\\t}\\n\\n\\tpublic String getStreet() {\\n\\t\\treturn street;\\n\\t}\\n\\n\\tpublic void setHouse(int h) {\\n\\t\\tthis.house = h;\\n\\t}\\n\\n\\tpublic int getHouse() {\\n\\t\\treturn house;\\n\\t}\\n\\n\\tpublic void setFlat(int f) {\\n\\t\\tthis.flat = f;\\n\\t}\\n\\n\\tpublic int getFlat() {\\n\\t\\treturn flat;\\n\\t}\\n}\\n",
2681 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHome home1 = new Home();\\n\\t\\thome1.setTown(\"Los Angeles\");\\n\\t\\thome1.setStreet(\"Williams St.\");\\n\\t\\thome1.setHouse(3);\\n\\t\\thome1.setFlat(23);\\n\\n\\t\\tSystem.out.print(home1.getHouse() + \" \");\\n\\t\\tSystem.out.print(home1.getStreet() + \" \");\\n\\t\\tSystem.out.println(home1.getFlat());\\n\\t\\tSystem.out.println(home1.getTown());\\n\\t}\\n}\\n",
2682 "The program displays addresses. The program ueses getters and setters.\\n\\nOutput:\\n\\n3 Williams St. 23\\nLos Angeles\\n\\n",
2683 "3 Williams St. 23\\nLos Angeles\\n",
2684 "1",
2685 "3",
2686 "30"
2687 ]
2688 },
2689 {
2690 "-name": "question177",
2691 "item": [
2692 "177",
2693 "36",
2694 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHome home1 = new Home();\\n\\t\\thome1.setTown(\"Los Angeles\");\\n\\t\\thome1.setStreet(\"Williams St.\");\\n\\t\\thome1.setHouse(3);\\n\\t\\thome1.setFlat(23);\\n\\n\\t\\tSystem.out.print(home1.getHouse() + \" \");\\n\\t\\tSystem.out.print(home1.getStreet() + \" \");\\n\\t\\tSystem.out.println(home1.getFlat());\\n\\t\\tSystem.out.println(home1.getTown());\\n\\t}\\n}\\n",
2695 "public class Home {\\n\\n\\tprivate String town;\\n\\tprivate String street;\\n\\tprivate int house;\\n\\tprivate int flat;\\n\\n\\tpublic void setTown(String t) {\\n\\t\\tthis.town = t;\\n\\t}\\n\\n\\tpublic String getTown() {\\n\\t\\treturn town;\\n\\t}\\n\\n\\tpublic void setStreet(String s) {\\n\\t\\tthis.street = s;\\n\\t}\\n\\n\\tpublic String getStreet() {\\n\\t\\treturn street;\\n\\t}\\n\\n\\tpublic void setHouse(int h) {\\n\\t\\tthis.house = h;\\n\\t}\\n\\n\\tpublic int getHouse() {\\n\\t\\treturn house;\\n\\t}\\n\\n\\tpublic void setFlat(int f) {\\n\\t\\tthis.flat = f;\\n\\t}\\n\\n\\tpublic int getFlat() {\\n\\t\\treturn flat;\\n\\t}\\n}\\n",
2696 "The program displays addresses. The program ueses getters and setters.\\n\\nOutput:\\n\\n3 Williams St. 23\\nLos Angeles\\n\\n",
2697 "3 Williams St. 23\\nLos Angeles\\n",
2698 "1",
2699 "2",
2700 "30"
2701 ]
2702 },
2703 {
2704 "-name": "question178",
2705 "item": [
2706 "178",
2707 "36",
2708 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tWash washingMachine1 = new Wash();\\n\\t\\twashingMachine1.setName(\"Bosch\");\\n\\t\\twashingMachine1.setColor(\"White\");\\n\\t\\twashingMachine1.setType(\"front\");\\n\\t\\twashingMachine1.setСentrifuge(1000);\\n\\t\\twashingMachine1.setProg(22);\\n\\n\\t\\tSystem.out.println(\"Washing machine:\" + washingMachine1.getName());\\n\\t\\tSystem.out.println(\"Color:\" + washingMachine1.getColor());\\n\\t\\tSystem.out.println(\"Type:\" + washingMachine1.getType());\\n\\t\\tSystem.out.println(\"Сentrifuge:\" + washingMaÑhine1.getCentrifuge());\\n\\t\\tSystem.out.println(\"Programmes:\" + washingMachine1.getProg());\\n\\t}\\n}\\n",
2709 "public class Wash {\\n\\n\\tprivate String name;\\n\\tprivate String color;\\n\\tprivate String type;\\n\\tprivate int centrifuge;\\n\\tprivate int prog;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String getColor() {\\n\\t\\treturn color;\\n\\t}\\n\\n\\tpublic void setColor(String color) {\\n\\t\\tthis.color = color;\\n\\t}\\n\\n\\tpublic String getType() {\\n\\t\\treturn type;\\n\\t}\\n\\n\\tpublic void setType(String type) {\\n\\t\\tthis.type = type;\\n\\t}\\n\\n\\tpublic int getCentrifuge() {\\n\\t\\treturn centrifuge;\\n\\t}\\n\\n\\tpublic void setCentrifuge(int centrifuge) {\\n\\t\\tthis.centrifuge = centrifuge;\\n\\t}\\n\\n\\tpublic int getProg() {\\n\\t\\treturn prog;\\n\\t}\\n\\n\\tpublic void setProg(int prog) {\\n\\t\\tthis.prog = prog;\\n\\t}\\n}\\n",
2710 "The program displays characteristics of the washing machine. The program uses getters and setters.\\n\\nOutput:\\n\\nWashing machine:Bosch\\nColor:White\\nType:front\\nСentrifuge:1000\\nProgrammes:22\\n",
2711 "Washing machine:Bosch\\nColor:White\\nType:front\\nСentrifuge:1000\\nProgrammes:22\\n",
2712 "1",
2713 "2",
2714 "29"
2715 ]
2716 },
2717 {
2718 "-name": "question179",
2719 "item": [
2720 "179",
2721 "36",
2722 "public class Wash {\\n\\n\\tprivate String name;\\n\\tprivate String color;\\n\\tprivate String type;\\n\\tprivate int centrifuge;\\n\\tprivate int prog;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String getColor() {\\n\\t\\treturn color;\\n\\t}\\n\\n\\tpublic void setColor(String color) {\\n\\t\\tthis.color = color;\\n\\t}\\n\\n\\tpublic String getType() {\\n\\t\\treturn type;\\n\\t}\\n\\n\\tpublic void setType(String type) {\\n\\t\\tthis.type = type;\\n\\t}\\n\\n\\tpublic int getCentrifuge() {\\n\\t\\treturn centrifuge;\\n\\t}\\n\\n\\tpublic void setCentrifuge(int centrifuge) {\\n\\t\\tthis.centrifuge = centrifuge;\\n\\t}\\n\\n\\tpublic int getProg() {\\n\\t\\treturn prog;\\n\\t}\\n\\n\\tpublic void setProg(int prog) {\\n\\t\\tthis.prog = prog;\\n\\t}\\n}\\n",
2723 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tWash washingMachine1 = new Wash();\\n\\t\\twashingMachine1.setName(\"Bosch\");\\n\\t\\twashingMachine1.setColor(\"White\");\\n\\t\\twashingMachine1.setType(\"front\");\\n\\t\\twashingMachine1.setСentrifuge(1000);\\n\\t\\twashingMachine1.setProg(22);\\n\\n\\t\\tSystem.out.println(\"Washing machine:\" + washingMachine1.getName());\\n\\t\\tSystem.out.println(\"Color:\" + washingMachine1.getColor());\\n\\t\\tSystem.out.println(\"Type:\" + washingMachine1.getType());\\n\\t\\tSystem.out.println(\"Сentrifuge:\" + washingMaÑhine1.getCentrifuge());\\n\\t\\tSystem.out.println(\"Programmes:\" + washingMachine1.getProg());\\n\\t}\\n}\\n",
2724 "The program displays characteristics of the washing machine. The program uses getters and setters.\\n\\nOutput:\\n\\nWashing machine:Bosch\\nColor:White\\nType:front\\nСentrifuge:1000\\nProgrammes:22\\n",
2725 "Washing machine:Bosch\\nColor:White\\nType:front\\nСentrifuge:1000\\nProgrammes:22\\n",
2726 "1",
2727 "2",
2728 "35"
2729 ]
2730 },
2731 {
2732 "-name": "question180",
2733 "item": [
2734 "180",
2735 "36",
2736 "public class Box {\\n\\tprivate int width;\\n\\tprivate int height;\\n\\tprivate int length;\\n\\tprivate String colors;\\n\\n\\tpublic int getWidth() {\\n\\t\\treturn width;\\n\\t}\\n\\n\\tpublic void setWidth(int width) {\\n\\t\\tthis.width = width;\\n\\t}\\n\\n\\tpublic int getHeight() {\\n\\t\\treturn height;\\n\\t}\\n\\n\\tpublic void setHeight(int height) {\\n\\t\\tthis.height = height;\\n\\t}\\n\\n\\tpublic String getColors() {\\n\\t\\treturn colors;\\n\\t}\\n\\n\\tpublic void setColors(String colors) {\\n\\t\\tthis.colors = colors;\\n\\t}\\n\\n\\tpublic int getLength() {\\n\\t\\treturn length;\\n\\t}\\n\\n\\tpublic void setLength(int length) {\\n\\t\\tthis.length = length;\\n\\t}\\n}\\n",
2737 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tBox box1 = new Box();\\n\\t\\tbox1.setWidth(10);\\n\\t\\tbox1.setHeight(20);\\n\\t\\tbox1.setLength(30);\\n\\t\\tbox1.setColors(\"Red\");\\n\\n\\t\\tSystem.out.println(\"Width:\" + box1.getWidth());\\n\\t\\tSystem.out.println(\"Height:\" + box1.getHeight());\\n\\t\\tSystem.out.println(\"Length:\" + box1.getLength());\\n\\t\\tSystem.out.println(\"Color:\" + box1.getColors());\\n\\n\\t}\\n}\\n",
2738 "The program displays characteristics of the dox. The program uses getters and setters.\\n\\nOutput:\\n\\nWidth:10\\nHeight:20\\nLength:30\\nColor:Red\\n\\n",
2739 "Width:10\\nHeight:20\\nLength:30\\nColor:Red\\n",
2740 "1",
2741 "2",
2742 "30"
2743 ]
2744 },
2745 {
2746 "-name": "question181",
2747 "item": [
2748 "181",
2749 "37",
2750 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tSystem.out.println(\"Monday\");\\n\\t\\tMain.vivod(32, 68, 54, 23, 100);\\n\\t\\tSystem.out.println(\"Tuesday\");\\n\\t\\tMain.vivod(45, 6, 32);\\n\\t\\tSystem.out.println(\"Wednesday\");\\n\\t\\tMain.vivod(79, 65, 22, 11);\\n\\t}\\n\\n\\tpublic static void vivod(int ... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tint countNoViolation = 0;\\n\\t\\tfor (int i : v) {\\n\\t\\t\\tif (i > 60) {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is a violation of traffic rules\");\\n\\t\\t\\t\\tcountViolation = countViolation + 1;\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is not a violation of traffic rules\");\\n\\t\\t\\t\\tcountNoViolation = countNoViolation + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.print(\"without violations: \" + countNoViolation);\\n\\t\\tSystem.out.println(\", violations: \" + countViolation);\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
2751 "Several cars passing along a country road in a day. The speed limit of this road is 60 km per hour. The program detects violations and counts the number of violations for first three days of the week.\\n\\nOutput:\\n\\nMonday\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n23 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 3, violations: 2\\n\\nTuesday\\n45 it is not a violation of traffic rules\\n6 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 3, violations: 0\\n\\nWednesday\\n79 it is a violation of traffic rules\\n65 it is a violation of traffic rules\\n22 it is not a violation of traffic rules\\n11 it is not a violation of traffic rules\\nwithout violations: 2, violations: 2\\n",
2752 "Monday\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n23 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 3, violations: 2\\n\\nTuesday\\n45 it is not a violation of traffic rules\\n6 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 3, violations: 0\\n\\nWednesday\\n79 it is a violation of traffic rules\\n65 it is a violation of traffic rules\\n22 it is not a violation of traffic rules\\n11 it is not a violation of traffic rules\\nwithout violations: 2, violations: 2\\n",
2753 "1",
2754 "3",
2755 "31"
2756 ]
2757 },
2758 {
2759 "-name": "question182",
2760 "item": [
2761 "182",
2762 "37",
2763 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tTruc truck1 = new Truc(\"Volvo\", 20);\\n\\t\\tTruc truck2 = new Truc(\"Mercedes\", 22);\\n\\t\\tTruc truck3 = new Truc(\"MAN\", 19);\\n\\t\\tTruc truck4 = new Truc(\"Volvo\", 10);\\n\\t\\tTruc truck5 = new Truc(\"KIA\", 30);\\n\\n\\t\\tSystem.out.println(\"1 day\");\\n\\t\\tcountCargo(truck1, truck3, truck2, truck5, truck4);\\n\\t\\tSystem.out.println(\"2 day\");\\n\\t\\tcountCargo(truck1, truck5, truck4, truck4);\\n\\t\\tSystem.out.println(\"3 day\");\\n\\t\\tcountCargo(truck5, truck1);\\n\\t}\\n\\n\\tpublic static void countCargo(Truc... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Per day \" + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2764 "public class Truc {\\n\\tprivate String name;\\n\\tprivate int capacity;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getCapacity() {\\n\\t\\treturn capacity;\\n\\t}\\n\\nruc(String name, int capacity) {\\n\\t\\tthis.capacity = capacity;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
2765 "Trucks carry sand to the plant. Trucks have different capacity and make different number of transportations. The program fixes each transportation and counts mass of sand, carried by trucks per day.\\n\\nOutput:\\n1 day\\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nPer day 101 tons\\n\\n2 day\\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nPer day 70 tons\\n\\n3 day\\nKIA 30 tons\\nVolvo 20 tons\\nPer day 50 tons\\n",
2766 "1 day\\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nPer day 101 tons\\n\\n2 day\\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nPer day 70 tons\\n\\n3 day\\nKIA 30 tons\\nVolvo 20 tons\\nPer day 50 tons\\n",
2767 "1",
2768 "3",
2769 "104"
2770 ]
2771 },
2772 {
2773 "-name": "question183",
2774 "item": [
2775 "183",
2776 "37",
2777 "public class Truc {\\n\\tprivate String name;\\n\\tprivate int capacity;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getCapacity() {\\n\\t\\treturn capacity;\\n\\t}\\n\\n\\tTruc(String name, int capacity) {\\n\\t\\tthis.capacity = capacity;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
2778 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tTruc truck1 = new Truc(\"Volvo\", 20);\\n\\t\\tTruc truck2 = new Truc(\"Mercedes\", 22);\\n\\t\\tTruc truck3 = new Truc(\"MAN\", 19);\\n\\t\\tTruc truck4 = new Truc(\"Volvo\", 10);\\n\\t\\tTruc truck5 = new Truc(\"KIA\", 30);\\n\\n\\t\\tSystem.out.println(\"1 day\");\\n\\t\\tcountCargo(truck1, truck3, truck2, truck5, truck4);\\n\\t\\tSystem.out.println(\"2 day\");\\n\\t\\tcountCargo(truck1, truck5, truck4, truck4);\\n\\t\\tSystem.out.println(\"3 day\");\\n\\t\\tcountCargo(truck5, truck1);\\n\\t}\\n\\n\\tpublic static void countCargo(Truc... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Per day \" + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2779 "Trucks carry sand to the plant. Trucks have different capacity and make different number of transportations. The program fixes each transportation and counts mass of sand, carried by trucks per day.\\n\\nOutput:\\n1 day\\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nPer day 101 tons\\n\\n2 day\\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nPer day 70 tons\\n\\n3 day\\nKIA 30 tons\\nVolvo 20 tons\\nPer day 50 tons\\n",
2780 "1 day\\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nPer day 101 tons\\n\\n2 day\\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nPer day 70 tons\\n\\n3 day\\nKIA 30 tons\\nVolvo 20 tons\\nPer day 50 tons\\n",
2781 "1",
2782 "2",
2783 "1"
2784 ]
2785 },
2786 {
2787 "-name": "question184",
2788 "item": [
2789 "184",
2790 "37",
2791 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tSystem.out.println(\"The hockey player counts his goals made during workouts:\");\\n\\t\\tSystem.out.println(\"Monday\");\\n\\t\\tSystem.out.println(Task.hokkey(true, false, false, false));\\n\\t\\tSystem.out.println(\"Tuesday\");\\n\\t\\tSystem.out.println(Task.hokkey(false, false, true, false, true, false));\\n\\t\\tSystem.out.println(\"Wednesday\");\\n\\t\\tSystem.out.println(Task.hokkey());\\n\\t\\tSystem.out.println(\"Thursday\");\\n\\t\\tSystem.out.println(Task.hokkey(false, false, true, false));\\n\\t\\tSystem.out.println(\"Friday\");\\n\\t\\tSystem.out.println(Task.hokkey(false));\\n\\t\\tSystem.out.println(\"Saturday\");\\n\\t\\tSystem.out.println(Task.hokkey(true, false, false, false, false));\\n\\t}\\n\\n\\tpublic static int hokkey(boolean... v) {\\n\\t\\tint countBullits = 0;\\n\\t\\tfor (boolean a : v) {\\n\\t\\t\\tif (a) {\\n\\t\\t\\t\\tcountBullits = countBullits + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn countBullits;\\n\\t}\\n}\\n",
2792 "Hockey player makes some shoots during workouts. The program counts the number of goals by day of week.\\n\\nOutput:\\n\\nThe hockey player counts his goals made during workouts:\\nMonday 1\\nTuesday 2\\nWednesday 0\\nThursday 1\\nFriday 0\\nSaturday 1\\n",
2793 "The hockey player counts his goals made during workouts:\\nMonday 1\\nTuesday 2\\nWednesday 0\\nThursday 1\\nFriday 0\\nSaturday 1\\n",
2794 "1",
2795 "2",
2796 "246"
2797 ]
2798 },
2799 {
2800 "-name": "question185",
2801 "item": [
2802 "185",
2803 "37",
2804 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMan man1 = new Man(\"Peter\", 41);\\n\\t\\tMan man2 = new Man(\"John\", 38);\\n\\t\\tMan man3 = new Man(\"Bill\", 33);\\n\\t\\tMan man4 = new Man(\"Mike\", 42);\\n\\t\\tMan man5 = new Man(\"Alex\", 39);\\n\\t\\tMan man6 = new Man(\"Andrew\", 36);\\n\\n\\t\\tchampionship(man1, man2, man3, man4, man5, man6);\\n\\t\\tchampionship(man3, man4, man5, man6);\\n\\t\\tchampionship(man1, man4, man5, man2);\\n\\t}\\n\\n\\tpublic static void championship(Man... v) {\\n\\t\\tint weight33 = 0;\\n\\t\\tint weight37 = 0;\\n\\t\\tint weight41 = 0;\\n\\t\\tint weight50 = 0;\\n\\t\\tfor (Man i : v) {\\n\\t\\t\\tif (i.getWeight() <= 33) {\\n\\t\\t\\t\\tweight33 = weight33 + 1;\\n\\t\\t\\t} else if (i.getWeight() <= 37) {\\n\\t\\t\\t\\tweight37 = weight37 + 1;\\n\\t\\t\\t} else if (i.getWeight() <= 41) {\\n\\t\\t\\t\\tweight41 = weight41 + 1;\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tweight50 = weight50 + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Up to 33 kg\" + weight33);\\n\\t\\tSystem.out.println(\"Up to 37 kg \" + weight37);\\n\\t\\tSystem.out.println(\"Up to 41 kg \" + weight41);\\n\\t\\tSystem.out.println(\"Up to 50 kg \" + weight50);\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2805 "public class Man {\\n\\tprivate String name;\\n\\tprivate int weight;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tMan(String name, int weight) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.weight = weight;\\n\\t}\\n}\\n",
2806 "Sport teams take part in three competitions. Different number of participants will arrive at every event. The program splits participants into different weight categories.\\n\\nOutput:\\n\\nUp to 33 kg 1\\nUp to 37 kg 1\\nUp to 41 kg 3\\nUp to 50 kg 1\\n\\nUp to 33 kg 1\\nUp to 37 kg 1\\nUp to 41 kg 1\\nUp to 50 kg 1\\n\\nUp to 33 kg 0\\nUp to 37 kg 0\\nUp to 41 kg 3\\nUp to 50 kg 1\\n",
2807 "Up to 33 kg 1\\nUp to 37 kg 1\\nUp to 41 kg 3\\nUp to 50 kg 1\\n\\nUp to 33 kg 1\\nUp to 37 kg 1\\nUp to 41 kg 1\\nUp to 50 kg 1\\n\\nUp to 33 kg 0\\nUp to 37 kg 0\\nUp to 41 kg 3\\nUp to 50 kg 1\\n",
2808 "1",
2809 "3",
2810 "153"
2811 ]
2812 },
2813 {
2814 "-name": "question186",
2815 "item": [
2816 "186",
2817 "38",
2818 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tTruc truck1 = new Truc(\"Volvo\", 20);\\n\\t\\tTruc truck2 = new Truc(\"Mercedes\", 22);\\n\\t\\tTruc truck3 = new Truc(\"MAN\", 19);\\n\\t\\tTruc truck4 = new Truc(\"Volvo\", 10);\\n\\t\\tTruc truck5 = new Truc(\"KIA\", 30);\\n\\n\\t\\tcountCargo(\"Brick factory \",\"Monday \",truck1, truck3, truck2, truck5, truck4);\\n\\t\\tcountCargo(\"Brick factory \",\"Tuesday \",truck1, truck5, truck4, truck4);\\n\\t\\tcountCargo(\"Brick factory \",\"Wednesday \",truck5, truck1);\\n\\t}\\n\\n\\tpublic static void countCargo(String pred,String day,Truc... v) {\\n\\t\\tSystem.out.println(pred);\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(day + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2819 "public class Truc {\\n\\tprivate String name;\\n\\tprivate int capacity;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getCapacity() {\\n\\t\\treturn capacity;\\n\\t}\\n\\n\\tTruc(String name, int capacity) {\\n\\t\\tthis.capacity = capacity;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
2820 "Trucks carry sand to the enterprise. The carrying capacities of trucks are different. The number of transportations per day in each truck is different. The program captures transportations and counts the number of tons of sand brought per day.\\n\\nOutput:\\n\\nBrick factory \\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nMonday 101 tons\\n\\nBrick factory \\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 70 tons\\n\\nBrick factory \\nKIA 30 tons\\nVolvo 20 tons\\nWednesday 50 tons\\n",
2821 "Brick factory \\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nMonday 101 tons\\n\\nBrick factory \\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 70 tons\\n\\nBrick factory \\nKIA 30 tons\\nVolvo 20 tons\\nWednesday 50 tons\\n",
2822 "1",
2823 "3",
2824 "155"
2825 ]
2826 },
2827 {
2828 "-name": "question187",
2829 "item": [
2830 "187",
2831 "38",
2832 "public class Truc {\\n\\tprivate String name;\\n\\tprivate int capacity;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getCapacity() {\\n\\t\\treturn capacity;\\n\\t}\\n\\n\\tTruc(String name, int capacity) {\\n\\t\\tthis.capacity = capacity;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
2833 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tTruc truck1 = new Truc(\"Volvo\", 20);\\n\\t\\tTruc truck2 = new Truc(\"Mercedes\", 22);\\n\\t\\tTruc truck3 = new Truc(\"MAN\", 19);\\n\\t\\tTruc truck4 = new Truc(\"Volvo\", 10);\\n\\t\\tTruc truck5 = new Truc(\"KIA\", 30);\\n\\n\\t\\tcountCargo(\"Brick factory \",\"Monday \",truck1, truck3, truck2, truck5, truck4);\\n\\t\\tcountCargo(\"Brick factory \",\"Tuesday \",truck1, truck5, truck4, truck4);\\n\\t\\tcountCargo(\"Brick factory \",\"Wednesday \",truck5, truck1);\\n\\t}\\n\\n\\tpublic static void countCargo(String pred,String day,Truc... v) {\\n\\t\\tSystem.out.println(pred);\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(day + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2834 "Trucks carry sand to the enterprise. The carrying capacities of trucks are different. The number of transportations per day in each truck is different. The program captures transportations and counts the number of tons of sand brought per day.\\n\\nOutput:\\n\\nBrick factory \\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nMonday 101 tons\\n\\nBrick factory \\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 70 tons\\n\\nBrick factory \\nKIA 30 tons\\nVolvo 20 tons\\nWednesday 50 tons\\n",
2835 "Brick factory \\nVolvo 20 tons\\nMAN 19 tons\\nMercedes 22 tons\\nKIA 30 tons\\nVolvo 10 tons\\nMonday 101 tons\\n\\nBrick factory \\nVolvo 20 tons\\nKIA 30 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 70 tons\\n\\nBrick factory \\nKIA 30 tons\\nVolvo 20 tons\\nWednesday 50 tons\\n",
2836 "1",
2837 "2",
2838 "1"
2839 ]
2840 },
2841 {
2842 "-name": "question188",
2843 "item": [
2844 "188",
2845 "38",
2846 "public class Task {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tTruc truck1 = new Truc(\"Volvo\", 20);\\n\\t\\tTruc truck2 = new Truc(\"Mercedes\", 22);\\n\\t\\tTruc truck3 = new Truc(\"MAN\", 19);\\n\\t\\tTruc truck4 = new Truc(\"Volvo\", 10);\\n\\t\\tTruc truck5 = new Truc(\"KIA\", 30);\\n\\n\\t\\tcountCargo(\"Glass factory, \", \"Tuesday \", truck2, truck4, truck4);\\n\\t\\tcountCargo(\"Brick factory, \", \"laying department, \", \"Tuesday \", truck1);\\n\\t\\tcountCargo(\"Brick factory, \", \"main warehouse, \", 3, \"Tuesday \",\\n\\t\\t\\t\\ttruck3, truck5, truck4);\\n\\t}\\n\\n\\tpublic static void countCargo(String pred, String day, Truc... v) {\\n\\t\\tSystem.out.println(pred);\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(day + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n\\n\\tpublic static void countCargo(String pred, String point, String day,\\n\\t\\t\\tTruc... v) {\\n\\t\\tSystem.out.println(pred + point);\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(day + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n\\n\\tpublic static void countCargo(String pred, String point, int house,\\n\\t\\t\\tString day, Truc... v) {\\n\\t\\tSystem.out.println(pred + point + house + \" house \");\\n\\t\\tint countViolation = 0;\\n\\t\\tfor (Truc i : v) {\\n\\t\\t\\tSystem.out.println(i.getName() + \" \" + i.getCapacity() + \" tons\");\\n\\t\\t\\tcountViolation = countViolation + i.getCapacity();\\n\\t\\t}\\n\\t\\tSystem.out.println(day + countViolation + \" tons\");\\n\\t\\tSystem.out.println(\"\");\\n\\t}\\n}\\n",
2847 "public class Truc {\\n\\tprivate String name;\\n\\tprivate int capacity;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic int getCapacity() {\\n\\t\\treturn capacity;\\n\\t}\\n\\n\\tTruc(String name, int capacity) {\\n\\t\\tthis.capacity = capacity;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
2848 "Trucks carry sand to different enterprises. The carrying capacities of trucks are different. Addresses of enterprises are different. The number of transportations is different. The program captures transportations and counts the number of tons of sand brought to enterprises.\\n\\nOutput:\\n\\nGlass factory,\\nMercedes 22 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 42 tons\\n\\nBrick factory, laying department,\\nVolvo 20 tons\\nTuesday 20 tons\\n\\nBrick factory, main warehouse, 3 house\\nMAN 19 tons\\nKIA 30 tons\\nVolvo 10 tons\\nTuesday 59 tons\\n",
2849 "Glass factory,\\nMercedes 22 tons\\nVolvo 10 tons\\nVolvo 10 tons\\nTuesday 42 tons\\n\\nBrick factory, laying department,\\nVolvo 20 tons\\nTuesday 20 tons\\n\\nBrick factory, main warehouse, 3 house\\nMAN 19 tons\\nKIA 30 tons\\nVolvo 10 tons\\nTuesday 59 tons\\n",
2850 "1",
2851 "3",
2852 "168"
2853 ]
2854 },
2855 {
2856 "-name": "question189",
2857 "item": [
2858 "189",
2859 "38",
2860 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMain.vivod(\"Monday\",32, 68, 54, 23, 100);\\n\\t\\tMain.vivod(\"Tuesday\",45, 6, 32);\\n\\t\\tMain.vivod(\"Wednesday\",79, 65, 22, 11);\\n\\t}\\n\\n\\tpublic static void vivod(String week,int... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tint countNoViolation = 0;\\n\\t\\tSystem.out.println(week);\\n\\t\\tfor (int i : v) {\\n\\t\\t\\tif (i > 60) {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is a violation of traffic rules\");\\n\\t\\t\\t\\tcountViolation = countViolation + 1;\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is not a violation of traffic rules\");\\n\\t\\t\\t\\tcountNoViolation = countNoViolation + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.print(\"without violations: \" + countNoViolation);\\n\\t\\tSystem.out.println(\", violations: \" + countViolation);\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
2861 "Several cars passing along a country road in a day. The speed limit of this road is 60 km per hour. The program detects violations and counts the number of violations for first three days of the week.\\n\\nOutput:\\n\\nMonday\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n23 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 3, violations: 2\\n\\nTuesday\\n45 it is not a violation of traffic rules\\n6 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 3, violations: 0\\n\\nWednesday\\n79 it is a violation of traffic rules\\n65 it is a violation of traffic rules\\n22 it is not a violation of traffic rules\\n11 it is not a violation of traffic rules\\nwithout violations: 2, violations: 2\\n",
2862 "Monday\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n23 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 3, violations: 2\\n\\nTuesday\\n45 it is not a violation of traffic rules\\n6 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 3, violations: 0\\n\\nWednesday\\n79 it is a violation of traffic rules\\n65 it is a violation of traffic rules\\n22 it is not a violation of traffic rules\\n11 it is not a violation of traffic rules\\nwithout violations: 2, violations: 2\\n",
2863 "1",
2864 "3",
2865 "76"
2866 ]
2867 },
2868 {
2869 "-name": "question190",
2870 "item": [
2871 "190",
2872 "38",
2873 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString state1 = \"California \";\\n\\t\\tString city1 = \"Los Angeles \";\\n\\t\\tint km1 = 7;\\n\\t\\tString city2 = \"San Francisco \";\\n\\t\\tString timeOfV = \"Monday 13. 00 - 13. 02\";\\n\\n\\t\\tMain.vivod(state1, city1, km1, timeOfV, 32, 68, 54, 100);\\n\\t\\tMain.vivod(city2, timeOfV, 45, 32);\\n\\t}\\n\\n\\tpublic static void vivod(String state, String city, int km, String week,\\n\\t\\t\\tint... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tint countNoViolation = 0;\\n\\t\\tSystem.out.println(week);\\n\\t\\tSystem.out.println(state + city + km + \" km\");\\n\\t\\tfor (int i : v) {\\n\\t\\t\\tif (i > 60) {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is a violation of traffic rules\");\\n\\t\\t\\t\\tcountViolation = countViolation + 1;\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is not a violation of traffic rules\");\\n\\t\\t\\t\\tcountNoViolation = countNoViolation + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.print(\"without violations \" + countNoViolation);\\n\\t\\tSystem.out.println(\", violations \" + countViolation);\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n\\n\\tpublic static void vivod(String city, String week, int... v) {\\n\\t\\tint countViolation = 0;\\n\\t\\tint countNoViolation = 0;\\n\\t\\tSystem.out.println(week);\\n\\t\\tSystem.out.println(city);\\n\\t\\tfor (int i : v) {\\n\\t\\t\\tif (i > 60) {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is a violation of traffic rules\");\\n\\t\\t\\t\\tcountViolation = countViolation + 1;\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tSystem.out.println(i + \" it is not a violation of traffic rules\");\\n\\t\\t\\t\\tcountNoViolation = countNoViolation + 1;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tSystem.out.print(\"without violations \" + countNoViolation);\\n\\t\\tSystem.out.println(\", violations \" + countViolation);\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
2874 "Cameras record exceeding speeds over 60 km per hour. Cameras are located at different addresses.\\n\\nOutput:\\n\\nMonday 13. 00 - 13. 02\\nCalifornia state Los Angeles 7 km\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 2, violations: 2\\n\\nMonday 13. 00 - 13. 02\\nSan Francisco\\n45 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 2, violations: 0\\n",
2875 "Monday 13. 00 - 13. 02\\nCalifornia state Los Angeles 7 km\\n32 it is not a violation of traffic rules\\n68 it is a violation of traffic rules\\n54 it is not a violation of traffic rules\\n100 it is a violation of traffic rules\\nwithout violations: 2, violations: 2\\n\\nMonday 13. 00 - 13. 02\\nSan Francisco\\n45 it is not a violation of traffic rules\\n32 it is not a violation of traffic rules\\nwithout violations: 2, violations: 0\\n",
2876 "1",
2877 "3",
2878 "116"
2879 ]
2880 },
2881 {
2882 "-name": "question191",
2883 "item": [
2884 "191",
2885 "39",
2886 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"BMW\", 10000);// 10000 - mileage between service\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// 100000 - warranty mileage\\n\\n\\t\\tfor (int i = 1; i <= 100000; i++) {\\n\\t\\t\\tif (i % car1.getToMileage() == 0) {\\n\\t\\t\\t\\tcar1.doTo(i);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
2887 "public class Car {\\n\\n\\tprivate String name;\\n\\tprivate int toMileage;\\n\\n\\tCar(String name, int toMileage) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.toMileage = toMileage;\\n\\t}\\n\\n\\tpublic void doTo(int i) {\\n\\t\\tTS tss = new TS();\\n\\t\\ttss.to(name, i);\\n\\t}\\n\\n\\tpublic int getToMileage() {\\n\\t\\treturn toMileage;\\n\\t}\\n\\n\\tclass TS {\\n\\t\\tpublic void to(String name, int i) {\\n\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\tSystem.out.println(\"Technical service \" + i + \" km\");\\n\\t\\t}\\n\\t}\\n}\\n",
2888 "Warranty mileage is 100,000 km. The program gives messages that the technical service is necessary.\\n\\nOutput:\\n\\nCar BMW. Technical service 10000 km\\nCar BMW. Technical service 20000 km\\nCar BMW. Technical service 30000 km\\nCar BMW. Technical service 40000 km\\nCar BMW. Technical service 50000 km\\nCar BMW. Technical service 60000 km\\nCar BMW. Technical service 70000 km\\nCar BMW. Technical service 80000 km\\nCar BMW. Technical service 90000 km\\nCar BMW. Technical service 100000 km\\n",
2889 "Car BMW. Technical service 10000 km\\nCar BMW. Technical service 20000 km\\nCar BMW. Technical service 30000 km\\nCar BMW. Technical service 40000 km\\nCar BMW. Technical service 50000 km\\nCar BMW. Technical service 60000 km\\nCar BMW. Technical service 70000 km\\nCar BMW. Technical service 80000 km\\nCar BMW. Technical service 90000 km\\nCar BMW. Technical service 100000 km\\n",
2890 "1",
2891 "2",
2892 "63"
2893 ]
2894 },
2895 {
2896 "-name": "question192",
2897 "item": [
2898 "192",
2899 "39",
2900 "public class Car {\\n\\n\\tprivate String name;\\n\\tprivate int toMileage;\\n\\n\\tCar(String name, int toMileage) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.toMileage = toMileage;\\n\\t}\\n\\n\\tpublic void doTo(int i) {\\n\\t\\tTS tss = new TS();\\n\\t\\ttss.to(name, i);\\n\\t}\\n\\n\\tpublic int getToMileage() {\\n\\t\\treturn toMileage;\\n\\t}\\n\\n\\tclass TS {\\n\\t\\tpublic void to(String name, int i) {\\n\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\tSystem.out.println(\"Technical service \" + i + \" km\");\\n\\t\\t}\\n\\t}\\n}\\n",
2901 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"BMW\", 10000);// 10000 - mileage between service\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// 100000 - warranty mileage\\n\\n\\t\\tfor (int i = 1; i <= 100000; i++) {\\n\\t\\t\\tif (i % car1.getToMileage() == 0) {\\n\\t\\t\\t\\tcar1.doTo(i);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
2902 "Warranty mileage is 100,000 km. The program gives messages that the technical service is necessary.\\n\\nOutput:\\n\\nCar BMW. Technical service 10000 km\\nCar BMW. Technical service 20000 km\\nCar BMW. Technical service 30000 km\\nCar BMW. Technical service 40000 km\\nCar BMW. Technical service 50000 km\\nCar BMW. Technical service 60000 km\\nCar BMW. Technical service 70000 km\\nCar BMW. Technical service 80000 km\\nCar BMW. Technical service 90000 km\\nCar BMW. Technical service 100000 km\\n",
2903 "Car BMW. Technical service 10000 km\\nCar BMW. Technical service 20000 km\\nCar BMW. Technical service 30000 km\\nCar BMW. Technical service 40000 km\\nCar BMW. Technical service 50000 km\\nCar BMW. Technical service 60000 km\\nCar BMW. Technical service 70000 km\\nCar BMW. Technical service 80000 km\\nCar BMW. Technical service 90000 km\\nCar BMW. Technical service 100000 km\\n",
2904 "1",
2905 "3",
2906 "51"
2907 ]
2908 },
2909 {
2910 "-name": "question193",
2911 "item": [
2912 "193",
2913 "39",
2914 "public class Stud {\\n\\tprivate String name;\\n\\tprivate int mark;\\n\\n\\tpublic Stud(String name, int mark) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.mark = mark;\\n\\t}\\n\\n\\tpublic void doGratters() {\\n\\t\\tGratters gratter1 = new Gratters();\\n\\t\\tgratter1.gratter();\\n\\t}\\n\\n\\tpublic class Gratters {\\n\\t\\tint marks = mark;\\n\\n\\t\\tpublic void gratter() {\\n\\t\\t\\tswitch (marks) {\\n\\t\\t\\tcase 1:\\n\\t\\t\\t\\tSystem.out.println(\"Very bad \" + name);\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 2:\\n\\t\\t\\t\\tSystem.out.println(\"Bad \" + name);\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 3:\\n\\t\\t\\t\\tSystem.out.println(\"Satisfactorily \" + name);\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 4:\\n\\t\\t\\t\\tSystem.out.println(\"Good \" + name);\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tcase 5:\\n\\t\\t\\t\\tSystem.out.println(\"Excellent \" + name);\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\tdefault:\\n\\t\\t\\t\\tSystem.out.println(\"Unclear grade\");\\n\\t\\t\\t\\tbreak;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
2915 "import java.util.Scanner;\\n\\npublic class Exam {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tSystem.out.println(\"Enter the student's grade on a 5 points scale.\");\\n\\t\\tSystem.out.println(\"Type a number:\");\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\t\\tint mark = sc.nextInt();\\n\\t\\tStud student1 = new Stud(\"John\", mark);\\n\\t\\tsc.close();\\n\\t\\tstudent1.doGratters();\\n\\t}\\n}\\n",
2916 "Enter the student's grade. The program displays a message about passing exam.\\n\\nOutput:\\n\\nEnter the student's grade on a 5 points scale.\\nType a number:\\n3\\nSatisfactorily John\\n",
2917 "Enter the student's grade on a 5 points scale.\\nType a number:\\n3\\nSatisfactorily John\\n",
2918 "1",
2919 "3",
2920 "51"
2921 ]
2922 },
2923 {
2924 "-name": "question194",
2925 "item": [
2926 "194",
2927 "39",
2928 "public class Car {\\n\\n\\tprivate String name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void doTo(int i) {\\n\\t\\tTS tss = new TS();\\n\\t\\ttss.to(name, i);\\n\\t}\\n\\n\\tclass TS {\\n\\t\\tpublic void to(String name, int i) {\\n\\t\\t\\tif (i == 40000 || i == 80000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Big TS \" + i + \" km\");\\n\\t\\t\\t} else if (i == 20000 || i == 60000 || i == 100000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Midsize TS \" + i + \" km\");\\n\\t\\t\\t} else if (i == 10000 || i == 30000 || i == 50000 || i == 70000\\n\\t\\t\\t\\t\\t|| i == 90000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Small TS \" + i + \" km\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
2929 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"BMW\");\\n\\n\\t\\tfor (int i = 1; i <= 100000; i++) {\\n\\t\\t\\tcar1.doTo(i);\\n\\t\\t}\\n\\t}\\n}\\n",
2930 "Warranty mileage is 100,000 km. The program gives messages about size of the necessary technical service.\\n\\nOutput:\\n\\nCar BMW. Small TS 10000 km\\nCar BMW. Midsize TS 20000 km\\nCar BMW. Small TS 30000 km\\nCar BMW. Big TS 40000 km\\nCar BMW. Small TS 50000 km\\nCar BMW. Midsize TS 60000 km\\nCar BMW. Small TS 70000 km\\nCar BMW. Big TS 80000 km\\nCar BMW. Small TS 90000 km\\nCar BMW. Midsize TS 100000 km\\n",
2931 "Car BMW. Small TS 10000 km\\nCar BMW. Midsize TS 20000 km\\nCar BMW. Small TS 30000 km\\nCar BMW. Big TS 40000 km\\nCar BMW. Small TS 50000 km\\nCar BMW. Midsize TS 60000 km\\nCar BMW. Small TS 70000 km\\nCar BMW. Big TS 80000 km\\nCar BMW. Small TS 90000 km\\nCar BMW. Midsize TS 100000 km\\n",
2932 "1",
2933 "3",
2934 "33"
2935 ]
2936 },
2937 {
2938 "-name": "question195",
2939 "item": [
2940 "195",
2941 "39",
2942 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"BMW\");\\n\\n\\t\\tfor (int i = 1; i <= 100000; i++) {\\n\\t\\t\\tcar1.doTo(i);\\n\\t\\t}\\n\\t}\\n}\\n",
2943 "public class Car {\\n\\n\\tprivate String name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void doTo(int i) {\\n\\t\\tTS tss = new TS();\\n\\t\\ttss.to(name, i);\\n\\t}\\n\\n\\tclass TS {\\n\\t\\tpublic void to(String name, int i) {\\n\\t\\t\\tif (i == 40000 || i == 80000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Big TS \" + i + \" km\");\\n\\t\\t\\t} else if (i == 20000 || i == 60000 || i == 100000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Midsize TS \" + i + \" km\");\\n\\t\\t\\t} else if (i == 10000 || i == 30000 || i == 50000 || i == 70000\\n\\t\\t\\t\\t\\t|| i == 90000) {\\n\\t\\t\\t\\tSystem.out.print(\"Car \" + name + \". \");\\n\\t\\t\\t\\tSystem.out.println(\"Small TS \" + i + \" km\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
2944 "Warranty mileage is 100,000 km. The program shows messages about size of the necessary technical service.\\n\\nOutput:\\n\\nCar BMW. Small TS 10000 km\\nCar BMW. Midsize TS 20000 km\\nCar BMW. Small TS 30000 km\\nCar BMW. Big TS 40000 km\\nCar BMW. Small TS 50000 km\\nCar BMW. Midsize TS 60000 km\\nCar BMW. Small TS 70000 km\\nCar BMW. Big TS 80000 km\\nCar BMW. Small TS 90000 km\\nCar BMW. Midsize TS 100000 km\\n",
2945 "Car BMW. Small TS 10000 km\\nCar BMW. Midsize TS 20000 km\\nCar BMW. Small TS 30000 km\\nCar BMW. Big TS 40000 km\\nCar BMW. Small TS 50000 km\\nCar BMW. Midsize TS 60000 km\\nCar BMW. Small TS 70000 km\\nCar BMW. Big TS 80000 km\\nCar BMW. Small TS 90000 km\\nCar BMW. Midsize TS 100000 km\\n",
2946 "1",
2947 "1",
2948 "32"
2949 ]
2950 },
2951 {
2952 "-name": "question196",
2953 "item": [
2954 "196",
2955 "40",
2956 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCat cat1 = new Cat();\\n\\t\\tcat1.setWeight(3);\\n\\t\\tcat1.setHeight(30);\\n\\t\\tcat1.setName(\"Cat LuÑy\");\\n\\t\\tcat1.makeSound();\\n\\t\\tcat1.eat();\\n\\t\\tSystem.out.println(\"Weight is \" + cat1.getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Height is \" + cat1.getHeight() + \" cm\");\\n\\t}\\n}\\n",
2957 "public class Anim {\\n\\n\\tprivate int weight;\\n\\tprivate int height;\\n\\n\\tpublic int getHeight() {\\n\\t\\treturn height;\\n\\t}\\n\\n\\tpublic void setHeight(int height) {\\n\\t\\tthis.height = height;\\n\\t}\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic void setWeight(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic void eat() {\\n\\t\\tSystem.out.println(\"Yum-yum\");\\n\\t}\\n}\\n",
2958 "public class Cat extends Anim {\\n\\tprivate String name;\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \" Meow-meow\");\\n\\t}\\n}\\n",
2959 "The program generates a message about the animal: its name, its sounds , its weight, its height.\\n\\nOutput:\\n\\nCat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2960 "Cat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2961 "1",
2962 "2",
2963 "19"
2964 ]
2965 },
2966 {
2967 "-name": "question197",
2968 "item": [
2969 "197",
2970 "40",
2971 "public class Anim {\\n\\n\\tprivate int weight;\\n\\tprivate int height;\\n\\n\\tpublic int getHeight() {\\n\\t\\treturn height;\\n\\t}\\n\\n\\tpublic void setHeight(int height) {\\n\\t\\tthis.height = height;\\n\\t}\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic void setWeight(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic void eat() {\\n\\t\\tSystem.out.println(\"Yum-yum\");\\n\\t}\\n}\\n",
2972 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCat cat1 = new Cat();\\n\\t\\tcat1.setWeight(3);\\n\\t\\tcat1.setHeight(30);\\n\\t\\tcat1.setName(\"Cat LuÑy\");\\n\\t\\tcat1.makeSound();\\n\\t\\tcat1.eat();\\n\\t\\tSystem.out.println(\"Weight is \" + cat1.getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Height is \" + cat1.getHeight() + \" cm\");\\n\\t}\\n}\\n",
2973 "public class Cat extends Anim {\\n\\tprivate String name;\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \" Meow-meow\");\\n\\t}\\n}\\n",
2974 "The program generates a message about the animal: its name, its sounds , its weight, its height.\\n\\nOutput:\\n\\nCat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2975 "Cat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2976 "1",
2977 "2",
2978 "12"
2979 ]
2980 },
2981 {
2982 "-name": "question198",
2983 "item": [
2984 "198",
2985 "40",
2986 "public class Cat extends Anim {\\n\\tprivate String name;\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \" Meow-meow\");\\n\\t}\\n}\\n",
2987 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCat cat1 = new Cat();\\n\\t\\tcat1.setWeight(3);\\n\\t\\tcat1.setHeight(30);\\n\\t\\tcat1.setName(\"Cat LuÑy\");\\n\\t\\tcat1.makeSound();\\n\\t\\tcat1.eat();\\n\\t\\tSystem.out.println(\"Weight is \" + cat1.getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Height is \" + cat1.getHeight() + \" cm\");\\n\\t}\\n}\\n",
2988 "public class Anim {\\n\\n\\tprivate int weight;\\n\\tprivate int height;\\n\\n\\tpublic int getHeight() {\\n\\t\\treturn height;\\n\\t}\\n\\n\\tpublic void setHeight(int height) {\\n\\t\\tthis.height = height;\\n\\t}\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic void setWeight(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic void eat() {\\n\\t\\tSystem.out.println(\"Yum-yum\");\\n\\t}\\n}\\n",
2989 "The program generates a message about the animal: its name, its sounds , its weight, its height.\\n\\nOutput:\\n\\nCat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2990 "Cat LuÑy Meow-meow\\nYum-yum\\nWeight is 3 kg\\nHeight is 30 cm\\n",
2991 "1",
2992 "1",
2993 "6"
2994 ]
2995 },
2996 {
2997 "-name": "question199",
2998 "item": [
2999 "199",
3000 "40",
3001 "public class Mash {\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic void setWeight(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.setName(\"BMW\");\\n\\t\\tcar1.setWeight(2000);\\n\\t\\tcar1.setPassanger(4);\\n\\n\\t\\tTank car2 = new Tank();\\n\\t\\tcar2.setName(\"T-34\");\\n\\t\\tcar2.setWeight(34000);\\n\\t\\tcar2.setMainGun(85);\\n\\n\\t\\tSystem.out.println(car1.getName() + \", \" + car1.getWeight() + \" kg\");\\n\\t\\tcar1.makeSound();\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tSystem.out.println(car2.getName() + \", \" + car2.getWeight() + \" kg\");\\n\\t\\tcar2.shot();\\n\\t}\\n}\\n",
3002 "public class Tank extends Mash {\\n\\n\\tprivate int mainGun;\\n\\n\\tpublic int getMainGun() {\\n\\t\\treturn mainGun;\\n\\t}\\n\\n\\tpublic void setMainGun(int mainGun) {\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t}\\n}\\n",
3003 "public class Car extends Mash {\\n\\n\\tprivate int passanger;\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + passanger + \" people\");\\n\\t}\\n\\n\\tpublic int getPassanger() {\\n\\t\\treturn passanger;\\n\\t}\\n\\n\\tpublic void setPassanger(int passanger) {\\n\\t\\tthis.passanger = passanger;\\n\\t}\\n}\\n",
3004 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nBMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3005 "BMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3006 "1",
3007 "3",
3008 "115"
3009 ]
3010 },
3011 {
3012 "-name": "question200",
3013 "item": [
3014 "200",
3015 "40",
3016 "public class Tank extends Mash {\\n\\n\\tprivate int mainGun;\\n\\n\\tpublic int getMainGun() {\\n\\t\\treturn mainGun;\\n\\t}\\n\\n\\tpublic void setMainGun(int mainGun) {\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t}\\n}\\n",
3017 "public class Mash {\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic void setWeight(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.setName(\"BMW\");\\n\\t\\tcar1.setWeight(2000);\\n\\t\\tcar1.setPassanger(4);\\n\\n\\t\\tTank car2 = new Tank();\\n\\t\\tcar2.setName(\"T-34\");\\n\\t\\tcar2.setWeight(34000);\\n\\t\\tcar2.setMainGun(85);\\n\\n\\t\\tSystem.out.println(car1.getName() + \", \" + car1.getWeight() + \" kg\");\\n\\t\\tcar1.makeSound();\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tSystem.out.println(car2.getName() + \", \" + car2.getWeight() + \" kg\");\\n\\t\\tcar2.shot();\\n\\t}\\n}\\n",
3018 "public class Car extends Mash {\\n\\n\\tprivate int passanger;\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + passanger + \" people\");\\n\\t}\\n\\n\\tpublic int getPassanger() {\\n\\t\\treturn passanger;\\n\\t}\\n\\n\\tpublic void setPassanger(int passanger) {\\n\\t\\tthis.passanger = passanger;\\n\\t}\\n}\\n",
3019 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nBMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3020 "BMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3021 "1",
3022 "2",
3023 "1"
3024 ]
3025 },
3026 {
3027 "-name": "question201",
3028 "item": [
3029 "201",
3030 "41",
3031 "public class Mash {\\n\\n\\tpublic int weight;\\n\\tprivate String name;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.setName(\"BMW\");\\n\\t\\tcar1.weight = 2000;\\n\\t\\tcar1.pass = 4;\\n\\n\\t\\tTank car2 = new Tank();\\n\\t\\tcar2.setName(\"T-34\");\\n\\t\\tcar2.weight = 34000;\\n\\t\\tcar2.mainGun = 85;\\n\\n\\t\\tcar1.makeSound();\\n\\t\\tcar2.shot();\\n\\t}\\n}\\n",
3032 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(getName() + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3033 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3034 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nBMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3035 "BMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3036 "1",
3037 "2",
3038 "84"
3039 ]
3040 },
3041 {
3042 "-name": "question202",
3043 "item": [
3044 "202",
3045 "41",
3046 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(getName() + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3047 "public class Mash {\\n\\n\\tpublic int weight;\\n\\tprivate String name;\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tpublic void setName(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar car1 = new Car();\\n\\t\\tcar1.setName(\"BMW\");\\n\\t\\tcar1.weight = 2000;\\n\\t\\tcar1.pass = 4;\\n\\n\\t\\tTank car2 = new Tank();\\n\\t\\tcar2.setName(\"T-34\");\\n\\t\\tcar2.weight = 34000;\\n\\t\\tcar2.mainGun = 85;\\n\\n\\t\\tcar1.makeSound();\\n\\t\\tcar2.shot();\\n\\t}\\n}\\n",
3048 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3049 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nBMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3050 "BMW, 2000 kg\\nBeep-beep, passengers 4 people\\n\\nT-34, 34000 kg\\nBoom-boom, caliber 85 mm\\n",
3051 "1",
3052 "2",
3053 "24"
3054 ]
3055 },
3056 {
3057 "-name": "question203",
3058 "item": [
3059 "203",
3060 "41",
3061 "public class Mash {\\n\\n\\tpublic int weight;\\n\\tString name;\\n\\n\\tMash() {\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(2000, \"BMW\", 4);\\n\\t\\tCar car2 = new Car(1500, \"Toyota\", 4);\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\t\\tMash mash1 = new Mash(10000, \"Unknown car\");\\n\\n\\t\\tcar1.makeSound();\\n\\t\\tcar2.makeSound();\\n\\t\\ttank1.shot();\\n\\t\\tSystem.out.println(mash1.name);\\n\\t}\\n}\\n",
3062 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tCar(int weight, String name, int pass) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.pass = pass;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3063 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3064 "The program displays a message about cars type, its weight and its features, if it is known.\\n\\nOutput:\\n\\nToyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nUnknown car\\n",
3065 "Toyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nUnknown car\\n",
3066 "1",
3067 "3",
3068 "74"
3069 ]
3070 },
3071 {
3072 "-name": "question204",
3073 "item": [
3074 "204",
3075 "41",
3076 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3077 "public class Mash {\\n\\n\\tpublic int weight;\\n\\tString name;\\n\\n\\tMash() {\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(2000, \"BMW\", 4);\\n\\t\\tCar car2 = new Car(1500, \"Toyota\", 4);\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\t\\tMash mash1 = new Mash(10000, \"Unknown car\");\\n\\n\\t\\tcar1.makeSound();\\n\\t\\tcar2.makeSound();\\n\\t\\ttank1.shot();\\n\\t\\tSystem.out.println(mash1.name);\\n\\t}\\n}\\n",
3078 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tCar(int weight, String name, int pass) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.pass = pass;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3079 "The program displays a message about cars type, its weight and its features, if it is known.\\n\\nOutput:\\n\\nToyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nUnknown car\\n",
3080 "Toyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nUnknown car\\n",
3081 "1",
3082 "2",
3083 "24"
3084 ]
3085 },
3086 {
3087 "-name": "question205",
3088 "item": [
3089 "205",
3090 "41",
3091 "public class Mash {\\n\\n\\tpublic int weight;\\n\\tString name;\\n\\n\\tMash() {\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(1500, \"Toyota\", 4);\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\t\\tMash mash1, mash2;\\n\\t\\tmash1 = car1;\\n\\t\\tmash2 = tank1;\\n\\t\\tSystem.out.println(mash1.name + \" \" + mash1.weight + \" kg\");\\n\\t\\tSystem.out.println(mash2.name + \" \" + mash2.weight + \" kg\");\\n\\t}\\n}\\n",
3092 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tCar(int weight, String name, int pass) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.pass = pass;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3093 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3094 "The program displays a message about the name of the car and its weight.\\n\\nOutput:\\n\\nToyota 1500 kg\\nT-34 34000 kg\\n",
3095 "Toyota 1500 kg\\nT-34 34000 kg\\n",
3096 "1",
3097 "3",
3098 "27"
3099 ]
3100 },
3101 {
3102 "-name": "question206",
3103 "item": [
3104 "206",
3105 "42",
3106 "public class Mash {\\n\\t// members of the class are declared as private\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(1500, \"Toyota\", 4);\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\n\\t\\tcar1.makeSound();\\n\\t\\ttank1.shot();\\n\\t}\\n}\\n",
3107 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tCar(int weight, String name, int pass) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.pass = pass;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3108 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3109 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nToyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n",
3110 "Toyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm",
3111 "1",
3112 "3",
3113 "18"
3114 ]
3115 },
3116 {
3117 "-name": "question207",
3118 "item": [
3119 "207",
3120 "42",
3121 "public class Car extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int pass;\\n\\n\\tCar(int weight, String name, int pass) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.pass = pass;\\n\\t}\\n\\n\\tpublic void makeSound() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Beep-beep, passengers \" + pass + \" people\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3122 "public class Mash {\\n\\t// members of the class are declared as private\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(1500, \"Toyota\", 4);\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\n\\t\\tcar1.makeSound();\\n\\t\\ttank1.shot();\\n\\t}\\n}\\n",
3123 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3124 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nToyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n",
3125 "Toyota,1500 kg\\nBeep-beep, passengers 4 people\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm",
3126 "1",
3127 "2",
3128 "24"
3129 ]
3130 },
3131 {
3132 "-name": "question208",
3133 "item": [
3134 "208",
3135 "42",
3136 "public class Mash {\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tMash() {\\n\\t\\tweight = 0;\\n\\t\\tthis.name = \"tank\";\\n\\t}\\n\\n\\tMash(String name) {\\n\\t\\tweight = 0;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\t\\tTank tank2 = new Tank(\"Abrams\", 120);\\n\\t\\tTank tank3 = new Tank(130);\\n\\n\\t\\ttank1.shot();\\n\\t\\ttank2.shot();\\n\\t\\ttank3.shot();\\n\\t}\\n}\\n",
3137 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tTank(int mainGun) {\\n\\t\\tsuper();\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tTank(String name, int mainGun) {\\n\\t\\tsuper(name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3138 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nAbrams,0 кг\\nBoom-boom, caliber 120 mm\\n\\ntank,0 kg\\nBoom-boom, caliber 130 mm\\n",
3139 "T-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nAbrams,0 кг\\nBoom-boom, caliber 120 mm\\n\\ntank,0 kg\\nBoom-boom, caliber 130 mm\\n",
3140 "1",
3141 "3",
3142 "5"
3143 ]
3144 },
3145 {
3146 "-name": "question209",
3147 "item": [
3148 "209",
3149 "42",
3150 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int mainGun;\\n\\n\\tTank(int mainGun) {\\n\\t\\tsuper();\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tTank(String name, int mainGun) {\\n\\t\\tsuper(name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tTank(int weight, String name, int mainGun) {\\n\\t\\tsuper(weight, name);\\n\\t\\tthis.mainGun = mainGun;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(getName() + \",\" + getWeight() + \" kg\");\\n\\t\\tSystem.out.println(\"Boom-boom, caliber \" + mainGun + \" mm\");\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3151 "public class Mash {\\n\\n\\tprivate int weight;\\n\\tprivate String name;\\n\\n\\tpublic int getWeight() {\\n\\t\\treturn weight;\\n\\t}\\n\\n\\tpublic String getName() {\\n\\t\\treturn name;\\n\\t}\\n\\n\\tMash() {\\n\\t\\tweight = 0;\\n\\t\\tthis.name = \"tank\";\\n\\t}\\n\\n\\tMash(String name) {\\n\\t\\tweight = 0;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tMash(int weight, String name) {\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 85);\\n\\t\\tTank tank2 = new Tank(\"Abrams\", 120);\\n\\t\\tTank tank3 = new Tank(130);\\n\\n\\t\\ttank1.shot();\\n\\t\\ttank2.shot();\\n\\t\\ttank3.shot();\\n\\t}\\n}\\n",
3152 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nT-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nAbrams,0 кг\\nBoom-boom, caliber 120 mm\\n\\ntank,0 kg\\nBoom-boom, caliber 130 mm\\n",
3153 "T-34,34000 kg\\nBoom-boom, caliber 85 mm\\n\\nAbrams,0 кг\\nBoom-boom, caliber 120 mm\\n\\ntank,0 kg\\nBoom-boom, caliber 130 mm\\n",
3154 "1",
3155 "2",
3156 "31"
3157 ]
3158 },
3159 {
3160 "-name": "question210",
3161 "item": [
3162 "210",
3163 "42",
3164 "public class Tank extends Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int speed;\\n\\tpublic String color;\\n\\n\\tTank(int weight, String name, int speed, String color, int speed1,\\n\\t\\t\\tString color1) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.weight = weight;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.color = color;\\n\\t\\tsuper.speed = speed1;\\n\\t\\tsuper.color = color1;\\n\\t}\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(name + \",\" + weight + \" kg\");\\n\\t\\tSystem.out.println(\"The speed is \" + speed + \" km per hour. On impassability: \" + super.speed);\\n\\t\\tSystem.out.println(\"Color is \" + color + \". In winter: \" + super.color);\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
3165 "public class Mash {\\n\\t// to reduce code all members of the class are declared as public\\n\\n\\tpublic int weight;\\n\\tpublic String name;\\n\\tpublic int speed;\\n\\tpublic String color;\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTank tank1 = new Tank(34000, \"T-34\", 80, \"khaki\",50, \"white\");\\n\\t\\tTank tank2 = new Tank(62000, \"Abrams\", 100, \"khaki\",65, \"white\");\\n\\t\\tTank tank3 = new Tank(45000, \"T-72\", 110, \"khaki\",70, \"white\");\\n\\n\\t\\ttank1.shot();\\n\\t\\ttank2.shot();\\n\\t\\ttank3.shot();\\n\\t}\\n}\\n",
3166 "The program displays a message about cars type, its weight and its features.\\n\\nOutput:\\n\\nT-34,34000 kg\\nThe speed is 80 km per hour. On impassability: 50\\nColor is khaki. In winter: white\\n\\nAbrams,62000 kg\\nThe speed is 100 km per hour. On impassability: 65\\nColor is khaki. In winter: white\\n\\nT-72,45000 kg\\nThe speed is 110 km per hour. On impassability: 70\\nColor is khaki. In winter: white\\n",
3167 "T-34,34000 kg\\nThe speed is 80 km per hour. On impassability: 50\\nColor is khaki. In winter: white\\n\\nAbrams,62000 kg\\nThe speed is 100 km per hour. On impassability: 65\\nColor is khaki. In winter: white\\n\\nT-72,45000 kg\\nThe speed is 110 km per hour. On impassability: 70\\nColor is khaki. In winter: white\\n",
3168 "1",
3169 "3",
3170 "24"
3171 ]
3172 },
3173 {
3174 "-name": "question211",
3175 "item": [
3176 "211",
3177 "43",
3178 "public class Mach {\\n\\tpublic int weight;\\n\\tpublic String type;\\n\\n\\tpublic void machineInformation() {\\n\\t\\tSystem.out.println(\"Weight:\" + weight);\\n\\t\\tSystem.out.println(\"Type:\" + type);\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMCar myCar1 = new MCar();\\n\\t\\tmyCar1.numer = \"FA 6845\";\\n\\t\\tmyCar1.holderName = \"Bill\";\\n\\t\\tmyCar1.color = \"Silver\";\\n\\t\\tmyCar1.brand = \"Toyota Carolla\";\\n\\t\\tmyCar1.maxSpeed = 160;\\n\\t\\tmyCar1.weight = 1300;\\n\\t\\tmyCar1.type = \"Sedan\";\\n\\n\\t\\tmyCar1.machineInformation();\\n\\t\\tmyCar1.carInformation();\\n\\t\\tmyCar1.myInformation();\\n\\t}\\n}\\n",
3179 "public class Car extends Mach {\\n\\tpublic String brand;\\n\\tpublic String color;\\n\\tpublic int maxSpeed;\\n\\n\\tpublic void carInformation() {\\n\\t\\tSystem.out.println(\"Brand:\" + brand);\\n\\t\\tSystem.out.println(\"Color:\" + color);\\n\\t\\tSystem.out.println(\"Maximum speed:\" + maxSpeed);\\n\\t}\\n}\\n",
3180 "public class MCar extends Car {\\n\\tpublic String numer;\\n\\tpublic String holderName;\\n\\n\\tpublic void myInformation() {\\n\\t\\tSystem.out.println(\"Car number:\" + numer);\\n\\t\\tSystem.out.println(\"Owner:\" + holderName);\\n\\t}\\n}\\n",
3181 "The program displays characteristics of the car. \\n\\nOutput:\\n\\nWeight:1300\\nType:Sedan\\nBrand:Toyota Carolla\\nColor:Silver\\nMaximum speed:160\\nCar number:FA 6845\\nOwner:Bill\\n",
3182 "Weight:1300\\nType:Sedan\\nBrand:Toyota Carolla\\nColor:Silver\\nMaximum speed:160\\nCar number:FA 6845\\nOwner:Bill\\n",
3183 "1",
3184 "3",
3185 "18"
3186 ]
3187 },
3188 {
3189 "-name": "question212",
3190 "item": [
3191 "212",
3192 "43",
3193 "public class Crow extends Bird {\\n\\tstatic String color = \"black\";\\n\\tString name;\\n\\n\\tpublic void fly() {\\n\\t\\tSystem.out.println(\"flies very fast\");\\n\\t}\\n\\n\\tpublic void say() {\\n\\t\\tSystem.out.println(\"says caw, caw\");\\n\\t}\\n\\n\\tCrow(int weight, String name) {\\n\\t\\tsuper(weight);\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3194 "public abstract class Anim {// abstract class\\n\\t// you cannot create an instance of the class\\n\\tint weight;\\n\\n\\tAnim(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic void sleep() {\\n\\t\\tSystem.out.println(\"sleeps quietly\");\\n\\t}\\n\\n\\tpublic void eat() {\\n\\t\\tSystem.out.println(\"eats yum yum\");\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCrow crow1 = new Crow(1200, \"Hardy\");\\n\\t\\tCrow crow2 = new Crow(1900, \"Sara\");\\n\\t\\tSystem.out.println(crow1.name + color + Crow.color);\\n\\t\\tcrow1.sleep();\\n\\t\\tcrow1.eat();\\n\\t\\tcrow1.run();\\n\\t\\tSystem.out.print(Bird.wings + \" wings \");\\n\\t\\tcrow1.fly();\\n\\t\\tcrow1.say();\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(crow2.name + \" color \" + Crow.color);\\n\\t\\tcrow2.sleep();\\n\\t\\tcrow2.eat();\\n\\t\\tcrow2.run();\\n\\t\\tSystem.out.print(Bird.wings + \" wings \");\\n\\t\\tcrow2.fly();\\n\\t\\tcrow2.say();\\n\\t}\\n}\\n",
3195 "public abstract class Bird extends Anim {// abstract class\\n\\t// you cannot create an instance of the class\\n\\n\\tstatic int wings = 2;\\n\\tBird(int weight) {\\n\\t\\tsuper(weight);\\n\\t}\\tpublic void run() {\\n\\t\\tSystem.out.println(\"runs on 2 legs\");\\n\\t}\\n}\\n",
3196 "The program displays information about crows.\\n\\nOutput:\\n\\nHardy color black\\nsleeps quietly\\neats yum yum\\nruns on 2 legs\\n2 wings flies very fast\\nsays caw, caw\\n\\nSara color black\\nsleeps quietly\\neats yum yum\\nruns on 2 legs\\n2 wings flies very fast\\nsays caw, caw\\n",
3197 "Hardy color black\\nsleeps quietly\\neats yum yum\\nruns on 2 legs\\n2 wings flies very fast\\nsays caw, caw\\n\\nSara color black\\nsleeps quietly\\neats yum yum\\nruns on 2 legs\\n2 wings flies very fast\\nsays caw, caw\\n",
3198 "1",
3199 "3",
3200 "20"
3201 ]
3202 },
3203 {
3204 "-name": "question213",
3205 "item": [
3206 "213",
3207 "43",
3208 "public abstract class Anim {// abstract class\\n\\t// you cannot create an instance of the class\\n\\tint weight;\\n\\n\\tAnim(int weight) {\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic void sleep() {\\n\\t\\tSystem.out.println(\"sleeps quietly\");\\n\\t}\\n\\n\\tpublic void eat() {\\n\\t\\tSystem.out.println(\"eats yum yum\");\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tPig pig1 = new Pig(90000, \"Nifnif\", \"pink\");\\n\\t\\tPig pig2 = new Pig(160000, \"Nafnaf\", \"grey\");\\n\\n\\t\\tSystem.out.println(pig1.name + \" color \" + pig1.color);\\n\\t\\tSystem.out.println(\"weight \" + pig1.weight + \" grams \");\\n\\t\\tpig1.sleep();\\n\\t\\tpig1.eat();\\n\\t\\tSystem.out.print(Mam.feet + \" paws \");\\n\\t\\tpig1.run();\\n\\t\\tpig1.say();\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(pig2.name + \" color \" + pig2.color);\\n\\t\\tSystem.out.println(\"weight \" + pig2.weight + \" grams \");\\n\\t\\tpig2.sleep();\\n\\t\\tpig2.eat();\\n\\t\\tSystem.out.print(Mam.feet + \" paws \");\\n\\t\\tpig2.run();\\n\\t\\tpig2.say();\\n\\t}\\n}\\n",
3209 "public abstract class Mam extends Anim {// abstract class\\n\\t// you cannot create an instance of the class\\n\\tstatic int feet = 4;\\n\\n\\tMam(int weight) {\\n\\t\\tsuper(weight);\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tSystem.out.println(\"runs on 4 paws\");\\n\\t}\\n}\\n",
3210 "public class Pig extends Mam {\\n\\n\\tString color;\\n\\tString name;\\n\\n\\tpublic void say() {\\n\\t\\tSystem.out.println(\"says grunt-grunt\");\\n\\t}\\n\\n\\tPig(int weight, String name, String color) {\\n\\t\\tsuper(weight);\\n\\t\\tthis.name = name;\\n\\t\\tthis.color = color;\\n\\t}\\n}\\n",
3211 "The program displays information about pigs.\\n\\nOutput:\\n\\nNifnif color pink\\nweight 90000 grams \\nsleeps quietly\\neats yum yum\\n4 paws runs on 4 paws\\nsays grunt-grunt\\n\\nNafnaf color grey\\nweight 160000 grams \\nsleeps quietly\\neats yum yum\\n4 paws runs on 4 paws\\nsays grunt-grunt\\n",
3212 "Nifnif color pink\\nweight 90000 grams \\nsleeps quietly\\neats yum yum\\n4 paws runs on 4 paws\\nsays grunt-grunt\\n\\nNafnaf color grey\\nweight 160000 grams \\nsleeps quietly\\neats yum yum\\n4 paws runs on 4 paws\\nsays grunt-grunt\\n",
3213 "1",
3214 "3",
3215 "38"
3216 ]
3217 },
3218 {
3219 "-name": "question214",
3220 "item": [
3221 "214",
3222 "43",
3223 "public class Mil {\\n\\n\\tint firingRange;\\n\\n\\tpublic void shot() {\\n\\t\\tSystem.out.println(\"Shoots\");\\n\\t}\\n\\n\\tpublic void obeyOrders() {\\n\\t\\tSystem.out.println(\"Yes, ser\");\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tMil military1 = new Mil();\\n\\t\\tmilitary1.firingRange = 1000;\\n\\n\\t\\tOffi officer1 = new Offi();\\n\\t\\tofficer1.firingRange = 600;\\n\\n\\t\\tCapt capitan1 = new Capt(1000, \"James\", 3);\\n\\n\\t\\tmilitary1.obeyOrders();\\n\\t\\tSystem.out.println(\"The firing range \" + military1.firingRange);\\n\\t\\tmilitary1.shot();\\n\\t\\tSystem.out.println();\\n\\n\\t\\tofficer1.command();\\n\\t\\tSystem.out.println(\"The firing range \" + officer1.firingRange);\\n\\t\\tofficer1.shot();\\n\\t\\tSystem.out.println();\\n\\n\\t\\tSystem.out.println(\"Captain \" + capitan1.name);\\n\\t\\tSystem.out.println(\"Rewards \" + capitan1.honors);\\n\\t\\tcapitan1.command();\\n\\t\\tSystem.out.println(\"The firing range \" + capitan1.firingRange);\\n\\t\\tcapitan1.shot();\\n\\t}\\n}\\n",
3224 "public class Offi extends Mil {\\n\\n\\tpublic void command() {\\n\\t\\tSystem.out.println(\"Forward\");\\n\\t}\\n}\\n",
3225 "public class Capt extends Offi {\\n\\tString name;\\n\\tint honors;\\n\\n\\tCapt(int firingRange, String name, int honors) {\\n\\t\\tthis.firingRange = firingRange;\\n\\t\\tthis.name = name;\\n\\t\\tthis.honors = honors;\\n\\t}\\n}\\n",
3226 "The program generates reports about soldiers: orders, firing range, soldier, shooting, name, number of awards.\\n\\nOutput:\\n\\nYes, ser\\nThe firing range 1000\\nShoots\\n\\nForward\\nThe firing range 600\\nshoots\\n\\nCaptain James\\nRewards 3\\nForward\\nThe firing range 1000\\nShoots\\n",
3227 "Yes, ser\\nThe firing range 1000\\nShoots\\n\\nForward\\nThe firing range 600\\nShoots\\n\\nCaptain James\\nRewards 3\\nForward\\nThe firing range 1000\\nShoots\\n",
3228 "1",
3229 "3",
3230 "35"
3231 ]
3232 },
3233 {
3234 "-name": "question215",
3235 "item": [
3236 "215",
3237 "43",
3238 "public class Tree {\\n\\tint height;\\n\\tString color;\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tAppl apple1 = new Appl(10, \"green\", \"Antonovka\", 500);\\n\\n\\t\\tSystem.out.println(\"The apple tree \" + apple1.sort);\\n\\t\\tapple1.grow();\\n\\t\\tSystem.out.println(\"height \" + apple1.height);\\n\\t\\tSystem.out.println(\"color \" + apple1.color);\\n\\t\\tapple1.flowers();\\n\\t\\tSystem.out.println(\"productivity \" + apple1.productivity);\\n\\t\\tSystem.out.println();\\n\\n\\t\\tTree tree1 = new Tree();\\n\\t\\ttree1.height = 18;\\n\\t\\ttree1.color = \"dark green\";\\n\\t\\tSystem.out.println(\"A tree\");\\n\\t\\tSystem.out.println(\"height \" + tree1.height);\\n\\t\\tSystem.out.println(\"color \" + tree1.color);\\n\\t}\\n}\\n",
3239 "public class Deci extends Tree {\\n\\n\\tpublic void grow() {\\n\\t\\tSystem.out.println(\"grows high\");\\n\\t}\\n}\\n",
3240 "public class Appl extends Deci {\\n\\n\\tString sort;\\n\\tint productivity;\\n\\n\\tAppl(int height, String color, String sort, int productivity) {\\n\\t\\tthis.height = height;\\n\\t\\tthis.color = color;\\n\\t\\tthis.sort = sort;\\n\\t\\tthis.productivity = productivity;\\n\\t}\\n\\n\\tpublic void flowers() {\\n\\t\\tSystem.out.println(\"blooms beautifully\");\\n\\t}\\n}\\n",
3241 "The program displays information about trees.\\n\\nOutput:\\n\\nThe apple tree Antonovka\\ngrows high\\nheight 10\\ncolor green\\nblooms beautifully\\nproductivity 500\\n\\nA tree\\nheight 18\\ncolor dark green\\n",
3242 "The apple tree Antonovka\\ngrows high\\nheight 10\\ncolor green\\nblooms beautifully\\nproductivity 500\\n\\nA tree\\nheight 18\\ncolor dark green\\n",
3243 "1",
3244 "3",
3245 "30"
3246 ]
3247 },
3248 {
3249 "-name": "question216",
3250 "item": [
3251 "216",
3252 "44",
3253 "//Unit elements are in one array\\npublic class Unit {\\n\\tint str;\\n\\tint speed;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc orc1 = new Orc(2, 1, \"Zuzu\");\\n\\t\\tOrc orc2 = new Orc(2, 1, \"Zozo\");\\n\\t\\tElf elf1 = new Elf(1, 2, \"Elain\");\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\");\\n\\n\\t\\tUnit units[] = new Unit[4];\\n\\t\\tunits[0] = orc1;\\n\\t\\tunits[1] = orc2;\\n\\t\\tunits[2] = elf1;\\n\\t\\tunits[3] = elf2;\\n\\t\\tfor (Unit un : units) {\\n\\t\\t\\tun.attack();\\n\\t\\t\\tun.defend();\\n\\t\\t\\tun.move();\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n}\\n",
3254 "public class Elf extends Unit {\\n\\tString name;\\n\\n\\tElf(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3255 "public class Orc extends Unit {\\n\\tString name;\\n\\n\\tOrc(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" hits by his cudgel. Strength \" + 2 * str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3256 "The program emulates a battle Orcs and Elves.\\n\\nOutput:\\n\\nZuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2.\\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2.\\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1.\\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1.\\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3257 "Zuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2.\\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2. \\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1. \\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1. \\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3258 "1",
3259 "3",
3260 "23"
3261 ]
3262 },
3263 {
3264 "-name": "question217",
3265 "item": [
3266 "217",
3267 "44",
3268 "public class Elf extends Unit {\\n\\tString name;\\n\\n\\tElf(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3269 "// Unit elements are in one array\\npublic class Unit {\\n\\tint str;\\n\\tint speed;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc orc1 = new Orc(2, 1, \"Zuzu\");\\n\\t\\tOrc orc2 = new Orc(2, 1, \"Zozo\");\\n\\t\\tElf elf1 = new Elf(1, 2, \"Elain\");\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\");\\n\\n\\t\\tUnit units[] = new Unit[4];\\n\\t\\tunits[0] = orc1;\\n\\t\\tunits[1] = orc2;\\n\\t\\tunits[2] = elf1;\\n\\t\\tunits[3] = elf2;\\n\\t\\tfor (Unit un : units) {\\n\\t\\t\\tun.attack();\\n\\t\\t\\tun.defend();\\n\\t\\t\\tun.move();\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n}\\n",
3270 "public class Orc extends Unit {\\n\\tString name;\\n\\n\\tOrc(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" hits by his cudgel. Strength \" + 2 * str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3271 "The program emulates a battle Orcs and Elves.\\n\\nOutput:\\n\\nZuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2. \\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2.\\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1.\\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1.\\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3272 "Zuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2.\\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2. \\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1. \\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1. \\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3273 "1",
3274 "3",
3275 "1"
3276 ]
3277 },
3278 {
3279 "-name": "question218",
3280 "item": [
3281 "218",
3282 "44",
3283 "public class Orc extends Unit {\\n\\tString name;\\n\\n\\tOrc(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" hits by his cudgel. Strength \" + 2 * str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3284 "// Unit elements are in one array\\npublic class Unit {\\n\\tint str;\\n\\tint speed;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc orc1 = new Orc(2, 1, \"Zuzu\");\\n\\t\\tOrc orc2 = new Orc(2, 1, \"Zozo\");\\n\\t\\tElf elf1 = new Elf(1, 2, \"Elain\");\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\");\\n\\n\\t\\tUnit units[] = new Unit[4];\\n\\t\\tunits[0] = orc1;\\n\\t\\tunits[1] = orc2;\\n\\t\\tunits[2] = elf1;\\n\\t\\tunits[3] = elf2;\\n\\t\\tfor (Unit un : units) {\\n\\t\\t\\tun.attack();\\n\\t\\t\\tun.defend();\\n\\t\\t\\tun.move();\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n}\\n",
3285 "public class Elf extends Unit {\\n\\tString name;\\n\\n\\tElf(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3286 "The program emulates a battle Orcs and Elves.\\n\\nOutput:\\n\\nZuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2. \\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2.\\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1.\\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1.\\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3287 "Zuzu hits by his cudgel. Strength 4. \\nZuzu covers his shield. Strength 2.\\nZuzu takes a step. \\n\\nZozo hits by his cudgel. Strength 4. \\nZozo covers his shield. Strength 2. \\nZozo takes a step. \\n\\nElain shoots a bow. Strength 1. Elain shoots a bow. Strength 1. \\nElain covers his shield. Strength 1. \\nElain takes a step. Elain takes a step. \\n\\nElon shoots a bow. Strength 1. Elon shoots a bow. Strength 1. \\nElon covers his shield. Strength 1. \\nElon takes a step. Elon takes a step. \\n",
3288 "1",
3289 "3",
3290 "1"
3291 ]
3292 },
3293 {
3294 "-name": "question219",
3295 "item": [
3296 "219",
3297 "44",
3298 "public class Unit {\\n\\tint str;\\n\\tint speed;\\n\\tString name;\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" hits. Strength \" + 2 * str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc orc1 = new Orc(2, 1, \"Zuzu\");\\n\\t\\tElf elf1 = new Elf(1, 2, \"Eline\");\\n\\n\\t\\torc1.attack();\\n\\t\\torc1.defend();\\n\\t\\torc1.move();\\n\\t\\tSystem.out.println();\\n\\t\\telf1.attack();\\n\\t\\telf1.defend();\\n\\t\\telf1.move();\\n\\t}\\n}\\n",
3299 "public class Elf extends Unit {\\n\\n\\tElf(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tsuper.attack();\\n\\t\\tSystem.out.println(\"My bow is accurate.\");\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tsuper.defend();\\n\\t\\tSystem.out.println(\"My shield is made of diamonds.\");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tsuper.move();\\n\\t\\tSystem.out.println(\"My legs are fast.\");\\n\\t}\\n}\\n",
3300 "public class Orc extends Unit {\\n\\tOrc(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tsuper.attack();\\n\\t\\tSystem.out.println(\"My cudgel is cool.\");\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tsuper.defend();\\n\\t\\tSystem.out.println(\"My shield is made of steel.\");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tsuper.move();\\n\\t\\tSystem.out.println(\"My feet are strong.\");\\n\\t}\\n}\\n",
3301 "The program emulates a battle Orc and Elf.\\n\\nOutput:\\n\\nZuzu hits. Strength 4.\\nMy cudgel is cool.\\nZuzu covers his shield. Strength 2.\\nMy shield is made of steel.\\nZuzu takes a step. \\nMy feet are strong.\\n\\nEline hits. Strength 2. Eline hits. Strength 2.\\nMy bow is accurate.\\nEline covers his shield. Strength 1.\\nMy shield is made of diamonds.\\nEline takes a step. Eline takes a step.\\nMy legs are fast.\\n",
3302 "Zuzu hits. Strength 4.\\nMy cudgel is cool.\\nZuzu covers his shield. Strength 2.\\nMy shield is made of steel.\\nZuzu takes a step. \\nMy feet are strong.\\n\\nEline hits. Strength 2. Eline hits. Strength 2.\\nMy bow is accurate.\\nEline covers his shield. Strength 1.\\nMy shield is made of diamonds.\\nEline takes a step. Eline takes a step.\\nMy legs are fast.\\n",
3303 "1",
3304 "3",
3305 "1"
3306 ]
3307 },
3308 {
3309 "-name": "question220",
3310 "item": [
3311 "220",
3312 "44",
3313 "public class Elf extends Unit {\\n\\n\\tElf(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tsuper.attack();\\n\\t\\tSystem.out.println(\"My bow is accurate.\");\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tsuper.defend();\\n\\t\\tSystem.out.println(\"My shield is made of diamonds.\");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tsuper.move();\\n\\t\\tSystem.out.println(\"My legs are fast.\");\\n\\t}\\n}\\n",
3314 "public class Unit {\\n\\tint str;\\n\\tint speed;\\n\\tString name;\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" hits. Strength \" + 2 * str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tSystem.out.println(name + \" covers his shield. Strength \" + str + \". \");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc orc1 = new Orc(2, 1, \"Zuzu\");\\n\\t\\tElf elf1 = new Elf(1, 2, \"Eline\");\\n\\n\\t\\torc1.attack();\\n\\t\\torc1.defend();\\n\\t\\torc1.move();\\n\\t\\tSystem.out.println();\\n\\t\\telf1.attack();\\n\\t\\telf1.defend();\\n\\t\\telf1.move();\\n\\t}\\n}\\n",
3315 "public class Orc extends Unit {\\n\\tOrc(int str, int speed, String name) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tsuper.attack();\\n\\t\\tSystem.out.println(\"My cudgel is cool.\");\\n\\t}\\n\\n\\tpublic void defend() {\\n\\t\\tsuper.defend();\\n\\t\\tSystem.out.println(\"My shield is made of steel.\");\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tsuper.move();\\n\\t\\tSystem.out.println(\"My feet are strong.\");\\n\\t}\\n}\\n",
3316 "The program emulates a battle Orc and Elf.\\n\\nOutput:\\n\\nZuzu hits. Strength 4.\\nMy cudgel is cool.\\nZuzu covers his shield. Strength 2.\\nMy shield is made of steel.\\nZuzu takes a step. \\nMy feet are strong.\\n\\nEline hits. Strength 2. Eline hits. Strength 2.\\nMy bow is accurate.\\nEline covers his shield. Strength 1.\\nMy shield is made of diamonds.\\nEline takes a step. Eline takes a step.\\nMy legs are fast.\\n",
3317 "Zuzu hits. Strength 4.\\nMy cudgel is cool.\\nZuzu covers his shield. Strength 2.\\nMy shield is made of steel.\\nZuzu takes a step. \\nMy feet are strong.\\n\\nEline hits. Strength 2. Eline hits. Strength 2.\\nMy bow is accurate.\\nEline covers his shield. Strength 1.\\nMy shield is made of diamonds.\\nEline takes a step. Eline takes a step.\\nMy legs are fast.\\n",
3318 "1",
3319 "3",
3320 "1"
3321 ]
3322 },
3323 {
3324 "-name": "question221",
3325 "item": [
3326 "221",
3327 "45",
3328 "public class Unit {\\n\\tint str;\\n\\tint speed;\\n\\tint helth;\\n\\tString name;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(1, 2, \"Eline\", 100);\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\", 100);\\n\\n\\t\\telf1.attack();\\n\\t\\telf1.move();\\n\\t\\telf1.selfCure();\\n\\t\\telf1.someBodyCure(elf2);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3329 "public interface Cure {\\n\\tpublic void selfCure();\\n\\n\\tpublic void someBodyCure(Unit unit);\\n}\\n",
3330 "public class Elf extends Unit implements Cure {\\n\\n\\tElf(int str, int speed, String name, int helth) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void selfCure() {\\n\\t\\thelth = helth + 10;\\n\\t\\tSystem.out.println(name + \"'s helth increases to \" + helth);\\n\\t}\\n\\n\\tpublic void someBodyCure(Unit unit) {\\n\\t\\tunit.helth = unit.helth + 20;\\n\\t\\tSystem.out.println(unit.name + \"'s helth increases to \" + unit.helth);\\n\\t}\\n}\\n",
3331 "Elves fight and increase their health.\\n\\nOutput:\\n\\nEline shoots a bow. Strength 1. Eline shoots a bow. Strength 1. \\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3332 "Eline shoots a bow. Strength 1. Eline shoots a bow. Strength 1.\\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3333 "1",
3334 "2",
3335 "63"
3336 ]
3337 },
3338 {
3339 "-name": "question222",
3340 "item": [
3341 "222",
3342 "45",
3343 "public interface Cure {\\n\\tpublic void selfCure();\\n\\n\\tpublic void someBodyCure(Unit unit);\\n}\\n",
3344 "public class Unit {\\n\\tint str;\\n\\tint speed;\\n\\tint helth;\\n\\tString name;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(1, 2, \"Eline\", 100);\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\", 100);\\n\\n\\t\\telf1.attack();\\n\\t\\telf1.move();\\n\\t\\telf1.selfCure();\\n\\t\\telf1.someBodyCure(elf2);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3345 "public class Elf extends Unit implements Cure {\\n\\n\\tElf(int str, int speed, String name, int helth) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void selfCure() {\\n\\t\\thelth = helth + 10;\\n\\t\\tSystem.out.println(name + \"'s helth increases to \" + helth);\\n\\t}\\n\\n\\tpublic void someBodyCure(Unit unit) {\\n\\t\\tunit.helth = unit.helth + 20;\\n\\t\\tSystem.out.println(unit.name + \"'s helth increases to \" + unit.helth);\\n\\t}\\n}\\n",
3346 "Elves fight and increase their health.\\n\\nOutput:\\n\\nEline shoots a bow. Strength 1. Eline shoots a bow. Strength 1. \\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3347 "Eline shoots a bow. Strength 1. Eline shoots a bow. Strength 1.\\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3348 "1",
3349 "1",
3350 "1"
3351 ]
3352 },
3353 {
3354 "-name": "question223",
3355 "item": [
3356 "223",
3357 "45",
3358 "public class Elf extends Unit implements Cure {\\n\\n\\tElf(int str, int speed, String name, int helth) {\\n\\t\\tthis.str = str;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t}\\n\\n\\tpublic void attack() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" shoots a bow. Strength \" + str + \". \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void move() {\\n\\t\\tfor (int i = 0; i < speed; i++) {\\n\\t\\t\\tSystem.out.print(name + \" takes a step. \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void selfCure() {\\n\\t\\thelth = helth + 10;\\n\\t\\tSystem.out.println(name + \"'s helth increases to \" + helth);\\n\\t}\\n\\n\\tpublic void someBodyCure(Unit unit) {\\n\\t\\tunit.helth = unit.helth + 20;\\n\\t\\tSystem.out.println(unit.name + \"'s helth increases to \" + unit.helth);\\n\\t}\\n}\\n",
3359 "public class Unit {\\n\\tint str;\\n\\tint speed;\\n\\tint helth;\\n\\tString name;\\n\\n\\tpublic void attack() {\\n\\t}\\n\\n\\tpublic void move() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(1, 2, \"Eline\", 100);\\n\\t\\tElf elf2 = new Elf(1, 2, \"Elon\", 100);\\n\\n\\t\\telf1.attack();\\n\\t\\telf1.move();\\n\\t\\telf1.selfCure();\\n\\t\\telf1.someBodyCure(elf2);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3360 "public interface Cure {\\n\\tpublic void selfCure();\\n\\n\\tpublic void someBodyCure(Unit unit);\\n}\\n",
3361 "Elves fight and increase their health.\\n\\nOutput:\\n\\nEline shoots a bow. Strength 1. Eline shoots a bow. Strength 1. \\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3362 "Eline shoots a bow. Strength 1. Eline shoots a bow. Strength 1.\\nEline takes a step. Eline takes a step.\\nEline's helth increases to 110\\nElon's helth increases to 120\\n",
3363 "1",
3364 "3",
3365 "1"
3366 ]
3367 },
3368 {
3369 "-name": "question224",
3370 "item": [
3371 "224",
3372 "45",
3373 "public class Mag implements MagS, Cure {\\n\\n\\tint helth;\\n\\tString name;\\n\\n\\tMag(String name, int helth) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tMag mag1 = new Mag(\"Voldemort\", 100);\\n\\t\\tMag mag2 = new Mag(\"Dumbledore\", 100);\\n\\n\\t\\tmag2.selfCure();\\n\\t\\tmag2.someBodyCure(mag1);\\n\\t\\tmag2.someBodyBern(mag1);\\n\\t\\tmag2.someBodyHurt(mag1);\\n\\t\\tmag1.someBodyHurt(mag2);\\n\\t}\\n\\n\\tpublic void selfCure() {\\n\\t\\thelth = helth + 10;\\n\\t\\tSystem.out.print(name + \" heals itself. \");\\n\\t\\tSystem.out.println(name + \"'s helth is \" + helth);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void someBodyCure(Mag mag) {\\n\\t\\tmag.helth = mag.helth + 20;\\n\\t\\tSystem.out.print(name + \" heals. \");\\n\\t\\tSystem.out.println(mag.name + \"'s helth is \" + mag.helth);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void someBodyBern(Mag mag) {\\n\\t\\tmag.helth = mag.helth - 30;\\n\\t\\tSystem.out.print(name + \" burns. \");\\n\\t\\tSystem.out.println(mag.name + \"'s helth is \" + mag.helth);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void someBodyHurt(Mag mag) {\\n\\t\\tmag.helth = mag.helth - 10;\\n\\t\\tSystem.out.print(name + \" hits. \");\\n\\t\\tSystem.out.println(mag.name + \"'s helth is \" + mag.helth);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3374 "public interface Cure {\\n\\tpublic void selfCure();\\n\\n\\tpublic void someBodyCure(Mag mag);\\n}\\n",
3375 "public interface MagS {\\n\\tpublic void someBodyBern(Mag mag);\\n\\n\\tpublic void someBodyHurt(Mag mag);\\n}\\n",
3376 "The program emulates a battle Dumbledore and Voldemort.\\n\\nOutput:\\n\\nDumbledore heals itself. Dumbledore's helth is 110\\n\\nDumbledore heals. Voldemort's helth is 120\\n\\nDumbledore burns. Voldemort's helth is 90\\n\\nDumbledore hits. Voldemort's helth is 80\\n\\nVoldemort hits. Dumbledore's helth is 100\\n",
3377 "Dumbledore heals itself. Dumbledore's helth is 110\\n\\nDumbledore heals. Voldemort's helth is 120\\n\\nDumbledore burns. Voldemort's helth is 90\\n\\nDumbledore hits. Voldemort's helth is 80\\n\\nVoldemort hits. Dumbledore's helth is 100\\n",
3378 "1",
3379 "3",
3380 "1"
3381 ]
3382 },
3383 {
3384 "-name": "question225",
3385 "item": [
3386 "225",
3387 "45",
3388 "public class King implements Inv {\\n\\tint strength;\\n\\tint helth;\\n\\tint magic;\\n\\tString name;\\n\\n\\tKing(int strength, int helth, int magic, String name) {\\n\\t\\tthis.strength = strength;\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeThemselvesInvisible() {\\n\\t\\tif (magic > 40) {\\n\\t\\t\\tSystem.out.println(name + \" becomes invisible\");\\n\\t\\t\\tmagic = magic - 40;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic void makeThemselvesVisible() {\\n\\t\\tif (magic > 30) {\\n\\t\\t\\tSystem.out.println(name + \" becomes visible\");\\n\\t\\t\\tmagic = magic - 30;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tKing king1 = new King(6, 100, 100, \"Arthur\");\\n\\t\\tHag hag1 = new Hag(100, 100, \"Elena\");\\n\\n\\t\\tking1.makeThemselvesInvisible();\\n\\t\\thag1.makeThemselvesInvisible();\\n\\t\\tSystem.out.println();\\n\\t\\tking1.makeThemselvesVisible();\\n\\t\\thag1.makeThemselvesVisible();\\n\\t\\tSystem.out.println();\\n\\t\\tking1.makeThemselvesInvisible();\\n\\t\\thag1.makeThemselvesInvisible();\\n\\t}\\n}\\n",
3389 "public class Hag implements Inv {\\n\\tint helth;\\n\\tint magic;\\n\\tString name;\\n\\n\\tHag(int helth, int magic, String name) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeThemselvesInvisible() {\\n\\t\\tif (magic > 20) {\\n\\t\\t\\tSystem.out.println(name + \" becomes invisible\");\\n\\t\\t\\tmagic = magic - 20;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"Not enough magic\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic void makeThemselvesVisible() {\\n\\t\\tif (magic > 10) {\\n\\t\\t\\tSystem.out.println(name + \" becomes visible\");\\n\\t\\t\\tmagic = magic - 10;\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"It is not enough magic\");\\n\\t\\t}\\n\\t}\\n}\\n",
3390 "public interface Inv {\\n\\tpublic void makeThemselvesInvisible();\\n\\n\\tpublic void makeThemselvesVisible();\\n}\\n",
3391 "The program emulates a play the king and the hag.\\n\\nOutput:\\n\\nArthur becomes invisible\\nElena becomes invisible\\n\\nArthur becomes visible\\nElena becomes visible\\n\\nArthur has not enough magic\\nElena becomes invisible\\n",
3392 "Arthur becomes invisible\\nElena becomes invisible\\n\\nArthur becomes visible\\nElena becomes visible\\n\\nArthur has not enough magic\\nElena becomes invisible\\n",
3393 "1",
3394 "3",
3395 "1"
3396 ]
3397 },
3398 {
3399 "-name": "question226",
3400 "item": [
3401 "226",
3402 "46",
3403 "public class King implements Dilly {\\n\\tint helth, magic;\\n\\tString name;\\n\\n\\tKing(int helth, int magic, String name) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSomeBodyHurt(King king) {\\n\\t\\tif (magic > 40) {\\n\\t\\t\\tSystem.out.println(\"King \" + name + \" attacks.\");\\n\\t\\t\\tmagic = magic - 40;\\n\\t\\t\\tking.helth = king.helth - 10;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(king.name + \"'s helth is \" + king.helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void cureThemself() {\\n\\t\\tSystem.out.println(\"King \" + name + \" heals himself.\");\\n\\t\\tif (magic >= 70) {\\n\\t\\t\\tmagic = magic - 70;\\n\\t\\t\\thelth = helth + 30;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(name + \"'s helth is \" + helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tKing king1 = new King(100, 100, \"Arthur\");\\n\\n\\t\\tDilly massive[] = new Dilly[5];\\n\\t\\tmassive[0] = new Hag(100, 100, \"Elena\");\\n\\t\\tmassive[1] = new Hag(100, 100, \"Helga\");\\n\\t\\tmassive[2] = new Hag(100, 100, \"Rata\");\\n\\t\\tmassive[3] = new Hag(100, 100, \"Sarah\");\\n\\t\\tmassive[4] = new King(100, 100, \"Richard\");\\n\\t\\tfor (Dilly d : massive) {\\n\\t\\t\\td.makeSomeBodyHurt(king1);\\n\\t\\t}\\n\\t\\tking1.cureThemself();\\n\\t\\tking1.cureThemself();\\n\\t}\\n}\\n",
3404 "public class Hag implements Dilly {\\n\\n\\tint helth;\\n\\tint magic;\\n\\tString name;\\n\\n\\tHag(int helth, int magic, String name) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSomeBodyHurt(King king) {\\n\\t\\tif (magic > 30) {\\n\\t\\t\\tSystem.out.println(\"Hag \" + name + \" attacks.\");\\n\\t\\t\\tmagic = magic - 30;\\n\\t\\t\\tking.helth = king.helth - 10;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(king.name + \"'s helth is \" + king.helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void cureThemself() {\\n\\t\\tif (magic > 40) {\\n\\t\\t\\tSystem.out.println(\"Hag \" + name + \" heals herself.\");\\n\\t\\t\\tmagic = magic - 40;\\n\\t\\t\\thelth = helth + 40;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(name + \"'s helth is \" + helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t}\\n}\\n",
3405 "public interface Dilly {\\n\\tpublic void makeSomeBodyHurt(King king);\\n\\n\\tpublic void cureThemself\\n}\\n",
3406 "King Arthur was attacked by king Richard and 4 witches. King Arthur heals himself.\\n\\nOutput:\\n\\nHag Elena attacks.\\nElena's magic is 70. Arthur's helth is 90.\\n\\nHag Helga attacks.\\nHelga's magic is 70. Arthur's helth is 80.\\n\\nHag Rata attacks.\\nRata's magic is 70. Arthur's helth is 70.\\n\\nHag Sarah attacks.\\nSarah's magic is 70. Arthur's helth is 60.\\n\\nKing Richard attacks.\\nRichard's magic is 60. Arthur's helth is 50.\\n\\nKing Arthur heals himself. \\nArthur's magic is 30. Arthur's is helth 80.\\n\\nKing Arthur heals himself. \\nArthur has not enough magic.\\n",
3407 "Hag Elena attacks.\\nElena's magic is 70. Arthur's helth is 90.\\n\\nHag Helga attacks.\\nHelga's magic is 70. Arthur's helth is 80.\\n\\nHag Rata attacks.\\nRata's magic is 70. Arthur's helth is 70.\\n\\nHag Sarah attacks.\\nSarah's magic is 70. Arthur's helth is 60.\\n\\nKing Richard attacks.\\nRichard's magic is 60. Arthur's helth is 50.\\n\\nKing Arthur heals himself. \\nArthur's magic is 30. Arthur's is helth 80.\\n\\nKing Arthur heals himself. \\nArthur has not enough magic.\\n",
3408 "1",
3409 "3",
3410 "395"
3411 ]
3412 },
3413 {
3414 "-name": "question227",
3415 "item": [
3416 "227",
3417 "46",
3418 "public class Hag implements Dilly {\\n\\n\\tint helth;\\n\\tint magic;\\n\\tString name;\\n\\n\\tHag(int helth, int magic, String name) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSomeBodyHurt(King king) {\\n\\t\\tif (magic > 30) {\\n\\t\\t\\tSystem.out.println(\"Hag \" + name + \" attacks.\");\\n\\t\\t\\tmagic = magic - 30;\\n\\t\\t\\tking.helth = king.helth - 10;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(king.name + \"'s helth is \" + king.helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void cureThemself() {\\n\\t\\tif (magic > 40) {\\n\\t\\t\\tSystem.out.println(\"Hag \" + name + \" heals herself.\");\\n\\t\\t\\tmagic = magic - 40;\\n\\t\\t\\thelth = helth + 40;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(name + \"'s helth is \" + helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t}\\n}\\n",
3419 "public class King implements Dilly {\\n\\tint helth, magic;\\n\\tString name;\\n\\n\\tKing(int helth, int magic, String name) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void makeSomeBodyHurt(King king) {\\n\\t\\tif (magic > 40) {\\n\\t\\t\\tSystem.out.println(\"King \" + name + \" attacks.\");\\n\\t\\t\\tmagic = magic - 40;\\n\\t\\t\\tking.helth = king.helth - 10;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(king.name + \"'s helth is \" + king.helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic void cureThemself() {\\n\\t\\tSystem.out.println(\"King \" + name + \" heals himself.\");\\n\\t\\tif (magic >= 70) {\\n\\t\\t\\tmagic = magic - 70;\\n\\t\\t\\thelth = helth + 30;\\n\\t\\t\\tSystem.out.print(name + \"'s magic is \" + magic + \".\");\\n\\t\\t\\tSystem.out.println(name + \"'s helth is \" + helth + \".\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(name + \" has not enough magic.\");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tKing king1 = new King(100, 100, \"Arthur\");\\n\\n\\t\\tDilly massive[] = new Dilly[5];\\n\\t\\tmassive[0] = new Hag(100, 100, \"Elena\");\\n\\t\\tmassive[1] = new Hag(100, 100, \"Helga\");\\n\\t\\tmassive[2] = new Hag(100, 100, \"Rata\");\\n\\t\\tmassive[3] = new Hag(100, 100, \"Sarah\");\\n\\t\\tmassive[4] = new King(100, 100, \"Richard\");\\n\\t\\tfor (Dilly d : massive) {\\n\\t\\t\\td.makeSomeBodyHurt(king1);\\n\\t\\t}\\n\\t\\tking1.cureThemself();\\n\\t\\tking1.cureThemself();\\n\\t}\\n}\\n",
3420 "public interface Dilly {\\n\\tpublic void makeSomeBodyHurt(King king);\\n\\n\\tpublic void cureThemself\\n}\\n",
3421 "King Arthur was attacked by king Richard and 4 witches. King Arthur heals himself.\\n\\nOutput:\\n\\nHag Elena attacks.\\nElena's magic is 70. Arthur's helth is 90.\\n\\nHag Helga attacks.\\nHelga's magic is 70. Arthur's helth is 80.\\n\\nHag Rata attacks.\\nRata's magic is 70. Arthur's helth is 70.\\n\\nHag Sarah attacks.\\nSarah's magic is 70. Arthur's helth is 60.\\n\\nKing Richard attacks.\\nRichard's magic is 60. Arthur's helth is 50.\\n\\nKing Arthur heals himself. \\nArthur's magic is 30. Arthur's is helth 80.\\n\\nKing Arthur heals himself. \\nArthur has not enough magic.\\n",
3422 "Hag Elena attacks.\\nElena's magic is 70. Arthur's helth is 90.\\n\\nHag Helga attacks.\\nHelga's magic is 70. Arthur's helth is 80.\\n\\nHag Rata attacks.\\nRata's magic is 70. Arthur's helth is 70.\\n\\nHag Sarah attacks.\\nSarah's magic is 70. Arthur's helth is 60.\\n\\nKing Richard attacks.\\nRichard's magic is 60. Arthur's helth is 50.\\n\\nKing Arthur heals himself. \\nArthur's magic is 30. Arthur's is helth 80.\\n\\nKing Arthur heals himself. \\nArthur has not enough magic.\\n",
3423 "1",
3424 "3",
3425 "68"
3426 ]
3427 },
3428 {
3429 "-name": "question228",
3430 "item": [
3431 "228",
3432 "46",
3433 "public class Fay implements Joy {\\n\\tString name;\\n\\tint magic;\\n\\n\\tFay(String name, int magic) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.magic = magic;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Fay \" + name + \" dances, magic grows to \" + magic);\\n\\t}\\n\\n\\tpublic void hug() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Fay \" + name + \" hugs, magic grows to \" + magic);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tJoy mass[] = new Joy[6];\\n\\t\\tmass[0] = new Fay(\"Alice\", 50);\\n\\t\\tmass[1] = new Elf(\"Elain\", 100);\\n\\t\\tmass[2] = new Fay(\"Julia\", 50);\\n\\t\\tmass[3] = new Elf(\"Elon\", 100);\\n\\t\\tmass[4] = new Fay(\"Bella\", 50);\\n\\t\\tmass[5] = new Elf(\"Ilot\", 100);\\n\\t\\tfor (Joy d : mass) {\\n\\t\\t\\td.dance();\\n\\t\\t\\td.hug();\\n\\t\\t}\\n\\t}\\n}\\n",
3434 "public class Elf implements Joy {\\n\\n\\tString name;\\n\\tint str;\\n\\n\\tElf(String name, int str) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.str = str;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Elf \" + name + \" dances, strength grows to \" + str);\\n\\t}\\n\\n\\tpublic void hug() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Elf \" + name + \" hugs, strength grows to \" + str);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3435 "public interface Joy {\\n\\tpublic void dance();\\n\\n\\tpublic void hug();\\n}\\n",
3436 "Fairies and Elves dance and hug. Magic of fairies grows. Strength of elves grows.\\n\\nOutput:\\n\\nFay Alice dances, magic grows to 55\\nFay Alice hugs, magic grows to 60\\n\\nElf Elain dances, strength grows to 105\\nElf Elain hugs, strength grows to 110\\n\\nFay Julia dances, magic grows to 55\\nFay Julia hugs, magic grows to 60\\n\\nElf Elon dances, strength grows to 105\\nElf Elon hugs, strength grows to 110\\n\\nFay Bella dances, magic grows to 55\\nFay Bella hugs, magic grows to 60\\n\\nElf Ilot dances, strength grows to 105\\nElf Ilot hugs, strength grows to 110\\n",
3437 "Fay Alice dances, magic grows to 55\\nFay Alice hugs, magic grows to 60\\n\\nElf Elain dances, strength grows to 105\\nElf Elain hugs, strength grows to 110\\n\\nFay Julia dances, magic grows to 55\\nFay Julia hugs, magic grows to 60\\n\\nElf Elon dances, strength grows to 105\\nElf Elon hugs, strength grows to 110\\n\\nFay Bella dances, magic grows to 55\\nFay Bella hugs, magic grows to 60\\n\\nElf Ilot dances, strength grows to 105\\nElf Ilot hugs, strength grows to 110\\n",
3438 "1",
3439 "3",
3440 "166"
3441 ]
3442 },
3443 {
3444 "-name": "question229",
3445 "item": [
3446 "229",
3447 "46",
3448 "public class Elf implements Joy {\\n\\n\\tString name;\\n\\tint str;\\n\\n\\tElf(String name, int str) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.str = str;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Elf \" + name + \" dances, strength grows to \" + str);\\n\\t}\\n\\n\\tpublic void hug() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Elf \" + name + \" hugs, strength grows to \" + str);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3449 "public class Fay implements Joy {\\n\\tString name;\\n\\tint magic;\\n\\n\\tFay(String name, int magic) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.magic = magic;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Fay \" + name + \" dances, magic grows to \" + magic);\\n\\t}\\n\\n\\tpublic void hug() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Fay \" + name + \" hugs, magic grows to \" + magic);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tJoy mass[] = new Joy[6];\\n\\t\\tmass[0] = new Fay(\"Alice\", 50);\\n\\t\\tmass[1] = new Elf(\"Elain\", 100);\\n\\t\\tmass[2] = new Fay(\"Julia\", 50);\\n\\t\\tmass[3] = new Elf(\"Elon\", 100);\\n\\t\\tmass[4] = new Fay(\"Bella\", 50);\\n\\t\\tmass[5] = new Elf(\"Ilot\", 100);\\n\\t\\tfor (Joy d : mass) {\\n\\t\\t\\td.dance();\\n\\t\\t\\td.hug();\\n\\t\\t}\\n\\t}\\n}\\n",
3450 "public interface Joy {\\n\\tpublic void dance();\\n\\n\\tpublic void hug();\\n}\\n",
3451 "Fairies and Elves dance and hug. Magic of fairies grows. Strength of elves grows.\\n\\nOutput:\\n\\nFay Alice dances, magic grows to 55\\nFay Alice hugs, magic grows to 60\\n\\nElf Elain dances, strength grows to 105\\nElf Elain hugs, strength grows to 110\\n\\nFay Julia dances, magic grows to 55\\nFay Julia hugs, magic grows to 60\\n\\nElf Elon dances, strength grows to 105\\nElf Elon hugs, strength grows to 110\\n\\nFay Bella dances, magic grows to 55\\nFay Bella hugs, magic grows to 60\\n\\nElf Ilot dances, strength grows to 105\\nElf Ilot hugs, strength grows to 110\\n",
3452 "Fay Alice dances, magic grows to 55\\nFay Alice hugs, magic grows to 60\\n\\nElf Elain dances, strength grows to 105\\nElf Elain hugs, strength grows to 110\\n\\nFay Julia dances, magic grows to 55\\nFay Julia hugs, magic grows to 60\\n\\nElf Elon dances, strength grows to 105\\nElf Elon hugs, strength grows to 110\\n\\nFay Bella dances, magic grows to 55\\nFay Bella hugs, magic grows to 60\\n\\nElf Ilot dances, strength grows to 105\\nElf Ilot hugs, strength grows to 110\\n",
3453 "1",
3454 "2",
3455 "1"
3456 ]
3457 },
3458 {
3459 "-name": "question230",
3460 "item": [
3461 "230",
3462 "46",
3463 "public class Hag implements Rage {\\n\\tString name;\\n\\tint magic;\\n\\n\\tHag(String name, int magic) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.magic = magic;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Hag \" + name + \" dances, magic grows \" + magic);\\n\\t}\\n\\n\\tpublic void fly() {\\n\\t\\tmagic = magic + 5;\\n\\t\\tSystem.out.println(\"Hag \" + name + \" flies, magic grows \" + magic);\\n\\t\\tSystem.out.println();\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tRage mass[] = new Rage[6];\\n\\t\\tmass[0] = new Hag(\"Helga\", 50);\\n\\t\\tmass[1] = new Troll(\"Zozo\", 100);\\n\\t\\tmass[2] = new Hag(\"Elena\", 50);\\n\\t\\tmass[3] = new Troll(\"Zuzu\", 100);\\n\\t\\tmass[4] = new Hag(\"Sara\", 50);\\n\\t\\tmass[5] = new Troll(\"Puck\", 100);\\n\\t\\tfor (Rage d : mass) {\\n\\t\\t\\td.dance();\\n\\t\\t\\td.fly();\\n\\t\\t}\\n\\t}\\n}\\n",
3464 "public class Troll implements Rage {\\n\\n\\tString name;\\n\\tint str;\\n\\n\\tTroll(String name, int str) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.str = str;\\n\\t}\\n\\n\\tpublic void dance() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Troll \" + name + \" dances, strength grows \" + str);\\n\\t}\\n\\n\\tpublic void fly() {\\n\\t\\tstr = str + 5;\\n\\t\\tSystem.out.println(\"Troll \" + name + \" flies, strength grows \" + str);\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3465 "public interface Rage {\\n\\tpublic void fly();\\n\\n\\tpublic void dance();\\n}\\n",
3466 "Hags and trolls dance and fly. Magic of hags grows. Strength of trolls grows.\\n\\nOutput:\\n\\nHag Helga dances, magic grows 55\\nHag Helga flies, magic grows 60\\n\\nTroll Zozo dances, strength grows 105\\nTroll Zozo flies, strength grows 110\\n\\nHag Elena dances, magic grows 55\\nHag Elena flies, magic grows 60\\n\\nTroll Zuzu dances, strength grows 105\\nTroll Zuzu flies, strength grows 110\\n\\nHag Sara dances, magic grows 55\\nHag Sara flies, magic grows 60\\n\\nTroll Puck dances, strength grows 105\\nTroll Puck flies, strength grows 110\\n",
3467 "Hag Helga dances, magic grows 55\\nHag Helga flies, magic grows 60\\n\\nTroll Zozo dances, strength grows 105\\nTroll Zozo flies, strength grows 110\\n\\nHag Elena dances, magic grows 55\\nHag Elena flies, magic grows 60\\n\\nTroll Zuzu dances, strength grows 105\\nTroll Zuzu flies, strength grows 110\\n\\nHag Sara dances, magic grows 55\\nHag Sara flies, magic grows 60\\n\\nTroll Puck dances, strength grows 105\\nTroll Puck flies, strength grows 110\\n\\n",
3468 "1",
3469 "3",
3470 "166"
3471 ]
3472 },
3473 {
3474 "-name": "question231",
3475 "item": [
3476 "231",
3477 "47",
3478 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka = \"Hello\";\\n\\t\\tString massiv[] = { \"dad\", \"mum\", \"daughter\" };\\n\\t\\tCar car1 = new Car(100, \"KIA\");\\n\\t\\tCar car2 = new Car(100, \"KIA\");\\n\\t\\tObject ob = new Object();\\n\\n\\t\\tSystem.out.println(stroka.hashCode());\\n\\t\\tSystem.out.println(massiv.hashCode());\\n\\t\\tSystem.out.println(car1.hashCode());\\n\\t\\tSystem.out.println(car2.hashCode());\\n\\t\\tSystem.out.println(ob.hashCode());\\n\\t}\\n}\\n",
3479 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3480 "The program displays hash-codes of string, of array, of object of type car, of the object of type Object.\\n\\nOutput:\\n\\n1177014952\\n18019860\\n31054905\\n605645\\n12097592\\n",
3481 "1177014952\\n18019860\\n31054905\\n605645\\n12097592\\n",
3482 "1",
3483 "1",
3484 "84"
3485 ]
3486 },
3487 {
3488 "-name": "question232",
3489 "item": [
3490 "232",
3491 "47",
3492 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint stroka[] = { 3, 43, 6 };\\n\\t\\tString massiv[] = { \"dad\", \"mum\", \"daughter\" };\\n\\t\\tCar car1 = new Car(100, \"KIA\");\\n\\t\\tCar car2 = new Car(100, \"KIA\");\\n\\t\\tObject ob = new Object();\\n\\n\\t\\tSystem.out.println(stroka.toString());\\n\\t\\tSystem.out.println(massiv.toString());\\n\\t\\tSystem.out.println(car1.toString());\\n\\t\\tSystem.out.println(car2.toString());\\n\\t\\tSystem.out.println(ob.toString());\\n\\t}\\n}\\n",
3493 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3494 "The program shows the operations of the toString method. The data are output in the following order: class names, sign \"@ \", hash codes.\\n\\nOutput:\\n\\n[I@422ede\\n[Ljava.lang.String;@112f614\\nCar@1d9dc39\\nCar@93dcd\\njava.lang.Object@b89838\\n",
3495 "[I@422ede\\n[Ljava.lang.String;@112f614\\nCar@1d9dc39\\nCar@93dcd\\njava.lang.Object@b89838\\n",
3496 "1",
3497 "1",
3498 "92"
3499 ]
3500 },
3501 {
3502 "-name": "question233",
3503 "item": [
3504 "233",
3505 "47",
3506 "public class Ship {\\n\\tint speed;\\n\\tString name;\\n\\n\\tShip(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tObject car = new Car(100, \"KIA\");\\n\\t\\tObject tank = new Tank(60, \"T34\", 85);\\n\\t\\tObject ship = new Ship(80, \"Cruiser\");\\n\\n\\t\\tObject massiv[] = new Object[3];\\n\\t\\tmassiv[0] = car;\\n\\t\\tmassiv[1] = tank;\\n\\t\\tmassiv[2] = ship;\\n\\n\\t\\tfor (Object ob : massiv) {\\n\\t\\t\\tSystem.out.println(ob.toString());\\n\\t\\t}\\n\\t}\\n}\\n",
3507 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name)\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3508 "public class Tank {\\n\\tint speed;\\n\\tString name;\\n\\tint gun;\\n\\n\\tTank(int speed, String name, int gun) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t\\tthis.gun = gun;\\n\\t}\\n}\\n",
3509 "The program declares all objects of all types as objects of type Object. The program creates an array of these objects and then uses toString method to all objects in the array.\\n\\nOutput:\\n\\nCar@112f614\\nTank@1d9dc39\\nShip@93dcd\\n",
3510 "Car@112f614\\nTank@1d9dc39\\nShip@93dcd\\n",
3511 "1",
3512 "2",
3513 "107"
3514 ]
3515 },
3516 {
3517 "-name": "question234",
3518 "item": [
3519 "234",
3520 "47",
3521 "public class Ship {\\n\\tint speed;\\n\\tString name;\\n\\n\\tShip(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tObject massiv[] = new Object[3];\\n\\t\\tmassiv[0] = new Car(100, \"KIA\");\\n\\t\\tmassiv[1] = new Tank(60, \"T34\", 85);\\n\\t\\tmassiv[2] = new Ship(80, \"Cruiser\");\\n\\n\\t\\tSystem.out.println(((Car) massiv[0]).name);\\n\\t\\tSystem.out.println(((Tank) massiv[1]).name);\\n\\t\\tSystem.out.println(((Ship) massiv[2]).name);\\n\\t}\\n}\\n",
3522 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3523 "public class Tank {\\n\\tint speed;\\n\\tString name;\\n\\tint gun;\\n\\n\\tTank(int speed, String name, int gun) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t\\tthis.gun = gun;\\n\\t}\\n}\\n",
3524 "The program declares all objects of all types as objects of type Object. Тhe program creates an array of these objects, and then displays names of objects, previously brought them to their types.\\n\\nOutput:\\n\\nKIA\\nT34\\nCruiser\\n",
3525 "KIA\\nT34\\nCruiser\\n",
3526 "1",
3527 "2",
3528 "62"
3529 ]
3530 },
3531 {
3532 "-name": "question235",
3533 "item": [
3534 "235",
3535 "47",
3536 "public class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka = \"Hello\";\\n\\t\\tString massiv[] = { \"dad\", \"mum\", \"daughter\" };\\n\\t\\tCar car1 = new Car(100, \"KIA\");\\n\\t\\tCar car2 = new Car(100, \"KIA\");\\n\\t\\tCar car3 = car1;\\n\\n\\t\\tSystem.out.println(stroka.equals(\"Hello\"));\\n\\t\\tSystem.out.println(stroka.equals(massiv));\\n\\t\\tSystem.out.println(car1.equals(car2));\\n\\t\\tSystem.out.println(car1.equals(car2));\\n\\t\\tSystem.out.println(car1.equals(car3));\\n\\t}\\n}\\n",
3537 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3538 "The program shows work of equals method with different types of data.\\n\\nOutput:\\n\\ntrue\\nfalse\\nfalse\\nfalse\\ntrue\\n",
3539 "true\\nfalse\\nfalse\\nfalse\\ntrue\\n",
3540 "1",
3541 "1",
3542 "81"
3543 ]
3544 },
3545 {
3546 "-name": "question236",
3547 "item": [
3548 "236",
3549 "48",
3550 "public class Main { // exception ArithmeticException\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint a = 0;\\n\\t\\tString stroka = \"a = 0. It is impossible to divide by 0\";\\n\\t\\tString strokacont = \"Continue to work. c = \";\\n\\t\\tint b = 7;\\n\\t\\tint c = 0;\\n\\t\\ttry {\\n\\t\\t\\tc = b / a;\\n\\t\\t} catch (ArithmeticException e) {\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t\\tc = b;\\n\\t\\t} finally {\\n\\t\\t\\tSystem.out.println(strokacont + c);\\n\\t\\t}\\n\\t}\\n}\\n",
3551 "The program generates ArithmeticException and handles this exception.\\n\\nOutput:\\n\\na = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nContinue to work. c = 7\\n",
3552 "a = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nContinue to work. c = 7\\n",
3553 "1",
3554 "2",
3555 "80"
3556 ]
3557 },
3558 {
3559 "-name": "question237",
3560 "item": [
3561 "237",
3562 "48",
3563 "public class Main { // Exception ArrayIndexOutOfBoundsException\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint a[] = { 5, 2, 54, 23 };\\n\\t\\tString stroka = \"The element а[4] does not exist, the last element of the array is а[3]\";\\n\\t\\tString strokacont = \"Continue to work. Ñ = \";\\n\\t\\tint c;\\n\\t\\ttry {\\n\\t\\t\\tc = a[4];\\n\\t\\t} catch (ArrayIndexOutOfBoundsException e) {\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t\\tc = a[3];\\n\\t\\t}\\n\\t\\tSystem.out.println(strokacont + c);\\n\\t}\\n}\\n",
3564 "The program generates ArrayIndexOutOfBoundsException and handles this exception.\\n\\nOutput:\\n\\nThe element а[4] does not exist, the last element of the array is а[3]\\nThe exception is java.lang.ArrayIndexOutOfBoundsException: 4\\nContinue to work. Ñ = 23\\n",
3565 "The element а[4] does not exist, the last element of the array is а[3]\\nThe exception is java.lang.ArrayIndexOutOfBoundsException: 4\\nContinue to work. Ñ = 23\\n",
3566 "1",
3567 "2",
3568 "92"
3569 ]
3570 },
3571 {
3572 "-name": "question238",
3573 "item": [
3574 "238",
3575 "48",
3576 "public class Main {// Exception ArrayStoreException\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka1 = \"You can not assign a string value to an array element,\";\\n\\t\\tString stroka2 = \"if that element is composed of objects of type Car.\";\\n\\t\\tString strokacont = \"The program continues to run.\";\\n\\n\\t\\tObject carMassive[] = new Car[3];\\n\\n\\t\\ttry {\\n\\t\\t\\tcarMassive[0] = \"Peter\";\\n\\t\\t} catch (ArrayStoreException e) {\\n\\t\\t\\tSystem.out.println(stroka1);\\n\\t\\t\\tSystem.out.println(stroka2);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t\\tcarMassive[0] = new Car(120, \"Toyota\");\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t\\tSystem.out.println(strokacont);\\n\\t}\\n}\\n",
3577 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3578 "The program generates ArrayStoreException and handles this exception.\\n\\nOutput:\\n\\nYou can not assign a string value to an array element,\\nif that element is composed of objects of type Car.\\nThe exception is java.lang.ArrayStoreException: java.lang.String\\n\\nThe program continues to run.\\n",
3579 "You can not assign a string value to an array element,\\nif that element is composed of objects of type Car.\\nThe exception is java.lang.ArrayStoreException: java.lang.String\\n\\nThe program continues to run.\\n",
3580 "1",
3581 "2",
3582 "94"
3583 ]
3584 },
3585 {
3586 "-name": "question239",
3587 "item": [
3588 "239",
3589 "48",
3590 "public class Main {// Exception ClassCastException\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka1 = \"You can not bring the array element of type Car\";\\n\\t\\tString stroka2 = \"to a string, integer and other variables.\";\\n\\t\\tString strokacont = \"The program continues to run.\";\\n\\n\\t\\tObject carMassive[] = new Car[3];\\n\\t\\tcarMassive[0] = new Car(120, \"Toyota\");\\n\\t\\ttry {\\n\\t\\t\\tSystem.out.println((String) carMassive[0]);\\n\\t\\t} catch (ClassCastException e) {\\n\\t\\t\\tSystem.out.println(stroka1);\\n\\t\\t\\tSystem.out.println(stroka2);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t\\tSystem.out.println(strokacont);\\n\\t}\\n}\\n",
3591 "public class Car {\\n\\tint speed;\\n\\tString name;\\n\\n\\tCar(int speed, String name) {\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
3592 "The program generates ClassCastException and handles this exception.\\n\\nOutput:\\n\\nYou can not bring the array element of type Car\\nto a string, integer and other variables.\\nThe exception is java.lang.ClassCastException: Car cannot be cast to java.lang.String\\n\\nThe program continues to run.\\n",
3593 "You can not bring the array element of type Car\\nto a string, integer and other variables.\\nThe exception is java.lang.ClassCastException: Car cannot be cast to java.lang.String\\n\\nThe program continues to run.\\n",
3594 "1",
3595 "2",
3596 "104"
3597 ]
3598 },
3599 {
3600 "-name": "question240",
3601 "item": [
3602 "240",
3603 "48",
3604 "public class Main { // Exception \\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tint a = 0;\\n\\t\\tString stroka = \"a = 0. It is impossible to divide by 0\";\\n\\t\\tString strokacont = \"Continue to work. Ñ=\";\\n\\t\\tint b = 7;\\n\\t\\tint c = 0;\\n\\t\\ttry {\\n\\t\\t\\tc = b / a;\\n\\t\\t} catch (Exception e) {\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t\\tc = b;\\n\\t\\t} finally {\\n\\t\\t\\tSystem.out.println(strokacont + c);\\n\\t\\t}\\n\\t}\\n}\\n",
3605 "The program generates the universal exception and handles this exception.\\n\\nOutput:\\n\\na = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nContinue to work. Ñ=7\\n",
3606 "a = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nContinue to work. Ñ=7\\n",
3607 "1",
3608 "2",
3609 "78"
3610 ]
3611 },
3612 {
3613 "-name": "question241",
3614 "item": [
3615 "241",
3616 "49",
3617 "public class Main { // \"throw\" throws\\n\\tstatic int cigma;\\n\\tstatic int beta = 7;\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tString stroka = \"a = 0. It is impossible to divide by 0\";\\n\\t\\tString strokacont = (\"The program continues to run. cigma=\" + beta);\\n\\t\\ttry {\\n\\t\\t\\tmethod1();\\n\\t\\t} catch (ArithmeticException e) {\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t\\tSystem.out.println(\"The exception is \" + e);\\n\\t\\t}\\n\\t\\tSystem.out.println(strokacont);\\n\\t}\\n\\n\\tpublic static void method1() throws ArithmeticException {\\n\\t\\tint a = 0;\\n\\t\\tcigma = beta / a;\\n\\t}\\n}\\n",
3618 "The program generates ArithmeticException in the method method1. The program \"throws\" the exception to the main method. This exception is handled in the main method.\\n\\nOutput:\\n\\na = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nThe program continues to run. cigma=7\\n",
3619 "a = 0. It is impossible to divide by 0\\nThe exception is java.lang.ArithmeticException: / by zero\\nThe program continues to run. cigma=7\\n",
3620 "1",
3621 "2",
3622 "74"
3623 ]
3624 },
3625 {
3626 "-name": "question242",
3627 "item": [
3628 "242",
3629 "49",
3630 "public class Main { // \"throw\" throws\\n\\tstatic int cigma;\\n\\tstatic int beta = 7;\\n\\n\\tpublic static void main(String[] args) throws ArithmeticException {\\n\\t\\tmethod1();\\n\\t\\tSystem.out.println(\"The program continues to run. cigma=\" + beta);\\n\\t}\\n\\n\\tpublic static void method1() throws ArithmeticException {\\n\\t\\tint a = (int) (Math.random() * 3);\\n\\t\\tcigma = beta / a;\\n\\t}\\n}\\n",
3631 "The program generates ArithmeticException in the method method1. The program \"throws\" the exception to the main method. This exception is not handled in the main method and the program \"throws\" it further in the hope, that the exception will not come.\\n\\nOutput:\\n\\nThe program continues to run. cigma=7\\n",
3632 "The program continues to run. cigma=7\\n",
3633 "1",
3634 "3",
3635 "24"
3636 ]
3637 },
3638 {
3639 "-name": "question243",
3640 "item": [
3641 "243",
3642 "49",
3643 "public class Man { // creating your own exception\\n\\tString name;\\n\\tint weight;\\n\\n\\tMan(String name, int weight) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka = \"The total weight should not exceed 200 kg.\";\\n\\t\\tMan man1 = new Man(\"Peter\", 140);\\n\\t\\tMan man2 = new Man(\"John\", 85);\\n\\t\\tMan man3 = new Man(\"Bill\", 40);\\n\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man1, man2, man3);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man1, man2);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man2, man3);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The elevator rides!\");\\n\\t}\\n\\n\\tpublic static void useLift(Man... mans) throws WEx {\\n\\t\\tint sum = 0;\\n\\t\\tfor (Man man : mans) {\\n\\t\\t\\tsum = sum + man.weight;\\n\\t\\t}\\n\\t\\tif (sum > 200) {\\n\\t\\t\\tthrow new WEx();\\n\\t\\t}\\n\\t}\\n}\\n",
3644 "public class WEx extends Exception {\\n\\n\\tprivate String message = \"EXCEPTION - the elevator is overloaded\";\\n\\n\\tpublic String getMessage() {\\n\\t\\treturn message;\\n\\t}\\n}\\n",
3645 "The program generates own exception \"WEx\" in the useLift method, \"throws\" this exception to the main method. This exception is handled in the main method.\\n\\nOutput:\\n\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\n\\nThe elevator rides!\\n",
3646 "EXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\n\\nThe elevator rides!\\n",
3647 "1",
3648 "3",
3649 "128"
3650 ]
3651 },
3652 {
3653 "-name": "question244",
3654 "item": [
3655 "244",
3656 "49",
3657 "public class WEx extends Exception {\\n\\n\\tprivate String message = \"EXCEPTION - the elevator is overloaded\";\\n\\n\\tpublic String getMessage() {\\n\\t\\treturn message;\\n\\t}\\n}\\n",
3658 "public class Man { // creating your own exception\\n\\tString name;\\n\\tint weight;\\n\\n\\tMan(String name, int weight) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.weight = weight;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka = \"The total weight should not exceed 200 kg.\";\\n\\t\\tMan man1 = new Man(\"Peter\", 140);\\n\\t\\tMan man2 = new Man(\"John\", 85);\\n\\t\\tMan man3 = new Man(\"Bill\", 40);\\n\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man1, man2, man3);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man1, man2);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\n\\t\\ttry {\\n\\t\\t\\tuseLift(man2, man3);\\n\\t\\t} catch (WEx e) {\\n\\t\\t\\tSystem.out.println(e.getMessage());\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The elevator rides!\");\\n\\t}\\n\\n\\tpublic static void useLift(Man... mans) throws WEx {\\n\\t\\tint sum = 0;\\n\\t\\tfor (Man man : mans) {\\n\\t\\t\\tsum = sum + man.weight;\\n\\t\\t}\\n\\t\\tif (sum > 200) {\\n\\t\\t\\tthrow new WEx();\\n\\t\\t}\\n\\t}\\n}\\n",
3659 "The program generates own exception \"WEx\" in the useLift method, \"throws\" this exception to the main method. This exception is handled in the main method.\\n\\nOutput:\\n\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\n\\nThe elevator rides!\\n",
3660 "EXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\nEXCEPTION - the elevator is overloaded\\nThe total weight should not exceed 200 kg.\\n\\nThe elevator rides!\\n",
3661 "1",
3662 "2",
3663 "1"
3664 ]
3665 },
3666 {
3667 "-name": "question245",
3668 "item": [
3669 "245",
3670 "49",
3671 "public class Pass { // creating your own exception\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString stroka = \"The car can carry at one time no more than 4 people.\";\\n\\n\\t\\ttry {\\n\\t\\t\\tuseCar(5);\\n\\t\\t} catch (PEx e) {\\n\\t\\t\\tSystem.out.println(e);\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\ttry {\\n\\t\\t\\tuseCar(6);\\n\\t\\t} catch (PEx e) {\\n\\t\\t\\tSystem.out.println(e);\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\ttry {\\n\\t\\t\\tuseCar(3);\\n\\t\\t} catch (PEx e) {\\n\\t\\t\\tSystem.out.println(e);\\n\\t\\t\\tSystem.out.println(stroka);\\n\\t\\t}\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tSystem.out.println(\"The car rides!\");\\n\\t}\\n\\n\\tpublic static void useCar(int i) throws PEx {\\n\\n\\t\\tif (i > 4) {\\n\\t\\t\\tthrow new PEx();\\n\\t\\t}\\n\\t}\\n}\\n",
3672 "public class PEx extends Exception {\\n\\n\\tpublic String toString() {\\n\\t\\treturn \"EXCEPTION - the car is overloaded\";\\n\\t}\\n}\\n",
3673 "The program generates own exception \"PEx\" in the useCar method, \"throws\" this exception to the main method. This exception is handled in the main method.\\n\\nOutput:\\n\\nEXCEPTION - the car is overloaded\\nThe car can carry at one time no more than 4 people.\\nEXCEPTION - the car is overloaded\\nThe car can carry at one time no more than 4 people.\\n\\nThe car rides!\\n",
3674 "EXCEPTION - the car is overloaded\\nThe car can carry at one time no more than 4 people.\\nEXCEPTION - the car is overloaded\\nThe car can carry at one time no more than 4 people.\\n\\nThe car rides!\\n",
3675 "1",
3676 "3",
3677 "48"
3678 ]
3679 },
3680 {
3681 "-name": "question246",
3682 "item": [
3683 "246",
3684 "50",
3685 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tSystem.out.println(\"The current thread is \" + t);\\n\\t\\tt.setName(\"The main thread\");\\n\\t\\tSystem.out.println(\"The current thread is \" + t);\\n\\t}\\n}\\n",
3686 "The program displays the name of the thread, its priority and the group. Then the program changes the name of the thread and displays its name, its priority and its group again.\\n\\nOutput:\\n\\nThe carrent thread is Thread[main,5,main]\\nThe current thread is Thread[The main thread,5,main]\\n",
3687 "The carrent thread is Thread[main,5,main]\\nThe current thread is Thread[The main thread,5,main]\\n",
3688 "1",
3689 "2",
3690 "1"
3691 ]
3692 },
3693 {
3694 "-name": "question247",
3695 "item": [
3696 "247",
3697 "50",
3698 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tt.setName(\"The main thread\");\\n\\t\\tSystem.out.println(\"The current thread is \" + t.getName());\\n\\t\\tSystem.out.println(t);\\n\\t}\\n}\\n",
3699 "The program displays the name of the thread separately and its name, its priority and the group together.\\n\\nOutput:\\n\\nThe current thread is The main thread\\nThread[The main thread,5,main]\\n",
3700 "The current thread is The main thread\\nThread[The main thread,5,main]\\n",
3701 "1",
3702 "2",
3703 "1"
3704 ]
3705 },
3706 {
3707 "-name": "question248",
3708 "item": [
3709 "248",
3710 "50",
3711 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tt.setName(\"The main thread\");\\n\\t\\tSystem.out.println(\"The state of the thread is \" + t.getState());\\n\\t\\tt.setPriority(Thread.MAX_PRIORITY);\\n\\t\\tSystem.out.println(t);\\n\\t}\\n}\\n",
3712 "The program displays the state of the thread, its name, its priority and the group. The name of the thread and its priority were pre-installed.\\n\\nOutput:\\n\\nThe state of the thread is RUNNABLE\\nThread[The main thread,10,main]\\n",
3713 "The state of the thread is RUNNABLE\\nThread[The main thread,10,main]\\n",
3714 "1",
3715 "3",
3716 "1"
3717 ]
3718 },
3719 {
3720 "-name": "question249",
3721 "item": [
3722 "249",
3723 "50",
3724 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tt.setName(\"The main thread\");\\n\\t\\tt.setPriority(Thread.MIN_PRIORITY);\\n\\t\\tSystem.out.println(t);\\n\\t\\tSystem.out.println(\"The number of running threads is \"\\n\\t\\t\\t\\t+ Thread.activeCount());\\n\\t}\\n}\\n",
3725 "The program sets the name of the thread and its priority. The program displays the name of the thread, its priority and the group. The program displays the number of running threads.\\n\\nOutput:\\n\\nThread[The main thread,1,main]\\nThe number of running threads is 1\\n",
3726 "Thread[The main thread,1,main]\\nThe number of running threads is 1\\n",
3727 "1",
3728 "3",
3729 "1"
3730 ]
3731 },
3732 {
3733 "-name": "question250",
3734 "item": [
3735 "250",
3736 "50",
3737 "public class Main {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tt.setName(\"The main thread\");\\n\\t\\tt.setPriority(Thread.MAX_PRIORITY);\\n\\t\\ttry {\\n\\t\\t\\tThread.sleep(2000);\\n\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\te.printStackTrace();\\n\\t\\t}\\n\\t\\tSystem.out.println(t);\\n\\t}\\n}\\n",
3738 "The program sets the name of the thread and its priority. The program displays the name of the thread, its priority and the group delay of 2 seconds.\\n\\nOutput:\\n\\nThread[The main thread,10,main]\\n",
3739 "Thread[The main thread,10,main]\\n",
3740 "1",
3741 "3",
3742 "1"
3743 ]
3744 },
3745 {
3746 "-name": "question251",
3747 "item": [
3748 "251",
3749 "51",
3750 "// disputes about the Middle-earth crown\\npublic class Mag {\\n\\tString name;\\n\\tint strength;\\n\\n\\tMag(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tElf elf = new Elf(\"Elain\", 100);\\n\\t\\tTroll troll = new Troll(\"Zuzy\", 100);\\n\\t\\tMag mag = new Mag(\"Dumbledore\", 100);\\n\\n\\t\\tThread t1 = new Thread(elf);\\n\\t\\tt1.start();\\n\\t\\tThread t2 = new Thread(troll);\\n\\t\\tt2.start();\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(350);\\n\\t\\t\\t\\tSystem.out.println(mag.name + \" Bella is Queen of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3751 "public class Elf implements Runnable {\\n\\tString name;\\n\\tint strength;\\n\\n\\tElf(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 6; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(200);\\n\\t\\t\\t\\tSystem.out.println(name + \" Arthur is King of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3752 "public class Troll implements Runnable {\\n\\tString name;\\n\\tint strength;\\n\\n\\tTroll(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(433);\\n\\t\\t\\t\\tSystem.out.println(name + \" Richard is King of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3753 "Mag, Elf and Troll argue who should be king of Middle-earth.\\n\\nPossible output:\\n\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\n",
3754 "Elain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\n",
3755 "1",
3756 "3",
3757 "114"
3758 ]
3759 },
3760 {
3761 "-name": "question252",
3762 "item": [
3763 "252",
3764 "51",
3765 "public class Elf implements Runnable {\\n\\tString name;\\n\\tint strength;\\n\\n\\tElf(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 6; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(200);\\n\\t\\t\\t\\tSystem.out.println(name + \" Arthur is King of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3766 "// disputes about the Middle-earth crown\\npublic class Mag {\\n\\tString name;\\n\\tint strength;\\n\\n\\tMag(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tElf elf = new Elf(\"Elain\", 100);\\n\\t\\tTroll troll = new Troll(\"Zuzy\", 100);\\n\\t\\tMag mag = new Mag(\"Dumbledore\", 100);\\n\\n\\t\\tThread t1 = new Thread(elf);\\n\\t\\tt1.start();\\n\\t\\tThread t2 = new Thread(troll);\\n\\t\\tt2.start();\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(350);\\n\\t\\t\\t\\tSystem.out.println(mag.name + \" Bella is Queen of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3767 "public class Troll implements Runnable {\\n\\tString name;\\n\\tint strength;\\n\\n\\tTroll(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.strength = strength;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(433);\\n\\t\\t\\t\\tSystem.out.println(name + \" Richard is King of Middle-earth\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3768 "Mag, Elf and Troll argue who should be king of Middle-earth.\\n\\nPossible output:\\n\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\n",
3769 "Elain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nElain Arthur is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\nElain Arthur is King of Middle-earth\\nZuzy Richard is King of Middle-earth\\nDumbledore Bella is Queen of Middle-earth\\n",
3770 "1",
3771 "3",
3772 "1"
3773 ]
3774 },
3775 {
3776 "-name": "question253",
3777 "item": [
3778 "253",
3779 "51",
3780 "// 2 witches conjure simultaneously \\npublic class Hag implements Runnable {\\n\\tString name;\\n\\n\\tHag(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHag hag1 = new Hag(\"Rata\");\\n\\t\\tHag hag2 = new Hag(\"Sara\");\\n\\t\\tThread t1 = Thread.currentThread();\\n\\t\\tt1.setName(\"-the spell of first witch-\");\\n\\t\\tThread t2 = new Thread(hag2);\\n\\t\\tt2.start();\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(150);\\n\\t\\t\\t\\tSystem.out.print(hag1.name + \" \" + t1.getName() + \" \");\\n\\t\\t\\t\\tSystem.out.println(\"Tata-tutu\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tThread t = Thread.currentThread();\\n\\t\\tt.setName(\"-the spell of second witch -\");\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(200);\\n\\t\\t\\t\\tSystem.out.print(name + \" \" + t.getName() + \" \");\\n\\t\\t\\t\\tSystem.out.println(\"Tram-trum\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3781 "Witches Rata and Sara conjure together.\\n\\nPossible output:\\n\\nRata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\nRata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\nRata -the spell of first witch- Tata-tutu\\nRata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\n",
3782 "Rata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\nRata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\nRata -the spell of first witch- Tata-tutu\\nRata -the spell of first witch- Tata-tutu\\nSara -the spell of second witch - Tram-trum\\n",
3783 "1",
3784 "3",
3785 "7"
3786 ]
3787 },
3788 {
3789 "-name": "question254",
3790 "item": [
3791 "254",
3792 "51",
3793 "// Elves shoot with bows and arrows\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eline\");\\n\\t\\tElf elf2 = new Elf(\"Eliot\");\\n\\t\\tElf elf3 = new Elf(\"Elot\");\\n\\t}\\n}\\n",
3794 "// Elves shoot with bows and arrows\\npublic class Elf implements Runnable {\\n\\tString name;\\n\\tThread t;\\n\\n\\tElf(String name) {\\n\\t\\tthis.name = name;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(200);\\n\\t\\t\\t\\tSystem.out.println(name + \" shoots-\" + target());\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\n\\tpublic int target() {\\n\\t\\tint aim = (int) (Math.random() * 11);\\n\\t\\treturn aim;\\n\\t}\\n}\\n",
3795 "Three elves shoot arrows at a target at the same time.\\n\\nPossible output:\\n\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-3\\nElot shoots-9\\nEliot shoots-7\\nEline shoots-10\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-1\\n",
3796 "Eliot shoots-5\\nElot shoots-9\\nEline shoots-3\\nElot shoots-9\\nEliot shoots-7\\nEline shoots-10\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-1\\n",
3797 "1",
3798 "2",
3799 "9"
3800 ]
3801 },
3802 {
3803 "-name": "question255",
3804 "item": [
3805 "255",
3806 "51",
3807 "// Elves shoot with bows and arrows\\npublic class Elf implements Runnable {\\n\\tString name;\\n\\tThread t;\\n\\n\\tElf(String name) {\\n\\t\\tthis.name = name;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 3; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(200);\\n\\t\\t\\t\\tSystem.out.println(name + \" shoots-\" + target());\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\n\\tpublic int target() {\\n\\t\\tint aim = (int) (Math.random() * 11);\\n\\t\\treturn aim;\\n\\t}\\n}\\n",
3808 "// Elves shoot with bows and arrows\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eline\");\\n\\t\\tElf elf2 = new Elf(\"Eliot\");\\n\\t\\tElf elf3 = new Elf(\"Elot\");\\n\\t}\\n}\\n",
3809 "Three elves shoot arrows at a target at the same time.\\n\\nPossible output:\\n\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-3\\nElot shoots-9\\nEliot shoots-7\\nEline shoots-10\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-1\\n",
3810 "Eliot shoots-5\\nElot shoots-9\\nEline shoots-3\\nElot shoots-9\\nEliot shoots-7\\nEline shoots-10\\nEliot shoots-5\\nElot shoots-9\\nEline shoots-1\\n",
3811 "1",
3812 "3",
3813 "9"
3814 ]
3815 },
3816 {
3817 "-name": "question256",
3818 "item": [
3819 "256",
3820 "52",
3821 "public class Main {\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tString winner = \"\";\\n\\t\\tString loser = \"\";\\n\\t\\tString stroka1 = \" rose to the 4 floor\";\\n\\t\\tString stroka2 = \" has won\";\\n\\t\\tElf elf = new Elf(\"Eliot\");\\n\\t\\tOrc orc = new Orc(\"Brut\");\\n\\t\\tThread t1 = new Thread(elf);\\n\\t\\tThread t2 = new Thread(orc);\\n\\t\\tt1.start();\\n\\t\\tt2.start();\\n\\t\\tt1.join();\\n\\t\\tif (t2.isAlive()) {\\n\\t\\t\\twinner = elf.name;\\n\\t\\t\\tloser = orc.name;\\n\\t\\t} else {\\n\\t\\t\\twinner = orc.name;\\n\\t\\t\\tloser = elf.name;\\n\\t\\t}\\n\\t\\tt2.join();\\n\\t\\tSystem.out.println(winner + stroka1);\\n\\t\\tSystem.out.println(loser + stroka1);\\n\\t\\tSystem.out.println(winner + stroka2);\\n\\t}\\n}\\n",
3822 "public class Orc implements Runnable {\\n\\tString name;\\n\\n\\tOrc(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(150);\\n\\t\\t\\t\\tSystem.out.println(name + \" rose to the \" + i + \" floor\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3823 "public class Elf implements Runnable {\\n\\tString name;\\n\\n\\tElf(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(150);\\n\\t\\t\\t\\tSystem.out.println(name + \" rose to the \" + (i) + \" floor\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3824 "Elf and Orc compete who will rise first to the 4th floor.\\n\\nPossible output:\\n\\nEliot rose to the 0 floor\\nBrut rose to the 0 floor\\nBrut rose to the 1 floor\\nEliot rose to the 1 floor\\nBrut rose to the 2 floor\\nEliot rose to the 2 floor\\nEliot rose to the 3 floor\\nBrut rose to the 3 floor\\nBrut rose to the 4 floor\\nEliot rose to the 4 floor\\nBrut has won\\n",
3825 "Eliot rose to the 0 floor\\nBrut rose to the 0 floor\\nBrut rose to the 1 floor\\nEliot rose to the 1 floor\\nBrut rose to the 2 floor\\nEliot rose to the 2 floor\\nEliot rose to the 3 floor\\nBrut rose to the 3 floor\\nBrut rose to the 4 floor\\nEliot rose to the 4 floor\\nBrut has won\\n",
3826 "1",
3827 "2",
3828 "83"
3829 ]
3830 },
3831 {
3832 "-name": "question257",
3833 "item": [
3834 "257",
3835 "52",
3836 "public class Orc implements Runnable {\\n\\tString name;\\n\\n\\tOrc(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 1; i < 5; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(150);\\n\\t\\t\\t\\tSystem.out.println(name + \" rose to the \" + i + \" floor\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3837 "public class Main {\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tString winner = \"\";\\n\\t\\tString loser = \"\";\\n\\t\\tString stroka1 = \" rose to the 4 floor\";\\n\\t\\tString stroka2 = \" has won\";\\n\\t\\tElf elf = new Elf(\"Eliot\");\\n\\t\\tOrc orc = new Orc(\"Brut\");\\n\\t\\tThread t1 = new Thread(elf);\\n\\t\\tThread t2 = new Thread(orc);\\n\\t\\tt1.start();\\n\\t\\tt2.start();\\n\\t\\tt1.join();\\n\\t\\tif (t2.isAlive()) {\\n\\t\\t\\twinner = elf.name;\\n\\t\\t\\tloser = orc.name;\\n\\t\\t} else {\\n\\t\\t\\twinner = orc.name;\\n\\t\\t\\tloser = elf.name;\\n\\t\\t}\\n\\t\\tt2.join();\\n\\t\\tSystem.out.println(winner + stroka1);\\n\\t\\tSystem.out.println(loser + stroka1);\\n\\t\\tSystem.out.println(winner + stroka2);\\n\\t}\\n}\\n",
3838 "public class Elf implements Runnable {\\n\\tString name;\\n\\n\\tElf(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 0; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(150);\\n\\t\\t\\t\\tSystem.out.println(name + \" rose to the \" + (i) + \" floor\");\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
3839 "Elf and Orc compete who will rise first to the 4th floor.\\n\\nPossible output:\\n\\nEliot rose to the 0 floor\\nBrut rose to the 0 floor\\nBrut rose to the 1 floor\\nEliot rose to the 1 floor\\nBrut rose to the 2 floor\\nEliot rose to the 2 floor\\nEliot rose to the 3 floor\\nBrut rose to the 3 floor\\nBrut rose to the 4 floor\\nEliot rose to the 4 floor\\nBrut has won\\n",
3840 "Eliot rose to the 0 floor\\nBrut rose to the 0 floor\\nBrut rose to the 1 floor\\nEliot rose to the 1 floor\\nBrut rose to the 2 floor\\nEliot rose to the 2 floor\\nEliot rose to the 3 floor\\nBrut rose to the 3 floor\\nBrut rose to the 4 floor\\nEliot rose to the 4 floor\\nBrut has won\\n",
3841 "1",
3842 "3",
3843 "1"
3844 ]
3845 },
3846 {
3847 "-name": "question258",
3848 "item": [
3849 "258",
3850 "52",
3851 "// Fairies are competing who will gain more magical pollen\\npublic class Fay implements Runnable {\\n\\n\\tString name;\\n\\tstatic String strokaSbor1 = \" picked up \";\\n\\tstatic String strokaSbor2 = \" glass of magic pollen \";\\n\\n\\tFay(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tString winner = \"\";\\n\\t\\tFay fay1 = new Fay(\"Nataly\");\\n\\t\\tFay fay2 = new Fay(\"Elza\");\\n\\t\\tThread f1 = new Thread(fay1);\\n\\t\\tThread f2 = new Thread(fay2);\\n\\t\\tf1.start();\\n\\t\\tf2.start();\\n\\t\\ttry {\\n\\t\\t\\tf1.join();\\n\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t}\\n\\t\\tif (f2.isAlive()) {\\n\\t\\t\\twinner = fay1.name;\\n\\t\\t} else {\\n\\t\\t\\twinner = fay2.name;\\n\\t\\t}\\n\\n\\t\\ttry {\\n\\t\\t\\tf2.join();\\n\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"Fay \" + winner + Fay.strokaSbor1 + 4\\n\\t\\t\\t+ Fay.strokaSbor2);\\n\\t\\tSystem.out.println(\"Fay \" + winner + \" has won\");\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tfor (int i = 1; i < 4; i++) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tThread.sleep(100);\\n\\t\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"Fay \" + name + Fay.strokaSbor1 + i\\n\\t\\t\\t\\t+ Fay.strokaSbor2);\\n\\t\\t}\\n\\t}\\n}\\n",
3852 "Fairies compete to see who will be the first to collect 4 glasses of magic pollen.\\n\\nPossible output:\\n\\nFay Elza picked up 1 glass of magic pollen\\nFay Nataly picked up 1 glass of magic pollen\\nFay Nataly picked up 2 glass of magic pollen\\nFay Elza picked up 2 glass of magic pollen\\nFay Elza picked up 3 glass of magic pollen\\nFay Nataly picked up 3 glass of magic pollen\\nFay Elza picked up 4 glass of magic pollen\\nFay Elza has won\\n",
3853 "Fay Elza picked up 1 glass of magic pollen\\nFay Nataly picked up 1 glass of magic pollen\\nFay Nataly picked up 2 glass of magic pollen\\nFay Elza picked up 2 glass of magic pollen\\nFay Elza picked up 3 glass of magic pollen\\nFay Nataly picked up 3 glass of magic pollen\\nFay Elza picked up 4 glass of magic pollen\\nFay Elza has won\\n",
3854 "1",
3855 "3",
3856 "12"
3857 ]
3858 },
3859 {
3860 "-name": "question259",
3861 "item": [
3862 "259",
3863 "52",
3864 "// Arthur and Richard compete who will be the first to wear an armor\\npublic class Main {\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\n\\t\\tString winner = \"\";\\n\\t\\tKing king1 = new King(\"Arthur\");\\n\\t\\tKing king2 = new King(\"Richard\");\\n\\n\\t\\tking1.t.join();\\n\\t\\tif (king2.t.isAlive()) {\\n\\t\\t\\twinner = king1.name;\\n\\t\\t} else {\\n\\t\\t\\twinner = king2.name;\\n\\t\\t}\\n\\t\\tking2.t.join();\\n\\t\\tSystem.out.println(\"King \" + winner + \" has won\");\\n\\t}\\n}\\n",
3865 "// Arthur and Richard compete who will be the first to wear an armor\\npublic class King implements Runnable {\\n\\n\\tThread t;\\n\\tString name;\\n\\tstatic String strokaSbor = \" put on his armor for \";\\n\\n\\tKing(String name) {\\n\\t\\tthis.name = name;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tint t = intTime();\\n\\t\\ttry {\\n\\t\\t\\tThread.sleep(t * 50);\\n\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"King \" + name + strokaSbor + t + \" minutes\");\\n\\t}\\n\\n\\tprivate int intTime() {\\n\\t\\tint g = (int) (Math.random() * 10) + 10;\\n\\t\\treturn g;\\n\\t}\\n}\\n",
3866 "Arthur and Richard compete who will be the first to wear an armor.\\n\\nPossible output:\\n\\nKing Richard put on his armor for 10 minutes\\nKing Arthur put on his armor for 15 minutes\\nKing Richard has won\\n",
3867 "King Richard put on his armor for 10 minutes\\nKing Arthur put on his armor for 15 minutes\\nKing Richard has won\\n",
3868 "1",
3869 "2",
3870 "70"
3871 ]
3872 },
3873 {
3874 "-name": "question260",
3875 "item": [
3876 "260",
3877 "52",
3878 "// Arthur and Richard compete who will be the first to wear an armor\\npublic class King implements Runnable {\\n\\n\\tThread t;\\n\\tString name;\\n\\tstatic String strokaSbor = \" put on his armor for \";\\n\\n\\tKing(String name) {\\n\\t\\tthis.name = name;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tint t = intTime();\\n\\t\\ttry {\\n\\t\\t\\tThread.sleep(t * 50);\\n\\t\\t} catch (InterruptedException e) {\\n\\t\\t\\tSystem.out.println(\"Interrupt\");\\n\\t\\t}\\n\\t\\tSystem.out.println(\"King \" + name + strokaSbor + t + \" minutes\");\\n\\t}\\n\\n\\tprivate int intTime() {\\n\\t\\tint g = (int) (Math.random() * 10) + 10;\\n\\t\\treturn g;\\n\\t}\\n}\\n",
3879 "// Arthur and Richard compete who will be the first to wear an armor\\npublic class Main {\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\n\\t\\tString winner = \"\";\\n\\t\\tKing king1 = new King(\"Arthur\");\\n\\t\\tKing king2 = new King(\"Richard\");\\n\\n\\t\\tking1.t.join();\\n\\t\\tif (king2.t.isAlive()) {\\n\\t\\t\\twinner = king1.name;\\n\\t\\t} else {\\n\\t\\t\\twinner = king2.name;\\n\\t\\t}\\n\\t\\tking2.t.join();\\n\\t\\tSystem.out.println(\"King \" + winner + \" has won\");\\n\\t}\\n}\\n",
3880 "Arthur and Richard compete who will be the first to wear an armor.\\n\\nPossible output:\\n\\nKing Richard put on his armor for 10 minutes\\nKing Arthur put on his armor for 15 minutes\\nKing Richard has won\\n",
3881 "King Richard put on his armor for 10 minutes\\nKing Arthur put on his armor for 15 minutes\\nKing Richard has won\\n",
3882 "1",
3883 "3",
3884 "25"
3885 ]
3886 },
3887 {
3888 "-name": "question261",
3889 "item": [
3890 "261",
3891 "53",
3892 "public class Man {\\n\\tString name;\\n\\tint age;\\n\\tString shop;\\n\\tString order[];\\n\\n\\tMan(String name, int age, String shop) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.age = age;\\n\\t\\tthis.shop = shop;\\n\\t}\\n\\n\\tpublic void setOrder(String… str) {\\n\\t\\tthis.order = str;\\n\\t}\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tString stroka = \"Customers made a repeat order\";\\n\\t\\tCash cash = new Cash();\\n\\t\\tMan order1 = new Man(\"Bill\", 35, \"badGayes\");\\n\\t\\torder1.setOrder(Whiskey, Steak);\\n\\t\\tMan order2 = new Man(\"Nataly\", 13, \"badGayes\");\\n\\t\\torder2.setOrder(\"Chisburger\", \"Cola\"); \\n\\t\\tMan order3 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder3.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar1 = new Bar(order1, cash);\\n\\t\\tBar bar2 = new Bar(order2, cash);\\n\\t\\tBar bar3 = new Bar(order3, cash);\\n\\n\\t\\tbar1.t.join();\\n\\t\\tbar2.t.join();\\n\\t\\tbar3.t.join();\\n\\n\\t\\tSystem.out.println(stroka);\\n\\t\\tSystem.out.println();\\n\\t\\tMan order4 = new Man(\"Bill\", 35, \"goodGayes.com\");\\n\\t\\torder4.setOrder(\"Whiskey\", \"Steak\");\\n\\t\\tMan order5 = new Man(\"Nataly\", 13, \"goodGayes.com\");\\n\\t\\torder5.setOrder(\"Chisburger\", \"Cola\");\\n\\t\\tMan order6 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder6.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar4 = new Bar(order4, cash);\\n\\t\\tBar bar5 = new Bar(order5, cash);\\n\\t\\tBar bar6 = new Bar(order6, cash);\\n\\n\\t\\tbar4.t.join();\\n\\t\\tbar5.t.join();\\n\\t\\tbar6.t.join();\\n\\t}\\n}\\n",
3893 "public class Cash {\\n\\n\\tpublic void orderCl(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic synchronized void orderClNew(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic void orders(Man client) {\\n\\t\\tSystem.out.println(client.name + \" is \" + client.age + \" years old\");\\n\\t\\tSystem.out.print(\"Order \");\\n\\t\\tfor (String ord : client.order) {\\n\\t\\t\\tSystem.out.print(ord + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3894 "public class Bar implements Runnable {\\n\\tThread t;\\n\\tMan client;\\n\\tCash cashBox;\\n\\n\\tBar(Man client, Cash cashBox) {\\n\\t\\tthis.client = client;\\n\\t\\tthis.cashBox = cashBox;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tif (client.shop.equals(\"badGayes\")) {\\n\\t\\t\\tcashBox.orderCl(client);\\n\\t\\t} else {\\n\\t\\t\\tcashBox.orderClNew(client);\\n\\t\\t}\\n\\t}\\n}\\n",
3895 "Three buyers made orders at the same time in the same online store. Shop was not synchronized. Nobody understood the orders. They went to another online store. They made orders again. Shop was synchronized. This time orders were accurate.\\n\\nPossible output:\\n\\nNataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes \\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3896 "Nataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n \\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3897 "1",
3898 "3",
3899 "222"
3900 ]
3901 },
3902 {
3903 "-name": "question262",
3904 "item": [
3905 "262",
3906 "53",
3907 "public class Cash {\\n\\n\\tpublic void orderCl(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic synchronized void orderClNew(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic void orders(Man client) {\\n\\t\\tSystem.out.println(client.name + \" is \" + client.age + \" years old\");\\n\\t\\tSystem.out.print(\"Order \");\\n\\t\\tfor (String ord : client.order) {\\n\\t\\t\\tSystem.out.print(ord + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3908 "public class Man {\\n\\tString name;\\n\\tint age;\\n\\tString shop;\\n\\tString order[];\\n\\n\\tMan(String name, int age, String shop) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.age = age;\\n\\t\\tthis.shop = shop;\\n\\t}\\n\\n\\tpublic void setOrder(String… str) {\\n\\t\\tthis.order = str;\\n\\t}\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tString stroka = \"Customers made a repeat order\";\\n\\t\\tCash cash = new Cash();\\n\\t\\tMan order1 = new Man(\"Bill\", 35, \"badGayes\");\\n\\t\\torder1.setOrder(Whiskey, Steak);\\n\\t\\tMan order2 = new Man(\"Nataly\", 13, \"badGayes\");\\n\\t\\torder2.setOrder(\"Chisburger\", \"Cola\"); \\n\\t\\tMan order3 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder3.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar1 = new Bar(order1, cash);\\n\\t\\tBar bar2 = new Bar(order2, cash);\\n\\t\\tBar bar3 = new Bar(order3, cash);\\n\\n\\t\\tbar1.t.join();\\n\\t\\tbar2.t.join();\\n\\t\\tbar3.t.join();\\n\\n\\t\\tSystem.out.println(stroka);\\n\\t\\tSystem.out.println();\\n\\t\\tMan order4 = new Man(\"Bill\", 35, \"goodGayes.com\");\\n\\t\\torder4.setOrder(\"Whiskey\", \"Steak\");\\n\\t\\tMan order5 = new Man(\"Nataly\", 13, \"goodGayes.com\");\\n\\t\\torder5.setOrder(\"Chisburger\", \"Cola\");\\n\\t\\tMan order6 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder6.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar4 = new Bar(order4, cash);\\n\\t\\tBar bar5 = new Bar(order5, cash);\\n\\t\\tBar bar6 = new Bar(order6, cash);\\n\\n\\t\\tbar4.t.join();\\n\\t\\tbar5.t.join();\\n\\t\\tbar6.t.join();\\n\\t}\\n}\\n",
3909 "public class Bar implements Runnable {\\n\\tThread t;\\n\\tMan client;\\n\\tCash cashBox;\\n\\n\\tBar(Man client, Cash cashBox) {\\n\\t\\tthis.client = client;\\n\\t\\tthis.cashBox = cashBox;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tif (client.shop.equals(\"badGayes\")) {\\n\\t\\t\\tcashBox.orderCl(client);\\n\\t\\t} else {\\n\\t\\t\\tcashBox.orderClNew(client);\\n\\t\\t}\\n\\t}\\n}\\n",
3910 "Three buyers made orders at the same time in the same online store. Shop was not synchronized. Nobody understood the orders. They went to another online store. They made orders again. Shop was synchronized. This time orders were accurate.\\n\\nPossible output:\\n\\nNataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes \\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3911 "Nataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n \\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3912 "1",
3913 "2",
3914 "27"
3915 ]
3916 },
3917 {
3918 "-name": "question263",
3919 "item": [
3920 "263",
3921 "53",
3922 "public class Bar implements Runnable {\\n\\tThread t;\\n\\tMan client;\\n\\tCash cashBox;\\n\\n\\tBar(Man client, Cash cashBox) {\\n\\t\\tthis.client = client;\\n\\t\\tthis.cashBox = cashBox;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tif (client.shop.equals(\"badGayes\")) {\\n\\t\\t\\tcashBox.orderCl(client);\\n\\t\\t} else {\\n\\t\\t\\tcashBox.orderClNew(client);\\n\\t\\t}\\n\\t}\\n}\\n",
3923 "public class Man {\\n\\tString name;\\n\\tint age;\\n\\tString shop;\\n\\tString order[];\\n\\n\\tMan(String name, int age, String shop) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.age = age;\\n\\t\\tthis.shop = shop;\\n\\t}\\n\\n\\tpublic void setOrder(String… str) {\\n\\t\\tthis.order = str;\\n\\t}\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tString stroka = \"Customers made a repeat order\";\\n\\t\\tCash cash = new Cash();\\n\\t\\tMan order1 = new Man(\"Bill\", 35, \"badGayes\");\\n\\t\\torder1.setOrder(Whiskey, Steak);\\n\\t\\tMan order2 = new Man(\"Nataly\", 13, \"badGayes\");\\n\\t\\torder2.setOrder(\"Chisburger\", \"Cola\"); \\n\\t\\tMan order3 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder3.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar1 = new Bar(order1, cash);\\n\\t\\tBar bar2 = new Bar(order2, cash);\\n\\t\\tBar bar3 = new Bar(order3, cash);\\n\\n\\t\\tbar1.t.join();\\n\\t\\tbar2.t.join();\\n\\t\\tbar3.t.join();\\n\\n\\t\\tSystem.out.println(stroka);\\n\\t\\tSystem.out.println();\\n\\t\\tMan order4 = new Man(\"Bill\", 35, \"goodGayes.com\");\\n\\t\\torder4.setOrder(\"Whiskey\", \"Steak\");\\n\\t\\tMan order5 = new Man(\"Nataly\", 13, \"goodGayes.com\");\\n\\t\\torder5.setOrder(\"Chisburger\", \"Cola\");\\n\\t\\tMan order6 = new Man(\"Elza\", 25, \"badGayes\");\\n\\t\\torder6.setOrder(\"Salad\", \"Tea\", \"Cigarettes\");\\n\\n\\t\\tBar bar4 = new Bar(order4, cash);\\n\\t\\tBar bar5 = new Bar(order5, cash);\\n\\t\\tBar bar6 = new Bar(order6, cash);\\n\\n\\t\\tbar4.t.join();\\n\\t\\tbar5.t.join();\\n\\t\\tbar6.t.join();\\n\\t}\\n}\\n",
3924 "public class Cash {\\n\\n\\tpublic void orderCl(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic synchronized void orderClNew(Man client) {\\n\\t\\torders(client);\\n\\t}\\n\\n\\tpublic void orders(Man client) {\\n\\t\\tSystem.out.println(client.name + \" is \" + client.age + \" years old\");\\n\\t\\tSystem.out.print(\"Order \");\\n\\t\\tfor (String ord : client.order) {\\n\\t\\t\\tSystem.out.print(ord + \" \");\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println();\\n\\t}\\n}\\n",
3925 "Three buyers made orders at the same time in the same online store. Shop was not synchronized. Nobody understood the orders. They went to another online store. They made orders again. Shop was synchronized. This time orders were accurate.\\n\\nPossible output:\\n\\nNataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes \\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3926 "Nataly is 13 years old\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n \\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nOrder Chisburger Cola\\n\\nCustomers made a repeat order\\n\\nBill is 35 years old\\nOrder Whiskey Steak\\n\\nElza is 25 years old\\nOrder Salad Tea Cigarettes\\n\\nNataly is 13 years old\\nOrder Chisburger Cola\\n",
3927 "1",
3928 "3",
3929 "1"
3930 ]
3931 },
3932 {
3933 "-name": "question264",
3934 "item": [
3935 "264",
3936 "53",
3937 "public class Call {\\n\\tpublic synchronized void calls(String msg) {\\n\\t\\tSystem.out.print(\" +375 -29 -\");\\n\\t\\tSystem.out.print(msg);\\n\\t\\tSystem.out.println(\" mts\");\\n\\t}\\n\\n\\tpublic void call(String msg) {\\n\\t\\tSystem.out.print(\" +375 -29 -\");\\n\\t\\tSystem.out.print(msg);\\n\\t\\tSystem.out.println(\" mts\");\\n\\t}\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tboolean synchron = true;\\n\\n\\t\\tCall target = new Call();\\n\\t\\tCaller caller1 = new Caller(\"556 -54 -89\", target, synchron);\\n\\t\\tCaller caller2 = new Caller(\"665 -84 -55\", target, synchron);\\n\\t\\tCaller caller3 = new Caller(\"654 -88 -88\", target, synchron);\\n\\t\\tcaller1.t.join();\\n\\t\\tcaller2.t.join();\\n\\t\\tcaller3.t.join();\\n\\t\\tSystem.out.println(\" \");\\n\\n\\t\\tsynchron = false;\\n\\n\\t\\tCaller caller4 = new Caller(\"556 -54 -89\", target, synchron);\\n\\t\\tCaller caller5 = new Caller(\"665 -84 -55\", target, synchron);\\n\\t\\tCaller caller6 = new Caller(\"654 -88 -88\", target, synchron);\\n\\t\\tcaller4.t.join();\\n\\t\\tcaller5.t.join();\\n\\t\\tcaller6.t.join();\\n\\t}\\n}\\n",
3938 "public class Caller implements Runnable {\\n\\tThread t;\\n\\tString msg;\\n\\tCall target;\\n\\tboolean synchron;\\n\\n\\tCaller(String msg, Call target, boolean synchron) {\\n\\t\\tthis.msg = msg;\\n\\t\\tthis.target = target;\\n\\t\\tthis.synchron = synchron;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tif (synchron) {\\n\\t\\t\\ttarget.call(msg);\\n\\t\\t} else {\\n\\t\\t\\ttarget.calls(msg);\\n\\t\\t}\\n\\t}\\n}\\n",
3939 "The program displays three phone numbers. At the first time the program uses no synchronized method. At the second time the program uses synchronized method.\\n\\nPossible output:\\n\\n +375 -29 -665 -84 -55 +375 -29 -556 -54 -89 mts\\n mts\\n +375 -29 -654 -88 -88 mts\\n\\n +375 -29 -556 -54 -89 mts\\n +375 -29 -665 -84 -55 mts\\n +375 -29 -654 -88 -88 mts\\n",
3940 "+ 375 -29 -665 -84 -55 +375 -29 -556 -54 -89 mts\\n mts\\n +375 -29 -654 -88 -88 mts\\n\\n +375 -29 -556 -54 -89 mts\\n +375 -29 -665 -84 -55 mts\\n +375 -29 -654 -88 -88 mts\\n",
3941 "1",
3942 "3",
3943 "4"
3944 ]
3945 },
3946 {
3947 "-name": "question265",
3948 "item": [
3949 "265",
3950 "53",
3951 "public class Caller implements Runnable {\\n\\tThread t;\\n\\tString msg;\\n\\tCall target;\\n\\tboolean synchron;\\n\\n\\tCaller(String msg, Call target, boolean synchron) {\\n\\t\\tthis.msg = msg;\\n\\t\\tthis.target = target;\\n\\t\\tthis.synchron = synchron;\\n\\t\\tt = new Thread(this);\\n\\t\\tt.start();\\n\\t}\\n\\n\\tpublic void run() {\\n\\t\\tif (synchron) {\\n\\t\\t\\ttarget.call(msg);\\n\\t\\t} else {\\n\\t\\t\\ttarget.calls(msg);\\n\\t\\t}\\n\\t}\\n}\\n",
3952 "public class Call {\\n\\tpublic synchronized void calls(String msg) {\\n\\t\\tSystem.out.print(\" +375 -29 -\");\\n\\t\\tSystem.out.print(msg);\\n\\t\\tSystem.out.println(\" mts\");\\n\\t}\\n\\n\\tpublic void call(String msg) {\\n\\t\\tSystem.out.print(\" +375 -29 -\");\\n\\t\\tSystem.out.print(msg);\\n\\t\\tSystem.out.println(\" mts\");\\n\\t}\\n\\n\\tpublic static void main(String[] args) throws InterruptedException {\\n\\t\\tboolean synchron = true;\\n\\n\\t\\tCall target = new Call();\\n\\t\\tCaller caller1 = new Caller(\"556 -54 -89\", target, synchron);\\n\\t\\tCaller caller2 = new Caller(\"665 -84 -55\", target, synchron);\\n\\t\\tCaller caller3 = new Caller(\"654 -88 -88\", target, synchron);\\n\\t\\tcaller1.t.join();\\n\\t\\tcaller2.t.join();\\n\\t\\tcaller3.t.join();\\n\\t\\tSystem.out.println(\" \");\\n\\n\\t\\tsynchron = false;\\n\\n\\t\\tCaller caller4 = new Caller(\"556 -54 -89\", target, synchron);\\n\\t\\tCaller caller5 = new Caller(\"665 -84 -55\", target, synchron);\\n\\t\\tCaller caller6 = new Caller(\"654 -88 -88\", target, synchron);\\n\\t\\tcaller4.t.join();\\n\\t\\tcaller5.t.join();\\n\\t\\tcaller6.t.join();\\n\\t}\\n}\\n",
3953 "The program displays three phone numbers. At the first time the program uses no synchronized method. At the second time the program uses synchronized method. \\n\\nPossible output:\\n\\n +375 -29 -665 -84 -55 +375 -29 -556 -54 -89 mts\\n mts\\n +375-29-654-88-88 mts\\n\\n +375 -29 -556 -54 -89 mts\\n +375 -29 -665 -84 -55 mts\\n +375 -29 -654 -88 -88 mts\\n",
3954 "+375 -29 -665 -84 -55 +375 -29 -556 -54 -89 mts\\n mts\\n +375 -29 -654 -88 -88 mts\\n \\n +375 -29 -556 -54 -89 mts\\n +375 -29 -665 -84 -55 mts\\n +375 -29 -654 -88 -88 mts\\n",
3955 "1",
3956 "3",
3957 "1"
3958 ]
3959 },
3960 {
3961 "-name": "question266",
3962 "item": [
3963 "266",
3964 "54",
3965 "public class Gds {\\n\\n\\tString name;\\n\\tint price;\\n\\tType t;\\n\\n\\tGds(String name, int price, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.price = price;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tGds[] goods = new Gds[5];\\n\\t\\tgoods[0] = new Gds(\"Chair\", 20, Type.ForChildren);\\n\\t\\tgoods[1] = new Gds(\"Chair\", 13, Type.Furniture);\\n\\t\\tgoods[2] = new Gds(\"Carpet\", 28, Type.ProductsForAuto);\\n\\t\\tgoods[3] = new Gds(\"Carpet\", 45, Type.House);\\n\\t\\tgoods[4] = new Gds(\"Dress\", 38.9, Type.Сlothes);\\n\\t\\tfor (int i = 0; i < 5; i++) {\\n\\t\\t\\tSystem.out.print(goods[i].name + \", price: \" + goods[i].price);\\n\\t\\t\\tSystem.out.println(\" dol. \" + goods[i].t + \" department.\");\\n\\t\\t}\\n\\t}\\n}\\n",
3966 "public enum Type {\\n\\tFood, ProductsForAuto, Cars, Toys, House, Garlen,\\n\\tSport, Helth, Medicine, Furniture, ForMoms, Video,\\n \\tForChildren, ProductsForConstruction, Сlothes, Other\\n}\\n",
3967 "The program displays the product name, its type and the department in which it is sold.\\n\\nOutput:\\n\\nChair, price: 20 dol. ForChildren department.\\nChair, price: 13 dol. Furniture department.\\nCarpet, price: 28 dol. ProductsForAuto department.\\nCarpet, price: 45 dol. House department.\\nDress, price: 38.90 dol. Сlothes department.\\n",
3968 "Chair, price: 20 dol. ForChildren department.\\nChair, price: 13 dol. Furniture department.\\nCarpet, price: 28 dol. ProductsForAuto department.\\nCarpet, price: 45 dol. House department.\\nDress, price: 38.90 dol. Сlothes department.\\n",
3969 "1",
3970 "3",
3971 "15"
3972 ]
3973 },
3974 {
3975 "-name": "question267",
3976 "item": [
3977 "267",
3978 "54",
3979 "public class User {\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tUser[] user = new User[5];\\n\\t\\tuser[0] = new User(\"Alice\", Area.Atlanta, Type.NormalUser);\\n\\t\\tuser[1] = new User(\"Bill\", Area.Baltimor, Type.Admin);\\n\\t\\tuser[2] = new User(\"Bella\", Area.Boston, Type.Moderator);\\n\\t\\tuser[3] = new User(\"Alex\", Area.Chicago, Type.ExperiencedUser);\\n\\t\\tuser[4] = new User(\"Julia\", Area.Other, Type.Beginner);\\n\\t\\tfor (int i = 0; i < 5; i++) {\\n\\t\\t\\tSystem.out.print(user[i].t + \" \" + user[i].name);\\n\\t\\t\\tSystem.out.println(\" \" + user[i].region);\\n\\t\\t}\\n\\t}\\n}\\n",
3980 "public enum Area {\\n\\tFrisco, Atlanta, Dallas, Baltimor, Boston, Chicago, Other\\n}\\n",
3981 "public enum Type {\\n\\tBeginner, NormalUser, ExperiencedUser, Moderator, Admin\\n}\\n",
3982 "The program displays the status of the user, his name and the city of residence.\\n\\nOutput:\\n\\nNormalUser Alice Atlanta\\nAdmin Bill Baltimor\\nModerator Bella Boston\\nExperiencedUser Alex Chicago\\nBeginner Julia Other\\n",
3983 "NormalUser Alice Atlanta\\nAdmin Bill Baltimor\\nModerator Bella Boston\\nExperiencedUser Alex Chicago\\nBeginner Julia Other\\n",
3984 "1",
3985 "3",
3986 "9"
3987 ]
3988 },
3989 {
3990 "-name": "question268",
3991 "item": [
3992 "268",
3993 "54",
3994 "public class Plum {\\n\\n\\tName name;\\n\\tTyp types;\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tPlum plum1 = new Plum();\\n\\t\\tplum1.name = Name.AnnaSpath;\\n\\t\\tplum1.types = Typ.Purple;\\n\\n\\t\\tPlum plum2 = new Plum();\\n\\t\\tplum2.name = Name.BlueBird;\\n\\t\\tplum2.types = Typ.Ripening;\\n\\n\\t\\tPlum plum3 = new Plum();\\n\\t\\tplum3.name = Name.Alexis;\\n\\t\\tplum3.types = Typ.Yellow;\\n\\n\\t\\tSystem.out.println(\"Plum \" + plum1.name + \", \" + plum1.types + \" type \");\\n\\t\\tSystem.out.println(\"Plum \" + plum2.name + \", \" + plum2.types + \" type \");\\n\\t\\tSystem.out.println(\"Plum \" + plum3.name + \", \" + plum3.types + \" type \");\\n\\t}\\n}\\n",
3995 "public enum Name {\\n\\tAkimov, Alexis, BlueBird, AnnaSpath, Stanley\\n}\\n",
3996 "public enum Typ {\\n\\tYellow, Ripening, Blue, WinterGrade, Purple\\n}\\n",
3997 "The program displays sorts and views of plum.\\n\\nOutput:\\n\\nPlum AnnaSpath, Purple type\\nPlum BlueBird, Ripening type\\nPlum Alexis, Yellow type\\n",
3998 "Plum AnnaSpath, Purple type\\nPlum BlueBird, Ripening type\\nPlum Alexis, Yellow type\\n",
3999 "1",
4000 "3",
4001 "5"
4002 ]
4003 },
4004 {
4005 "-name": "question269",
4006 "item": [
4007 "269",
4008 "54",
4009 "public class Gds {\\n\\n\\tString name;\\n\\tint price;\\n\\tType t;\\n\\n\\tGds(String name, int price, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.price = price;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString str = name + \", price: \" + price + \" dol. \" + t + \" department.\";\\n\\t\\treturn str;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tGds goods1 = new Gds(\"Chair\", 20, Type.ForChildren);\\n\\t\\tGds goods2 = new Gds(\"Carpet\", 45, Type.House);\\n\\t\\tGds goods3 = new Gds(\"Dress\", 38.90, Type.Сlothes);\\n\\t\\tSystem.out.println(goods1.toString());\\n\\t\\tSystem.out.println(goods2.toString());\\n\\t\\tSystem.out.println(goods3.toString());\\n\\t}\\n}\\n",
4010 "public enum Type {\\n\\tFood, ProductsForAuto, Cars, Toys, House, Garlen,\\n\\tSport, Helth, Medicine, Furniture, ForMoms, Video,\\n \\tForChildren, ProductsForConstruction, Сlothes, Other\\n}\\n",
4011 "The program displays the product name, its type and the department in which it is sold.\\n\\nOutput:\\n\\nChair, price: 20 dol. ForChildren department.\\nCarpet, price: 45 dol. House department.\\nDress, price: 38.90 dol. Сlothes department.\\n",
4012 "Chair, price: 20 dol. ForChildren department.\\nCarpet, price: 45 dol. House department.\\nDress, price: 38.90 dol. Сlothes department.\\n",
4013 "1",
4014 "3",
4015 "15"
4016 ]
4017 },
4018 {
4019 "-name": "question270",
4020 "item": [
4021 "270",
4022 "54",
4023 "public class User {\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic void printUser() {\\n\\t\\tSystem.out.println(this.t + \" \" + this.name + \" \" + this.region);\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tUser user1 = new User(\"Alice\", Area.Atlanta, Type.NormalUser);\\n\\t\\tuser1.printUser();\\n\\t\\tuser1.t = Type.ExperiencedUser;\\n\\t\\tuser1.printUser();\\n\\t\\tuser1.t = Type.Admin;\\n\\t\\tuser1.printUser();\\n\\t\\tuser1.region = Area.Frisco;\\n\\t\\tuser1.printUser();\\n\\t}\\n}\\n",
4024 "public enum Area {\\n\\tFrisco, Atlanta, Dallas, Baltimor, Boston, Chicago, Other\\n}\\n",
4025 "public enum Type {\\n\\tBeginner, NormalUser, ExperiencedUser, Moderator, Admin\\n}\\n",
4026 "The program displays the status of the user, his name and city of residence. Then the program changes the status or place of residence of the user and displays again.\\n\\nOutput:\\n\\nNormalUser Alice Atlanta\\nExperiencedUser Alice Atlanta\\nAdmin Alice Atlanta\\nAdmin Alice Frisco\\n",
4027 "NormalUser Alice Atlanta\\nExperiencedUser Alice Atlanta\\nAdmin Alice Atlanta\\nAdmin Alice Frisco\\n",
4028 "1",
4029 "3",
4030 "1"
4031 ]
4032 },
4033 {
4034 "-name": "question271",
4035 "item": [
4036 "271",
4037 "55",
4038 "public class Gds {\\n\\n\\tString name;\\n\\tint price;\\n\\tType t;\\n\\n\\tGds(String name, int price, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.price = price;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tType typ;\\n\\t\\ttyp = Type.valueOf(\"Furniture\");\\n\\n\\t\\tGds gds1 = new Gds(\"Chair\", 20, Type.ForChildren);\\n\\t\\tSystem.out.println(gds1.name + \", \" + gds1.price + \" dol. \" + gds1.t);\\n\\t\\tgds1.t = typ;\\n\\t\\tSystem.out.println(gds1.name + \", \" + gds1.price + \" dol. \" + gds1.t);\\n\\n\\t\\tType typesOfGoods[] = Type.values();\\n\\t\\tfor (Type t : typesOfGoods) {\\n\\t\\t\\tSystem.out.println(t);\\n\\t\\t}\\n\\t}\\n}\\n",
4039 "public enum Type {\\n\\tFood, ProductsForAuto, Cars, Toys, House, Garlen,\\n\\tSport, Helth, Medicine, Furniture, ForMoms, Video,\\n\\tForChildren, ProductsForConstruction, Сlothes, Other\\n}\\n",
4040 "The program displays the name of the product, its price and the department where it is sold. After that the program changes the department and displays a list of departments in the store.\\n\\nOutput:\\n\\nChair, 20 dol. ForChildren\\nChair, 20 dol. Furniture\\nFood\\nProductsForAuto\\nCars\\nToys\\nHouse\\nGarlen\\nSport\\nHelth\\nMedicine\\nFurniture\\nForMoms\\nVideo\\nForChildren\\nProductsForConstruction\\nСlothes\\nOther\\n",
4041 "Chair, 20 dol. ForChildren\\nChair, 20 dol. Furniture\\nFood\\nProductsForAuto\\nCars\\nToys\\nHouse\\nGarlen\\nSport\\nHelth\\nMedicine\\nFurniture\\nForMoms\\nVideo\\nForChildren\\nProductsForConstruction\\nСlothes\\nOther\\n",
4042 "1",
4043 "3",
4044 "86"
4045 ]
4046 },
4047 {
4048 "-name": "question272",
4049 "item": [
4050 "272",
4051 "55",
4052 "public class Plum {\\n\\n\\tName name;\\n\\tType types;\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tPlum plum1 = new Plum();\\n\\t\\tplum1.name = Name.AnnaSpath;\\n\\t\\tplum1.types = Type.Purple;\\n\\t\\tSystem.out.println(\"Plum \" + plum1.name + \", \" + plum1.types + \" type \");\\n\\t\\tplum1.name = Name.valueOf(\"Stanley\");\\n\\t\\tplum1.types = Type.Yellow;\\n\\t\\tSystem.out.println(\"Plum \" + plum1.name + \", \" + plum1.types + \" type \" );\\n\\t\\tSystem.out.println(\" \");\\n\\n\\t\\tfor (Name n : Name.values()) {\\n\\t\\t\\tSystem.out.println(n);\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Type t : Type.values()) {\\n\\t\\t\\tSystem.out.println(t);\\n\\t\\t}\\n\\t}\\n}\\n",
4053 "public enum Name {\\n\\tAkimov, Alexis, BlueBird, AnnaSpath, Stanley\\n}\\n",
4054 "public enum Type {\\n\\tYellow, Ripening, Blue, WinterGrade, Purple\\n}\\n",
4055 "The program displays a sort of plum and its type. Then the program displays all sorts of plums and all kinds of plums.\\n\\nOutput:\\n\\nPlum AnnaSpath, Purple type\\nPlum Stanley, Yellow type\\n\\nAkimov\\nAlexis\\nBlueBird\\nAnnaSpath\\nStanley\\n\\nYellow\\nRipening\\nBlue\\nWinterGrade\\nPurple\\n",
4056 "Plum AnnaSpath, Purple type\\nPlum Stanley, Yellow type\\n\\nAkimov\\nAlexis\\nBlueBird\\nAnnaSpath\\nStanley\\n\\nYellow\\nRipening\\nBlue\\nWinterGrade\\nPurple\\n",
4057 "1",
4058 "2",
4059 "92"
4060 ]
4061 },
4062 {
4063 "-name": "question273",
4064 "item": [
4065 "273",
4066 "55",
4067 "public class User {\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tUser user1 = new User(\"Alice\", Area.Atlanta, Type.NormalUser);\\n\\t\\tSystem.out.println(user1.t + \" \" + user1.name + \" \" + user1.region);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Area a : Area.values()) {\\n\\t\\t\\tSystem.out.println(a + \" \" + a.getCountry());\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Type t : Type.values()) {\\n\\t\\t\\tSystem.out.println(t + \", the minimum rating \" + t.getReiting());\\n\\t\\t}\\n\\t}\\n}\\n",
4068 "public enum Area {\\n\\tFrisco(\"USA\"), Atlanta(\"USA\"), Dallas(\"USA\"), Baltimor(\"USA\"),\\n\\tBoston(\"USA\"), Chicago(\"USA\"), Other(\"\");\\n\\tprivate String country;\\n\\n\\tArea(String country) {\\n\\t\\tthis.country = country;\\n\\t}\\n\\n\\tpublic String getCountry() {\\n\\t\\treturn country;\\n\\t}\\n}\\n",
4069 "public enum Type {\\n\\tBeginner(0), NormalUser(10), ExperiencedUser(20), Moderator(50), Admin(100);\\n\\n\\tprivate int reiting;\\n\\n\\tType(int reiting) {\\n\\t\\tthis.reiting = reiting;\\n\\t}\\n\\n\\tpublic int getReiting() {\\n\\t\\treturn reiting;\\n\\t}\\n}\\n",
4070 "The program displays the status of the user, his name and the city of residence. Then the program displays a list of cities with countries and a list of possible statuses of users with minimum ratings to achieve these statuses.\\n\\nOutput:\\n\\nNormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4071 "NormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4072 "1",
4073 "2",
4074 "140"
4075 ]
4076 },
4077 {
4078 "-name": "question274",
4079 "item": [
4080 "274",
4081 "55",
4082 "public enum Area {\\n\\tFrisco(\"USA\"), Atlanta(\"USA\"), Dallas(\"USA\"), Baltimor(\"USA\"),\\n\\tBoston(\"USA\"), Chicago(\"USA\"), Other(\"\");\\n\\tprivate String country;\\n\\n\\tArea(String country) {\\n\\t\\tthis.country = country;\\n\\t}\\n\\n\\tpublic String getCountry() {\\n\\t\\treturn country;\\n\\t}\\n}\\n",
4083 "public class User {\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tUser user1 = new User(\"Alice\", Area.Atlanta, Type.NormalUser);\\n\\t\\tSystem.out.println(user1.t + \" \" + user1.name + \" \" + user1.region);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Area a : Area.values()) {\\n\\t\\t\\tSystem.out.println(a + \" \" + a.getCountry());\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Type t : Type.values()) {\\n\\t\\t\\tSystem.out.println(t + \", the minimum rating \" + t.getReiting());\\n\\t\\t}\\n\\t}\\n}\\n",
4084 "public enum Type {\\n\\tBeginner(0), NormalUser(10), ExperiencedUser(20), Moderator(50), Admin(100);\\n\\n\\tprivate int reiting;\\n\\n\\tType(int reiting) {\\n\\t\\tthis.reiting = reiting;\\n\\t}\\n\\n\\tpublic int getReiting() {\\n\\t\\treturn reiting;\\n\\t}\\n}\\n",
4085 "The program displays the status of the user, his name and the city of residence. Then the program displays a list of cities with countries and a list of possible statuses of users with minimum ratings to achieve these statuses.\\n\\nOutput:\\n\\nNormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4086 "NormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4087 "1",
4088 "2",
4089 "1"
4090 ]
4091 },
4092 {
4093 "-name": "question275",
4094 "item": [
4095 "275",
4096 "55",
4097 "public enum Type {\\n\\tBeginner(0), NormalUser(10), ExperiencedUser(20), Moderator(50), Admin(100);\\n\\n\\tprivate int reiting;\\n\\n\\tType(int reiting) {\\n\\t\\tthis.reiting = reiting;\\n\\t}\\n\\n\\tpublic int getReiting() {\\n\\t\\treturn reiting;\\n\\t}\\n}\\n",
4098 "public class User {\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tUser user1 = new User(\"Alice\", Area.Atlanta, Type.NormalUser);\\n\\t\\tSystem.out.println(user1.t + \" \" + user1.name + \" \" + user1.region);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Area a : Area.values()) {\\n\\t\\t\\tSystem.out.println(a + \" \" + a.getCountry());\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Type t : Type.values()) {\\n\\t\\t\\tSystem.out.println(t + \", the minimum rating \" + t.getReiting());\\n\\t\\t}\\n\\t}\\n}\\n",
4099 "public enum Area {\\n\\tFrisco(\"USA\"), Atlanta(\"USA\"), Dallas(\"USA\"), Baltimor(\"USA\"),\\n\\tBoston(\"USA\"), Chicago(\"USA\"), Other(\"\");\\n\\tprivate String country;\\n\\n\\tArea(String country) {\\n\\t\\tthis.country = country;\\n\\t}\\n\\n\\tpublic String getCountry() {\\n\\t\\treturn country;\\n\\t}\\n}\\n",
4100 "The program displays the status of the user, his name and the city of residence. Then the program displays a list of cities with countries and a list of possible statuses of users with minimum ratings to achieve these statuses.\\n\\nOutput:\\n\\nNormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4101 "NormalUser Alice Atlanta\\n\\nFrisco USA\\nAtlanta USA\\nDallas USA\\nBaltimor USA\\nBoston USA\\nChicago USA\\nOther\\n\\nBeginner, the minimum rating 0\\nNormalUser, the minimum rating 10\\nExperiencedUser, the minimum rating 20\\nModerator, the minimum rating 50\\nAdmin, the minimum rating 100\\n",
4102 "1",
4103 "2",
4104 "1"
4105 ]
4106 },
4107 {
4108 "-name": "question276",
4109 "item": [
4110 "276",
4111 "56",
4112 "public class Gds {\\n\\tString name;\\n\\tint price;\\n\\tType t;\\n\\tGds(String name, int price, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.price = price;\\n\\t\\tthis.t = t;\\n\\t}\\n\\tpublic String toString() {\\n\\t\\tString str = name + \", price: \" + price + \" dol. \" + t + \" department. \";\\n\\t\\treturn str;\\n\\t}\\n\\tpublic static void main(String[] args) {\\n\\t\\tGds goods1 = new Gds(\"Chair\", 20, Type.ForChildren);\\n\\t\\tGds goods2 = new Gds(\"Carpet\", 45, Type.House);\\n\\t\\tGds goods3 = new Gds(\"Dress\", 38.90, Type.Сlothes);\\n\\n\\t\\tSystem.out.print(goods1.toString());\\n\\t\\tSystem.out.println(\"Department №\" + goods1.t.ordinal());\\n\\t\\tSystem.out.print(goods2.toString());\\n\\t\\tSystem.out.println(\"Department №\" + goods2.t.ordinal());\\n\\t\\tSystem.out.print(goods3.toString());\\n\\t\\tSystem.out.println(\"Department №\" + goods3.t.ordinal());\\n\\t}\\n}\\n",
4113 "public enum Type {\\n\\tFood, ProductsForAuto, Cars, Toys, House, Garlen,\\n\\tSport, Helth, Medicine, Furniture, ForMoms, Video,\\n\\tForChildren, ProductsForConstruction, Сlothes, Other\\n}\\n",
4114 "The program displays the name of the product, its price, the department in which the product is sold, and the serial number of the department.\\n\\nOutput:\\n\\nChair, price: 20 dol. ForChildren department. Department №12\\nCarpet, price: 45 dol. House department. Department №4\\nDress, price: 38.90 dol. Сlothes department. Department №14\\n",
4115 "Chair, price: 20 dol. ForChildren department. Department №12\\nCarpet, price: 45 dol. House department. Department №4\\nDress, price: 38.90 dol. Сlothes department. Department №14\\n",
4116 "1",
4117 "1",
4118 "193"
4119 ]
4120 },
4121 {
4122 "-name": "question277",
4123 "item": [
4124 "277",
4125 "56",
4126 "public class Unit {// the compareTo()method \\n\\tstatic String under = \" has a lower rank than \";\\n\\tstatic String above = \" has a higher rank than \";\\n\\tstatic String equa = \" has the rank as \";\\n\\tString surname;\\n\\tRank rank;\\n\\tUnit(String surname, Rank rank) {\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.rank = rank;\\n\\t}\\n\\tpublic static void main(String[] args) {\\n\\t\\tUnit officer1 = new Unit(\"Smith\", Rank.Sublieutenant);\\n\\t\\tUnit officer2 = new Unit(\"Johnson\", Rank.Lieutenant);\\n\\t\\tUnit officer3 = new Unit(\"Williams\", Rank.Captain);\\n\\t\\tUnit officer4 = new Unit(\"Jones\", Rank.Major);\\n\\t\\tUnit officer5 = new Unit(\"Brown\", Rank.Major);\\n\\t\\tUnit.rankCampare(officer1, officer2);\\n\\t\\tUnit.rankCampare(officer3, officer4);\\n\\t\\tUnit.rankCampare(officer4, officer5);\\n\\t}\\n\\tstatic public void rankCampare(Unit officer1, Unit officer2) {\\n\\t\\tif (officer1.rank.compareTo(officer2.rank) < 0) {\\n\\t\\t\\tSystem.out.println(officer1.surname + under + officer2.surname);\\n\\t\\t} else if (officer1.rank.compareTo(officer2.rank) > 0) {\\n\\t\\t\\tSystem.out.println(officer1.surname + above + officer2.surname);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(officer1.surname + equa + officer2.surname);\\n\\t\\t}\\n\\t}\\n}\\n",
4127 "public enum Rank {\\n\\tSublieutenant, Lieutenant, Captain, Major, LieutenantColonel, Colonel\\n}\\n",
4128 "The program compares: who has higher rank.\\n\\nOutput:\\n\\nSwith has a lower rank than Johnson\\nWilliams has a lower rank than Jones\\nJones has the rank as Brown\\n",
4129 "Swith has a lower rank than Johnson\\nWilliams has a lower rank than Jones\\nJones has the rank as Brown\\n",
4130 "1",
4131 "2",
4132 "242"
4133 ]
4134 },
4135 {
4136 "-name": "question278",
4137 "item": [
4138 "278",
4139 "56",
4140 "public class Unit { // the equals()method \\n\\tstatic String noEqua = \" has a different rank than \";\\n\\tstatic String equa = \" has the rank as \";\\n\\tString surname;\\n\\tRank rank;\\n\\tUnit(String surname, Rank rank) {\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.rank = rank;\\n\\t}\\n\\tpublic static void main(String[] args) {\\n\\t\\tUnit officer1 = new Unit(\"Smith\", Rank.Sublieutenant);\\n\\t\\tUnit officer2 = new Unit(\"Johnson\", Rank.Lieutenant);\\n\\t\\tUnit officer3 = new Unit(\"Williams\", Rank.Captain);\\n\\t\\tUnit officer4 = new Unit(\"Jones\", Rank.Major);\\n\\t\\tUnit officer5 = new Unit(\"Brown\", Rank.Major);\\n\\t\\tUnit.rankEqual(officer1, officer2);\\n\\t\\tUnit.rankEqual(officer3, officer4);\\n\\t\\tUnit.rankEqual(officer4, officer5);\\n\\t}\\n\\tstatic public void rankEqual(Unit officer1, Unit officer2) {\\n\\t\\tif (officer1.rank.equals(officer2.rank)) {\\n\\t\\t\\tSystem.out.println(officer1.surname + equa + officer2.surname);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(officer1.surname + noEqua + officer2.surname);\\n\\t\\t}\\n\\t}\\n}\\n",
4141 "public enum Rank {\\n\\tSublieutenant, Lieutenant, Captain, Major, LieutenantColonel, Colonel\\n}\\n",
4142 "The program compares officers by rank.\\n\\nOutput:\\n\\nSmith has a different rank than Johnson\\nWilliams has a different rank than Jones\\nJones has the rank as Brown\\n",
4143 "Smith has a different rank than Johnson\\nWilliams has a different rank than Jones\\nJones has the rank as Brown\\n",
4144 "1",
4145 "1",
4146 "228"
4147 ]
4148 },
4149 {
4150 "-name": "question279",
4151 "item": [
4152 "279",
4153 "56",
4154 "public class Unit {// == analogue of equal()\\n\\tstatic String noEqua = \" has a different rank than \";\\n\\tstatic String equa = \" has the rank as \";\\n\\tString surname;\\n\\tRank rank;\\n\\tUnit(String surname, Rank rank) {\\n\\t\\tthis.surname = surname;\\n\\t\\tthis.rank = rank;\\n\\t}\\n\\tpublic static void main(String[] args) {\\n\\t\\tUnit officer1 = new Unit(\"Smith\", Rank.Sublieutenant);\\n\\t\\tUnit officer2 = new Unit(\"Johnson\", Rank.Lieutenant);\\n\\t\\tUnit officer3 = new Unit(\"Williams\", Rank.Captain);\\n\\t\\tUnit officer4 = new Unit(\"Jones\", Rank.Major);\\n\\t\\tUnit officer5 = new Unit(\"Brown\", Rank.Major);\\n\\t\\tUnit.rankEqual(officer1, officer2);\\n\\t\\tUnit.rankEqual(officer3, officer4);\\n\\t\\tUnit.rankEqual(officer4, officer5);\\n\\t}\\n\\tstatic public void rankEqual(Unit officer1, Unit officer2) {\\n\\t\\tif (officer1.rank == officer2.rank) {\\n\\t\\t\\tSystem.out.println(officer1.surname + equa + officer2.surname);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(officer1.surname + noEqua + officer2.surname);\\n\\t\\t}\\n\\t}\\n}\\n",
4155 "public enum Rank {\\n\\tSublieutenant, Lieutenant, Captain, Major, LieutenantColonel, Colonel\\n}\\n",
4156 "The program compares officers by rank.\\n\\nOutput:\\n\\nSmith has a different rank than Johnson\\nWilliams has a different rank than Jones\\nJones has the rank as Brown\\n",
4157 "Smith has a different rank than Johnson\\nWilliams has a different rank than Jones\\nJones has the rank as Brown\\n",
4158 "1",
4159 "1",
4160 "230"
4161 ]
4162 },
4163 {
4164 "-name": "question280",
4165 "item": [
4166 "280",
4167 "56",
4168 "public class User { // ordinal() method\\n\\tString name;\\n\\tArea region;\\n\\tType t;\\n\\tUser(String name, Area region, Type t) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.region = region;\\n\\t\\tthis.t = t;\\n\\t}\\n\\tpublic static void main(String[] args) {\\n\\t\\tfor (Area a : Area.values()) {\\n\\t\\t\\tSystem.out.println(a + \" ordinal â„– \" + a.ordinal());\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Type t : Type.values()) {\\n\\t\\t\\tSystem.out.println(t + \" ordinal â„– \" + t.ordinal());\\n\\t\\t}\\n\\t}\\n}\\n",
4169 "public enum Area {\\n\\tFrisco, Atlanta, Dallas, Baltimor, Boston, Chicago, Other\\n}\\n",
4170 "public enum Type {\\n\\tBeginner, NormalUser, ExperiencedUser, Moderator, Admin\\n}\\n",
4171 "The program displays cities, which are written in the enum, and displays their ordinal numbers.Then the program displays statuses of users, which are also recorded in the enum, and displays their ordinal numbers.\\n\\nOutput:\\n\\nFrisco ordinal â„– 0\\nAtlanta ordinal â„– 1\\nDallas ordinal â„– 2\\nBaltimor ordinal â„– 3\\nBoston ordinal â„– 4\\nChicago ordinal â„– 5\\nOther ordinal â„– 6\\n\\nBeginner ordinal â„– 0\\nNormalUser ordinal â„– 1\\nExperiencedUser ordinal â„– 2\\nModerator ordinal â„– 3\\nAdmin ordinal â„– 4\\n",
4172 "Frisco ordinal â„– 0\\nAtlanta ordinal â„– 1\\nDallas ordinal â„– 2\\nBaltimor ordinal â„– 3\\nBoston ordinal â„– 4\\nChicago ordinal â„– 5\\nOther ordinal â„– 6\\n\\nBeginner ordinal â„– 0\\nNormalUser ordinal â„– 1\\nExperiencedUser ordinal â„– 2\\nModerator ordinal â„– 3\\nAdmin ordinal â„– 4\\n",
4173 "1",
4174 "1",
4175 "84"
4176 ]
4177 },
4178 {
4179 "-name": "question281",
4180 "item": [
4181 "281",
4182 "57",
4183 "import java.io.File;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile dir1 = new File(\"New Dir\");\\n\\t\\tdir1.mkdir();\\n\\t\\tSystem.out.println(\"Does the directory '\" + dir1.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ dir1.exists());\\n\\t\\tSystem.out.println(\"Is \" + dir1.getName() + \" a file? \" + dir1.isFile());\\n\\t\\tSystem.out.println(\"Is \" + dir1.getName() + \" a directory? \" + dir1.isDirectory());\\n\\t\\tFile dir2 = new File(\"New Directory\");\\n\\t\\tdir1.renameTo(dir2);\\n\\t\\tSystem.out.println(\"Directory '\" + dir2.getName() + \"'\");\\n\\t\\tFile dir3 = new File(\"New Direc\");\\n\\t\\tdir3.mkdir();\\n\\t\\tSystem.out.println(\"Does the directory '\" + dir3.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ dir3.exists());\\n\\t\\tdir3.delete();\\n\\t\\tSystem.out.println(\"Does the directory '\" + dir3.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ dir3.exists());\\n\\t}\\n}\\n",
4184 "The program creates a new folder \"New Dir\" and checks: is it a file or a directory. Then, the program renames the folder in the \"New Directory\", then creates a folder \"New Direc\" and removes it.\\n\\nOutput:\\n\\nDoes the directory 'New Dir' exist? true\\nIs New Dir a file? false\\nIs New Dir a directory? true\\nDirectory 'New Directory'\\nDoes the directory 'New Direc' exist? true\\nDoes the directory 'New Direc' exist? false\\n",
4185 "Does the directory 'New Dir' exist? true\\nIs New Dir a file? false\\nIs New Dir a directory? true\\nDirectory 'New Directory'\\nDoes the directory 'New Direc' exist? true\\nDoes the directory 'New Direc' exist? false\\n",
4186 "1",
4187 "3",
4188 "1"
4189 ]
4190 },
4191 {
4192 "-name": "question282",
4193 "item": [
4194 "282",
4195 "57",
4196 "import java.io.File;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tfile1.createNewFile();\\n\\t\\tSystem.out.println(\"Does the file '\" + file1.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ file1.exists());\\n\\t\\tSystem.out.println(\"Absolute path-\" + file1.getAbsolutePath());\\n\\t\\tFile file2 = new File(\"file2.txt\");\\n\\t\\tfile2.createNewFile();\\n\\t\\tSystem.out.println(\"Absolute path-\" + file2.getAbsolutePath());\\n\\t\\tFile file3 = new File(\"file3.txt\");\\n\\t\\tSystem.out.println(\"Absolute path-\" + file3.getAbsolutePath());\\n\\t\\tfile2.renameTo(file3);\\n\\t\\tSystem.out.println(\"Does the file '\" + file2.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ file2.exists());\\n\\t\\tSystem.out.println(\"Does the file '\" + file3.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ file3.exists());\\n\\t\\tfile3.delete();\\n\\t\\tSystem.out.println(\"Does the file '\" + file3.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ file3.exists());\\n\\t}\\n}\\n",
4197 "The program creates a new file \"file1.txt \", checks the file for existence, and outputs the file path. More then creates 2 files \"file2.txt \" and \"file3.txt \", displays their way, then renames the \"file2.txt \" in \"file3.txt \" and checks files for existence. After that, the program deletes the file \"file3.txt \" and checks the file for existence.\\n\\nOutput:\\n\\nDoes the file 'file1.txt' exist? true\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file1.txt\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file2.txt\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file3.txt\\nDoes the file 'file2.txt' exist? false\\nDoes the file 'file3.txt' exist? true\\nDoes the file 'file3.txt' exist? false\\n",
4198 "Does the file 'file1.txt' exist? true\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file1.txt\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file2.txt\\nAbsolute path-C:\\Users\\User\\workspace\\NewTestLesson57Question282\\file3.txt\\nDoes the file 'file2.txt' exist? false\\nDoes the file 'file3.txt' exist? true\\nDoes the file 'file3.txt' exist? false\\n",
4199 "1",
4200 "3",
4201 "1"
4202 ]
4203 },
4204 {
4205 "-name": "question283",
4206 "item": [
4207 "283",
4208 "57",
4209 "import java.io.File;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tif (file1.exists()) {\\n\\t\\t\\tfile1.delete();\\n\\t\\t}\\n\\t\\tfile1.createNewFile();\\n\\t\\tSystem.out.println(\"Does the file '\" + file1.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ file1.exists());\\n\\t\\tSystem.out.println(\"Is it possible to read ? \" + file1.canRead());\\n\\t\\tSystem.out.println(\"Is it possible to write ? \" + file1.canWrite());\\n\\t\\tfile1.setReadOnly();\\n\\t\\tSystem.out.println(\"Is it possible to write ? \" + file1.canWrite());\\n\\t}\\n}\\n",
4210 "The program creates a new file \"file1.txt\", after removing the file if it already existed. The program checks the file exists and then checks the file for read and write to the file. Then it renames the file status \"read only\" and again checks for the ability to write to the file.\\n\\nOutput:\\n\\nDoes the file 'file1.txt' exist? true\\nIs it possible to read ? true\\nIs it possible to write ? true\\nIs it possible to write ? false\\n",
4211 "Does the file 'file1.txt' exist? true\\nIs it possible to read ? true\\nIs it possible to write ? true\\nIs it possible to write ? false\\n",
4212 "1",
4213 "3",
4214 "1"
4215 ]
4216 },
4217 {
4218 "-name": "question284",
4219 "item": [
4220 "284",
4221 "57",
4222 "import java.io.File;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tfile1.createNewFile();\\n\\t\\tSystem.out.println(\"File takes - \" + file1.length() + \" Kb\");\\n\\t\\tSystem.out.println(\"Free disk space - \" + file1.getTotalSpace() + \" Kb\");\\n\\t\\tSystem.out.println(\"Free space for recording - \" + file1.getFreeSpace()\\n\\t\\t\\t\\t+ \" Kb\");\\n\\t\\tfile1.getFreeSpace();\\n\\t\\tSystem.out.println(\"Time of modification - \" + file1.lastModified());\\n\\t}\\n}\\n",
4223 "The program creates a new file \"file1.txt\" then checks how much space is required for the file, how much free disk space, how much free space for recording and time of last modification.\\n\\nOutput:\\n\\nFile takes - 0 Kb\\nFree disk space - 146002669568 Kb\\nFree space for recording - 94855864320 Kb\\nTime of modification - 1417080493954\\n",
4224 "File takes - 0 Kb\\nFree disk space - 146002669568 Kb\\nFree space for recording - 94855864320 Kb\\nTime of modification - 1417080493954\\n",
4225 "1",
4226 "3",
4227 "1"
4228 ]
4229 },
4230 {
4231 "-name": "question285",
4232 "item": [
4233 "285",
4234 "57",
4235 "import java.io.File;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tString way = \"C:\\\\Users\\\\User\\\\workspace\\\\NewTestLesson57Question285\\\\\";\\n\\t\\tFile direc = new File(way);\\n\\t\\tSystem.out.println(\"Does the directory '\" + direc.getName() + \"' exist? \"\\n\\t\\t\\t\\t+ direc.exists());\\n\\t\\tSystem.out.println(\"\");\\n\\t\\tif (direc.isDirectory()) {\\n\\t\\t\\tSystem.out.println(\"The directory \" + direc.getName()\\n\\t\\t\\t\\t\\t+ \" contains:\");\\n\\t\\t\\tString s[] = direc.list();\\n\\t\\t\\tfor (int i = 0; i < s.length; i++) {\\n\\t\\t\\t\\tFile file = new File(way + s[i]);\\n\\t\\t\\t\\tif (file.isDirectory()) {\\n\\t\\t\\t\\t\\tSystem.out.println(\"directory \" + file.getName());\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tSystem.out.println(\"file \" + file.getName());\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n",
4236 "The program takes the current directory and displays files and folders from the current directory.\\n\\nOutput:\\n\\nDoes the directory 'NewTestLesson57Question285' exist? true\\n\\nThe directory NewTestLesson57Question285 contains:\\nfile .classpath\\nfile .project\\ndirectory .settings\\ndirectory bin\\nfile file1.txt\\ndirectory src\\n",
4237 "Does the directory 'NewTestLesson57Question285' exist? true\\n\\nThe directory NewTestLesson57Question285 contains:\\nfile .classpath\\nfile .project\\ndirectory .settings\\ndirectory bin\\nfile file1.txt\\ndirectory src\\n",
4238 "1",
4239 "3",
4240 "46"
4241 ]
4242 },
4243 {
4244 "-name": "question286",
4245 "item": [
4246 "286",
4247 "58",
4248 "import java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream streamOut1 = new FileOutputStream(file1);\\n\\t\\tFileInputStream streamIn1 = new FileInputStream(file1);\\n\\t\\tint b[] = { 99, 3, 155, 54, 0 };\\n\\t\\tfor (int i = 0; i < b.length; i++) {\\n\\t\\t\\tstreamOut1.write(b[i]);\\n\\t\\t}\\n\\t\\tint res = streamIn1.read();\\n\\t\\twhile (res != -1) {\\n\\t\\t\\tSystem.out.println(res);\\n\\t\\t\\tres = streamIn1.read();\\n\\t\\t}\\n\\t\\tstreamOut1.close();\\n\\t\\tstreamIn1.close();\\n\\t}\\n}\\n",
4249 "The program writes the bit data from an array to a file, and then outputs the bit data on the screen from the file.\\n\\nOutput:\\n\\n99\\n3\\n155\\n54\\n0\\n",
4250 "99\\n3\\n155\\n54\\n0\\n",
4251 "1",
4252 "3",
4253 "55"
4254 ]
4255 },
4256 {
4257 "-name": "question287",
4258 "item": [
4259 "287",
4260 "58",
4261 "import java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream streamOut1 = new FileOutputStream(file1);\\n\\t\\tFileInputStream streamIn1 = new FileInputStream(file1);\\n\\n\\t\\tbyte b = 99;\\n\\t\\tstreamOut1.write(b);\\n\\t\\tb = 65;\\n\\t\\tstreamOut1.write(b);\\n\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\t\\tSystem.out.println(streamIn1.read());\\n\\n\\t\\tstreamOut1.close();\\n\\t\\tstreamIn1.close();\\n\\t}\\n}\\n",
4262 "The program reads the bit data in the file and then displays the data on the screen.\\n\\nOutput:\\n\\n99\\n65\\n-1\\n",
4263 "99\\n65\\n-1\\n",
4264 "1",
4265 "2",
4266 "55"
4267 ]
4268 },
4269 {
4270 "-name": "question288",
4271 "item": [
4272 "288",
4273 "58",
4274 "import java.io.ByteArrayInputStream;\\nimport java.io.ByteArrayOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tbyte btIn[] = { 7, 2, 34, 123 };\\n\\t\\tbyte btOut[] = new byte[4];\\n\\t\\tByteArrayInputStream streamIn1 = new ByteArrayInputStream(btIn);\\n\\t\\tByteArrayOutputStream streamOut1 = new ByteArrayOutputStream();\\n\\n\\t\\tfor (int i = 0; i < btIn.length; i++) {\\n\\t\\t\\tint d = streamIn1.read();\\n\\t\\t\\tSystem.out.println(d);\\n\\t\\t\\tstreamOut1.write(d);\\n\\t\\t}\\n\\n\\t\\tbtOut = streamOut1.toByteArray();\\n\\t\\tstreamIn1.close();\\n\\t\\tfor (int i = 0; i < btOut.length; i++) {\\n\\t\\t\\tSystem.out.println(btOut[i]);\\n\\t\\t}\\n\\t\\tstreamOut1.close();\\n\\t}\\n}\\n",
4275 "The program reads the data from the bit stream of the array, displays them on the screen, and then writes it to another bitmap array and displays the array to the screen.\\n\\nOutput:\\n\\n7\\n2\\n34\\n123\\n7\\n2\\n34\\n123\\n",
4276 "7\\n2\\n34\\n123\\n7\\n2\\n34\\n123\\n",
4277 "1",
4278 "2",
4279 "79"
4280 ]
4281 },
4282 {
4283 "-name": "question289",
4284 "item": [
4285 "289",
4286 "58",
4287 "import java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream streamOut1 = new FileOutputStream(file1);\\n\\t\\tFileInputStream streamIn1 = new FileInputStream(file1);\\n\\t\\tint c;\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tc = (int) (Math.random() * 10 + 1);\\n\\t\\t\\tstreamOut1.write(Ñ);\\n\\t\\t}\\n\\t\\tint result = streamIn1.read();\\n\\t\\twhile (result != -1) {\\n\\t\\t\\tSystem.out.print(result + \" \");\\n\\t\\t\\tresult = streamIn1.read();\\n\\t\\t}\\n\\t\\tstreamOut1.close();\\n\\t\\tstreamIn1.close();\\n\\t}\\n}\\n",
4288 "The program writes a random bit data in the file and then displays the data from the file on the screen.\\n\\nOutput:\\n\\n7 6 9 8 2 1 3 8 9 3 \\n",
4289 "7 6 9 8 2 1 3 8 9 3 \\n",
4290 "1",
4291 "3",
4292 "55"
4293 ]
4294 },
4295 {
4296 "-name": "question290",
4297 "item": [
4298 "290",
4299 "58",
4300 "import java.io.ByteArrayInputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tbyte btIn[] = { 1, 1, 41, 74, 3, 23, 4, 5 };\\n\\n\\t\\tByteArrayInputStream streamIn1 = new ByteArrayInputStream(btIn);\\n\\t\\tint a = streamIn1.read();\\n\\t\\twhile (a != -1) {\\n\\t\\t\\tSystem.out.println(a);\\n\\t\\t\\ta = streamIn1.read();\\n\\t\\t}\\n\\t\\tstreamIn1.close();\\n\\t}\\n}\\n",
4301 "The program outputs the bit data from the array to the stream, and then displays the data from the stream on the screen.\\n\\nOutput:\\n\\n1\\n1\\n41\\n74\\n3\\n23\\n4\\n5\\n",
4302 "1\\n1\\n41\\n74\\n3\\n23\\n4\\n5\\n",
4303 "1",
4304 "2",
4305 "66"
4306 ]
4307 },
4308 {
4309 "-name": "question291",
4310 "item": [
4311 "291",
4312 "59",
4313 "import java.io.DataInputStream;\\nimport java.io.DataOutputStream;\\nimport java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream outputSream1 = new FileOutputStream(file1);\\n\\t\\tDataOutputStream dataOutputSream1 = new DataOutputStream(outputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tdouble d = Math.random() * 10;\\n\\t\\t\\tdataOutputSream1.writeDouble(d);\\n\\t\\t}\\n\\t\\tFileInputStream inputSream1 = new FileInputStream(file1);\\n\\t\\tDataInputStream dataInputSream1 = new DataInputStream(inputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tSystem.out.println(dataInputSream1.readDouble());\\n\\t\\t}\\n\\t\\tdataOutputSream1.close();\\n\\t\\tdataInputSream1.close();\\n\\t}\\n}\\n",
4314 "The program converts double data into bit data, and then writes them to a file. Then the program reads the bit data from the file and converts them into double data. Then the program displays the data.\\n\\nPossible output:\\n\\n4.894792029807217\\n9.53882233381233\\n5.380071927363817\\n5.559953487762945\\n4.543136925399399\\n5.537525183949544\\n8.528685843149029\\n7.783064132682314\\n5.720797772301346\\n6.1441608864196215\\n",
4315 "4.894792029807217\\n9.53882233381233\\n5.380071927363817\\n5.559953487762945\\n4.543136925399399\\n5.537525183949544\\n8.528685843149029\\n7.783064132682314\\n5.720797772301346\\n6.1441608864196215\\n",
4316 "1",
4317 "3",
4318 "96"
4319 ]
4320 },
4321 {
4322 "-name": "question292",
4323 "item": [
4324 "292",
4325 "59",
4326 "import java.io.DataInputStream;\\nimport java.io.DataOutputStream;\\nimport java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream outputSream1 = new FileOutputStream(file1);\\n\\t\\tDataOutputStream dataOutputSream1 = new DataOutputStream(outputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tboolean b = i % 2 == 0 ? false : true;\\n\\t\\t\\tdataOutputSream1.writeBoolean(b);\\n\\t\\t}\\n\\t\\tFileInputStream inputSream1 = new FileInputStream(file1);\\n\\t\\tDataInputStream dataInputSream1 = new DataInputStream(inputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tSystem.out.println(dataInputSream1.readBoolean());\\n\\t\\t}\\n\\t\\tdataOutputSream1.close();\\n\\t\\tdataInputSream1.close();\\n\\t}\\n}\\n",
4327 "The program converts boolean data into bit data, and then writes them to a file. Then the program reads the bit data from the file and converts them into boolean data. Then the program displays the data.\\n\\nOutput:\\n\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\n",
4328 "false\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\nfalse\\ntrue\\n",
4329 "1",
4330 "3",
4331 "96"
4332 ]
4333 },
4334 {
4335 "-name": "question293",
4336 "item": [
4337 "293",
4338 "59",
4339 "import java.io.DataInputStream;\\nimport java.io.DataOutputStream;\\nimport java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tFile file1 = new File(\"file1.txt\");\\n\\t\\tFileOutputStream outputSream1 = new FileOutputStream(file1);\\n\\t\\tDataOutputStream dataOutputSream1 = new DataOutputStream(outputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tString s = (i + 1) + \" number \";\\n\\t\\t\\tdataOutputSream1.writeChars(s);\\n\\t\\t}\\n\\n\\t\\tFileInputStream inputSream1 = new FileInputStream(file1);\\n\\t\\tDataInputStream dataInputSream1 = new DataInputStream(inputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tfor (int j = 0; j < 10; j++) {\\n\\t\\t\\t\\tSystem.out.print(dataInputSream1.readChar());\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println(\"\");\\n\\t\\t}\\n\\t\\tdataOutputSream1.close();\\n\\t\\tdataInputSream1.close();\\n\\t}\\n}\\n",
4340 "The program converts char data into bit data, and then writes them to a file. Then the program reads the bit data from the file and converts them into char data. Then the program displays the data.\\n\\nOutput:\\n\\n1 number\\n2 number\\n3 number\\n4 number\\n5 number\\n6 number\\n7 number\\n8 number\\n9 number\\n10 number\\n",
4341 "1 number\\n2 number\\n3 number\\n4 number\\n5 number\\n6 number\\n7 number\\n8 number\\n9 number\\n10 number\\n",
4342 "1",
4343 "3",
4344 "96"
4345 ]
4346 },
4347 {
4348 "-name": "question294",
4349 "item": [
4350 "294",
4351 "59",
4352 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tString f = \"file1.txt\";\\n\\t\\tFileOutputStream outputSream1 = new FileOutputStream(f);\\n\\t\\tBufferedOutputStream bOPS = new BufferedOutputStream(outputSream1);\\n\\t\\tfor (int i = 0; i < 10; i++) {\\n\\t\\t\\tbOPS.write(i);\\n\\t\\t}\\n\\t\\tbOPS.flush();\\n\\n\\t\\tFileInputStream inputSream1 = new FileInputStream(f);\\n\\t\\tBufferedInputStream bIPS = new BufferedInputStream(inputSream1);\\n\\t\\tint result = bIPS.read();\\n\\t\\twhile (result != -1) {\\n\\t\\t\\tSystem.out.print(result + \" \");\\n\\t\\t\\tresult = bIPS.read();\\n\\t\\t}\\n\\t\\tbOPS.close();\\n\\t\\tbIPS.close();\\n\\t}\\n}\\n",
4353 "The program buffers bit data and then writes them to a file. Then read the bit data from the file into the buffer and outputs the data to the screen.\\n\\nOutput:\\n\\n0 1 2 3 4 5 6 7 8 9\\n",
4354 "0 1 2 3 4 5 6 7 8 9\\n",
4355 "1",
4356 "3",
4357 "83"
4358 ]
4359 },
4360 {
4361 "-name": "question295",
4362 "item": [
4363 "295",
4364 "59",
4365 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.InputStream;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tString fileName = \"file1.txt\";\\n\\n\\t\\tFileOutputStream outStream1 = new FileOutputStream(fileName);\\n\\t\\tBufferedOutputStream bufferedoutStream = new BufferedOutputStream(\\n\\t\\t\\t\\toutStream1);\\n\\t\\tlong timeStart = System.currentTimeMillis();\\n\\n\\t\\tfor (int i = 0; i < 1000000; i++) {\\n\\t\\t\\tbufferedoutStream.write(i);\\n\\t\\t}\\n\\t\\tbufferedoutStream.flush();\\n\\t\\tlong time = System.currentTimeMillis() - timeStart;\\n\\t\\tSystem.out.println(\"Recording time of BufferedOutputStream is \" + time\\n\\t\\t\\t\\t+ \" millisec\");\\n\\t\\tbufferedoutStream.close();\\n\\n\\t\\tInputStream inStream = new FileInputStream(fileName);\\n\\t\\ttimeStart = System.currentTimeMillis();\\n\\t\\twhile (inStream.read() != -1) {\\n\\t\\t}\\n\\t\\ttime = System.currentTimeMillis() - timeStart;\\n\\t\\tSystem.out.println(\"Reading time of FileInputStream is \" + time\\n\\t\\t\\t\\t+ \" millisec\");\\n\\t\\tinStream.close();\\n\\n\\t\\tFileInputStream inStream2 = new FileInputStream(fileName);\\n\\t\\tBufferedInputStream bufferedinStream = new BufferedInputStream(\\n\\t\\t\\t\\tinStream2);\\n\\t\\ttimeStart = System.currentTimeMillis();\\n\\t\\tint result = bufferedinStream.read();\\n\\t\\twhile (result != -1) {\\n\\t\\t\\tresult = bufferedinStream.read();\\n\\t\\t}\\n\\t\\tbufferedoutStream.flush();\\n\\t\\ttime = System.currentTimeMillis() - timeStart;\\n\\t\\tSystem.out.println(\"Reading time of BufferedInputStream is \" + time\\n\\t\\t\\t\\t+ \" millisec\");\\n\\t\\tbufferedinStream.close();\\n\\t}\\n}\\n",
4366 "The program shows how much faster the writing and reading of buffered data than bit.\\n\\nPossible output:\\n\\nRecording time of BufferedOutputStream is 31 millisec\\nReading time of FileInputStream is 4158 millisec\\nReading time of BufferedInputStream is 9 millisec\\n",
4367 "Recording time of BufferedOutputStream is 31 millisec\\nReading time of FileInputStream is 4158 millisec\\nReading time of BufferedInputStream is 9 millisec\\n",
4368 "1",
4369 "3",
4370 "80"
4371 ]
4372 },
4373 {
4374 "-name": "question296",
4375 "item": [
4376 "296",
4377 "60",
4378 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.ObjectInputStream;\\nimport java.io.ObjectOutputStream;\\n\\npublic class Game {\\n\\tpublic static void main(String[] args) throws IOException,\\n\\t\\t\\tClassNotFoundException {\\n\\n\\t\\tElf elf1 = new Elf(\"Elain\", 80, 70, new String[] { \"Bow\", \"Sword\" });\\n\\t\\tOrc orc1 = new Orc(100, new String[] { \"Sling \", \"Club\" });\\n\\t\\tString file = \"file.txt\";\\n\\t\\tFileOutputStream outPutStream = new FileOutputStream(file);\\n\\t\\tObjectOutputStream objectOutputS = new ObjectOutputStream(outPutStream);\\n\\t\\tobjectOutputS.writeObject(elf1);\\n\\t\\telf1 = null;\\n\\t\\tobjectOutputS.writeObject(orc1);\\n\\t\\torc1 = null;\\n\\t\\tobjectOutputS.close();\\n\\t\\tFileInputStream inPutStream = new FileInputStream(file);\\n\\t\\tObjectInputStream objectInputS = new ObjectInputStream(inPutStream);\\n\\t\\tElf elf1New = (Elf) objectInputS.readObject();\\n\\t\\tOrc orc1New = (Orc) objectInputS.readObject();\\n\\t\\tobjectInputS.close();\\n\\t\\tSystem.out.println(\"Elf \" + elf1New.name + \" strength \" + elf1New.helth);\\n\\t\\tSystem.out.println(\"Orc, strength \" + orc1New.helth);\\n\\t}\\n}\\n",
4379 "import java.io.Serializable;\\n\\npublic class Elf implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint helth;\\n\\tint magic;\\n\\tString weapons[];\\n\\n\\tElf(String name, int helth, int magic, String weapons[]) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.weapons = weapons;\\n\\t}\\n}\\n",
4380 "import java.io.Serializable;\\n\\npublic class Orc implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tint helth;\\n\\tString weapons[];\\n\\n\\tOrc(int helth, String weapons[]) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.weapons = weapons;\\n\\t}\\n}\\n",
4381 "The program writes objects to a file. Then the program reads objects from the file and displays them.\\n\\nOutput:\\n\\nElf Elain strength 80\\nOrc, strength 100\\n",
4382 "Elf Elain strength 80\\nOrc, strength 100\\n",
4383 "1",
4384 "3",
4385 "133"
4386 ]
4387 },
4388 {
4389 "-name": "question297",
4390 "item": [
4391 "297",
4392 "60",
4393 "import java.io.Serializable;\\n\\npublic class Elf implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint helth;\\n\\tint magic;\\n\\tString weapons[];\\n\\n\\tElf(String name, int helth, int magic, String weapons[]) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.magic = magic;\\n\\t\\tthis.weapons = weapons;\\n\\t}\\n}\\n",
4394 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.ObjectInputStream;\\nimport java.io.ObjectOutputStream;\\n\\npublic class Game {\\n\\tpublic static void main(String[] args) throws IOException,\\n\\t\\t\\tClassNotFoundException {\\n\\n\\t\\tElf elf1 = new Elf(\"Elain\", 80, 70, new String[] { \"Bow\", \"Sword\" });\\n\\t\\tOrc orc1 = new Orc(100, new String[] { \"Sling \", \"Club\" });\\n\\t\\tString file = \"file.txt\";\\n\\t\\tFileOutputStream outPutStream = new FileOutputStream(file);\\n\\t\\tObjectOutputStream objectOutputS = new ObjectOutputStream(outPutStream);\\n\\t\\tobjectOutputS.writeObject(elf1);\\n\\t\\telf1 = null;\\n\\t\\tobjectOutputS.writeObject(orc1);\\n\\t\\torc1 = null;\\n\\t\\tobjectOutputS.close();\\n\\t\\tFileInputStream inPutStream = new FileInputStream(file);\\n\\t\\tObjectInputStream objectInputS = new ObjectInputStream(inPutStream);\\n\\t\\tElf elf1New = (Elf) objectInputS.readObject();\\n\\t\\tOrc orc1New = (Orc) objectInputS.readObject();\\n\\t\\tobjectInputS.close();\\n\\t\\tSystem.out.println(\"Elf \" + elf1New.name + \" strength \" + elf1New.helth);\\n\\t\\tSystem.out.println(\"Orc, strength \" + orc1New.helth);\\n\\t}\\n}\\n",
4395 "import java.io.Serializable;\\n\\npublic class Orc implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tint helth;\\n\\tString weapons[];\\n\\n\\tOrc(int helth, String weapons[]) {\\n\\t\\tthis.helth = helth;\\n\\t\\tthis.weapons = weapons;\\n\\t}\\n}\\n",
4396 "The program writes objects to a file. Then the program reads objects from the file and displays objects.\\n\\nOutput:\\n\\nElf Elain strength 80\\nOrc, strength 100\\n",
4397 "Elf Elain strength 80\\nOrc, strength 100\\n",
4398 "1",
4399 "3",
4400 "1"
4401 ]
4402 },
4403 {
4404 "-name": "question298",
4405 "item": [
4406 "298",
4407 "60",
4408 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.ObjectInputStream;\\nimport java.io.ObjectOutputStream;\\n\\npublic class Race {\\n\\n\\tpublic static void main(String[] args) throws IOException,\\n\\t\\t\\tClassNotFoundException {\\n\\t\\tMan driver1 = new Man(\"Alex\", 80);\\n\\t\\tCars redBulls = new Cars(\"RedBulls\", 370, 150, driver1);\\n\\n\\t\\tFile file = new File(\"file1.txt\");\\n\\t\\tFileOutputStream outputStream = new FileOutputStream(file);\\n\\t\\tBufferedOutputStream bufOutputS = new BufferedOutputStream(outputStream);\\n\\t\\tObjectOutputStream obOutputS = new ObjectOutputStream(bufOutputS);\\n\\t\\tobOutputS.writeObject(redBulls);\\n\\t\\tobOutputS.close();\\n\\n\\t\\tredBulls = null;\\n\\n\\t\\tFileInputStream inputStream = new FileInputStream(file);\\n\\t\\tBufferedInputStream bufInputS = new BufferedInputStream(inputStream);\\n\\t\\tObjectInputStream obInputS = new ObjectInputStream(bufInputS);\\n\\t\\tCars redBullsNew = (Cars) obInputS.readObject();\\n\\t\\tobInputS.close();\\n\\n\\t\\tSystem.out.print(\"Driver \" + redBullsNew.name + \" - \");\\n\\t\\tSystem.out.print(redBullsNew.driver.name + \". The experience - \");\\n\\t\\tSystem.out.println(redBullsNew.driver.experience + \".\");\\n\\t}\\n}\\n",
4409 "import java.io.Serializable;\\n\\npublic class Cars implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint speed;\\n\\tint fuel;\\n\\tMan driver;\\n\\n\\tCars(String name, int speed, int fuel, Man driver) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.fuel = fuel;\\n\\t\\tthis.driver = driver;\\n\\t}\\n}\\n",
4410 "import java.io.Serializable;\\n\\npublic class Man implements Serializable {\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint experience;\\n\\n\\tMan(String name, int experience) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.experience = experience;\\n\\t}\\n}\\n",
4411 "The program buffers the object and writes it to a file. Then the program reads the object from the file and displays the object.\\n\\nOutput:\\n\\nDriver Red Bulls - Alex. The experience - 80.\\n",
4412 "Driver Red Bulls - Alex. The experience - 80.\\n",
4413 "1",
4414 "3",
4415 "125"
4416 ]
4417 },
4418 {
4419 "-name": "question299",
4420 "item": [
4421 "299",
4422 "60",
4423 "import java.io.Serializable;\\n\\npublic class Cars implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint speed;\\n\\tint fuel;\\n\\tMan driver;\\n\\n\\tCars(String name, int speed, int fuel, Man driver) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.speed = speed;\\n\\t\\tthis.fuel = fuel;\\n\\t\\tthis.driver = driver;\\n\\t}\\n}\\n",
4424 "import java.io.BufferedInputStream;\\nimport java.io.BufferedOutputStream;\\nimport java.io.File;\\nimport java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.ObjectInputStream;\\nimport java.io.ObjectOutputStream;\\n\\npublic class Race {\\n\\n\\tpublic static void main(String[] args) throws IOException,\\n\\t\\t\\tClassNotFoundException {\\n\\t\\tMan driver1 = new Man(\"Alex\", 80);\\n\\t\\tCars redBulls = new Cars(\"RedBulls\", 370, 150, driver1);\\n\\n\\t\\tFile file = new File(\"file1.txt\");\\n\\t\\tFileOutputStream outputStream = new FileOutputStream(file);\\n\\t\\tBufferedOutputStream bufOutputS = new BufferedOutputStream(outputStream);\\n\\t\\tObjectOutputStream obOutputS = new ObjectOutputStream(bufOutputS);\\n\\t\\tobOutputS.writeObject(redBulls);\\n\\t\\tobOutputS.close();\\n\\n\\t\\tredBulls = null;\\n\\n\\t\\tFileInputStream inputStream = new FileInputStream(file);\\n\\t\\tBufferedInputStream bufInputS = new BufferedInputStream(inputStream);\\n\\t\\tObjectInputStream obInputS = new ObjectInputStream(bufInputS);\\n\\t\\tCars redBullsNew = (Cars) obInputS.readObject();\\n\\t\\tobInputS.close();\\n\\n\\t\\tSystem.out.print(\"Driver \" + redBullsNew.name + \" - \");\\n\\t\\tSystem.out.print(redBullsNew.driver.name + \". The experience - \");\\n\\t\\tSystem.out.println(redBullsNew.driver.experience + \".\");\\n\\t}\\n}\\n",
4425 "import java.io.Serializable;\\n\\npublic class Man implements Serializable {\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint experience;\\n\\n\\tMan(String name, int experience) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.experience = experience;\\n\\t}\\n}\\n",
4426 "The program buffers the object and writes it to a file. Then the program reads the object from the file and displays the object.\\n\\nOutput:\\n\\nDriver Red Bulls - Alex. The experience - 80.\\n",
4427 "Driver Red Bulls - Alex. The experience - 80.\\n",
4428 "1",
4429 "3",
4430 "1"
4431 ]
4432 },
4433 {
4434 "-name": "question300",
4435 "item": [
4436 "300",
4437 "60",
4438 "import java.io.FileInputStream;\\nimport java.io.FileOutputStream;\\nimport java.io.IOException;\\nimport java.io.ObjectInputStream;\\nimport java.io.ObjectOutputStream;\\n\\npublic class Act {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tUnit unit1 = new Unit(\"Tank\", 80);\\n\\t\\tUnit unit2 = new Unit(\"Fighter\", 2500);\\n\\t\\tUnit unit3 = new Unit(\"Attack plane\", 900);\\n\\n\\t\\tString f = \"file.txt\";\\n\\t\\tFileOutputStream oPS;\\n\\t\\tObjectOutputStream obStream;\\n\\t\\ttry {\\n\\t\\t\\toPS = new FileOutputStream(f);\\n\\t\\t\\tobStream = new ObjectOutputStream(oPS);\\n\\t\\t\\tobStream.writeObject(unit1);\\n\\t\\t\\tobStream.writeObject(unit2);\\n\\t\\t\\tobStream.writeObject(unit3);\\n\\t\\t\\tobStream.close();\\n\\t\\t} catch (IOException e1) {\\n\\t\\t\\te1.printStackTrace();\\n\\t\\t}\\n\\t\\tunit1 = null;\\n\\t\\tunit2 = null;\\n\\t\\tunit3 = null;\\n\\n\\t\\tFileInputStream oInPS;\\n\\t\\tObjectInputStream obInStream = null;\\n\\t\\tUnit unit1new = null;\\n\\t\\tUnit unit2new = null;\\n\\t\\tUnit unit3new = null;\\n\\t\\ttry {\\n\\t\\t\\toInPS = new FileInputStream(f);\\n\\t\\t\\tobInStream = new ObjectInputStream(oInPS);\\n\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tunit1new = (Unit) obInStream.readObject();\\n\\t\\t\\t\\tunit2new = (Unit) obInStream.readObject();\\n\\t\\t\\t\\tunit3new = (Unit) obInStream.readObject();\\n\\t\\t\\t\\tobInStream.close();\\n\\t\\t\\t} catch (ClassNotFoundException e) {\\n\\t\\t\\t\\te.printStackTrace();\\n\\t\\t\\t}\\n\\t\\t} catch (IOException e1) {\\n\\t\\t\\te1.printStackTrace();\\n\\t\\t}\\n\\t\\tSystem.out.println(unit1new.type + \" \" + unit1new.speed);\\n\\t\\tSystem.out.println(unit2new.type + \" \" + unit2new.speed);\\n\\t\\tSystem.out.println(unit3new.type + \" \" + unit3new.speed);\\n\\t\\t}\\n}\\n",
4439 "import java.io.Serializable;\\n\\npublic class Unit implements Serializable {\\n\\n\\tprivate static final long serialVersionUID = 1L;\\n\\n\\tString type;\\n\\tint speed;\\n\\n\\tUnit(String type, int speed) {\\n\\t\\tthis.type = type;\\n\\t\\tthis.speed = speed;\\n\\t}\\n}\\n",
4440 "import java.io.Serializable;\\n\\npublic class Man implements Serializable {\\n\\tprivate static final long serialVersionUID = 1L;\\n\\tString name;\\n\\tint experience;\\n\\n\\tMan(String name, int experience) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.experience = experience;\\n\\t}\\n}\\n",
4441 "The program writes objects to a file. Then the program reads objects from the file and displays objects.\\n\\nOutput:\\n\\nTank 80\\nFighter 2500\\nAttack plane 900\\n",
4442 "Tank 80\\nFighter 2500\\nAttack plane 900\\n",
4443 "1",
4444 "3",
4445 "114"
4446 ]
4447 },
4448 {
4449 "-name": "question301",
4450 "item": [
4451 "301",
4452 "61",
4453 "import java.io.File;\\nimport java.io.FileReader;\\nimport java.io.FileWriter;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tFile file = new File(\"file.txt\");\\n\\t\\tFileWriter fWriter = new FileWriter(file);\\n\\t\\tfWriter.write(\"Hello, old friend\");\\n\\t\\tfWriter.close();\\n\\n\\t\\tFileReader fReader = new FileReader(file);\\n\\t\\tint g = fReader.read();\\n\\t\\twhile (g != -1) {\\n\\t\\t\\t System.out.print((char) g);\\n\\t\\t\\tg = fReader.read();\\n\\t\\t}\\n\\t\\tfReader.close();\\n\\t}\\n}\\n",
4454 "The program writes the text to a file. Then the program reads the text from the file and displays the text.\\n\\nOutput:\\n\\nHello, old friend\\n",
4455 "Hello, old friend\\n",
4456 "1",
4457 "2",
4458 "67"
4459 ]
4460 },
4461 {
4462 "-name": "question302",
4463 "item": [
4464 "302",
4465 "61",
4466 "import java.io.BufferedReader;\\nimport java.io.BufferedWriter;\\nimport java.io.File;\\nimport java.io.FileReader;\\nimport java.io.FileWriter;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\t\\tFile file = new File(\"file.txt\");\\n\\t\\tFileWriter fWriter = new FileWriter(file);\\n\\t\\tBufferedWriter bufferedWriter = new BufferedWriter(fWriter);\\n\\t\\tbufferedWriter.write(\"Hello, old friend\");\\n\\t\\tbufferedWriter.close();\\n\\n\\t\\tFileReader fReader = new FileReader(file);\\n\\t\\tBufferedReader bufferedReader = new BufferedReader(fReader);\\n\\t\\tString s = bufferedReader.readLine();\\n\\t\\twhile (s != null) {\\n\\t\\t\\tSystem.out.print(s);\\n\\t\\t\\ts = bufferedReader.readLine();\\n\\t\\t}\\n\\t\\tbufferedReader.close();\\n\\t}\\n}\\n",
4467 "The program buffers the text and writes it to a file. Then the program reads the text from the file and displays the text.\\n\\nOutput:\\n\\nHello, old friend\\n",
4468 "Hello, old friend\\n",
4469 "1",
4470 "2",
4471 "83"
4472 ]
4473 },
4474 {
4475 "-name": "question303",
4476 "item": [
4477 "303",
4478 "61",
4479 "import java.io.CharArrayReader;\\nimport java.io.CharArrayWriter;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) throws IOException {\\n\\n\\t\\tchar mas[] = { 'H', 'e', 'l', 'l', 'o', ' ', 'W','o', 'r', 'l', 'd' };\\n\\t\\tchar masNew[] = new char[mas.length];\\n\\t\\tCharArrayWriter arrayWriter = new CharArrayWriter();\\n\\t\\tCharArrayReader charArrayReader = new CharArrayReader(mas);\\n\\n\\t\\tint g = charArrayReader.read();\\n\\t\\twhile (g != -1) {\\n\\t\\t\\tSystem.out.print((char) g);\\n\\t\\t\\tarrayWriter.write(g);\\n\\t\\t\\tg = charArrayReader.read();\\n\\t\\t}\\n\\t\\tmasNew = arrayWriter.toCharArray();\\n\\t\\tcharArrayReader.close();\\n\\t\\tarrayWriter.close();\\n\\t\\tSystem.out.println(\"\");\\n\\n\\t\\tfor (int a = 0; a < mas.length; a++) {\\n\\t\\t\\tSystem.out.print(masNew[a]);\\n\\t\\t}\\n\\t}\\n}\\n",
4480 "The program fill the stream from the array, displays the stream. Then the program writes stream to another array, and displays this array.\\n\\nOutput:\\n\\nHello World\\nHello World\\n",
4481 "Hello World\\nHello World\\n",
4482 "1",
4483 "3",
4484 "95"
4485 ]
4486 },
4487 {
4488 "-name": "question304",
4489 "item": [
4490 "304",
4491 "61",
4492 "import java.io.BufferedReader;\\nimport java.io.BufferedWriter;\\nimport java.io.File;\\nimport java.io.FileReader;\\nimport java.io.FileWriter;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tFile file = new File(\"file.txt\");\\n\\n\\t\\ttry {\\n\\t\\t\\tFileWriter fWriter = new FileWriter(file);\\n\\n\\t\\t\\tBufferedWriter bufferedWriter = new BufferedWriter(fWriter);\\n\\t\\t\\tbufferedWriter.write(\"Hello, old friend\");\\n\\t\\t\\tbufferedWriter.close();\\n\\n\\t\\t\\tFileReader fReader = new FileReader(file);\\n\\t\\t\\tBufferedReader bufferedReader = new BufferedReader(fReader);\\n\\t\\t\\tString s = bufferedReader.readLine();\\n\\t\\t\\twhile (s != null) {\\n\\t\\t\\t\\tSystem.out.print(s);\\n\\t\\t\\t\\ts = bufferedReader.readLine();\\n\\t\\t\\t}\\n\\t\\t\\tbufferedReader.close();\\n\\t\\t} catch (IOException e) {\\n\\t\\t\\te.printStackTrace();\\n\\t\\t}\\n\\t}\\n}\\n",
4493 "The program buffers the text and writes it to a file. Then the program reads the text from the file and displays the text.\\n\\nOutput:\\n\\nHello, old friend\\n",
4494 "Hello, old friend\\n",
4495 "1",
4496 "3",
4497 "82"
4498 ]
4499 },
4500 {
4501 "-name": "question305",
4502 "item": [
4503 "305",
4504 "61",
4505 "import java.io.BufferedReader;\\nimport java.io.BufferedWriter;\\nimport java.io.FileReader;\\nimport java.io.FileWriter;\\nimport java.io.IOException;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tString f = \"file.txt\";\\n\\n\\t\\ttry {\\n\\t\\t\\tBufferedWriter bufferedWriter = new BufferedWriter(\\n\\t\\t\\t\\t\\tnew FileWriter(f));\\n\\t\\t\\tbufferedWriter.write(\"Some text\");\\n\\t\\t\\tbufferedWriter.close();\\n\\t\\t\\tBufferedReader bufferedReader = new BufferedReader(\\n\\t\\t\\t\\t\\tnew FileReader(f));\\n\\t\\t\\tString s = bufferedReader.readLine();\\n\\t\\t\\twhile (s != null) {\\n\\t\\t\\t\\tSystem.out.print(s);\\n\\t\\t\\t\\ts = bufferedReader.readLine();\\n\\t\\t\\t}\\n\\t\\t\\tbufferedReader.close();\\n\\t\\t} catch (IOException e) {\\n\\t\\t\\te.printStackTrace();\\n\\t\\t}\\n\\t}\\n}\\n",
4506 "The program buffers the text and writes it to a file. Then the program reads the text from the file and displays the text.\\n\\nOutput:\\n\\nSome text\\n",
4507 "Some text\\n",
4508 "1",
4509 "3",
4510 "70"
4511 ]
4512 },
4513 {
4514 "-name": "question306",
4515 "item": [
4516 "306",
4517 "62",
4518 "import java.util.ArrayList;\\n\\npublic class Game {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eliot\", 30);\\n\\t\\tElf elf2 = new Elf(\"Elot\", 100);\\n\\n\\t\\tArrayList<Elf> battle = new ArrayList<Elf>();\\n\\t\\tbattle.add(elf1);\\n\\t\\tbattle.add(elf2);\\n\\t\\tfor (Elf unite : battle) {\\n\\t\\t\\tunite.fight();\\n\\t\\t}\\n\\t\\tElf elf3 = new Elf(\"Linton\", 110);\\n\\t\\tbattle.add(elf3);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Elf unite : battle) {\\n\\t\\t\\tunite.fight();\\n\\t\\t}\\n\\t\\tbattle.remove(elf1);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Elf unite : battle) {\\n\\t\\t\\tunite.fight();\\n\\t\\t}\\n\\t}\\n}\\n",
4519 "public class Elf {\\n\\tString name;\\n\\tint str;\\n\\n\\tElf(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tstr = strength;\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(name + \" has strength \" + str + \" fights with trolls.\");\\n\\t\\tstr = str - 20;\\n\\t\\tif (str <= 0) {\\n\\t\\t\\tSystem.out.println(name + \" died.\");\\n\\t\\t}\\n\\t}\\n}\\n",
4520 "This is an example of using methods add and remove in the ArrayList.\\n\\nOutput:\\n\\nEliot has strength 30 fights with trolls.\\nElot has strength 100 fights with trolls.\\n\\nEliot has strength 10 fights with trolls.\\nEliot died\\nElot has strength 80 fights with trolls.\\nLinton has strength 110 fights with trolls.\\n\\nElot has strength 60 fights with trolls.\\nLinton has strength 90 fights with trolls.\\n",
4521 "Eliot has strength 30 fights with trolls.\\nElot has strength 100 fights with trolls.\\n\\nEliot has strength 10 fights with trolls.\\nEliot died\\nElot has strength 80 fights with trolls.\\nLinton has strength 110 fights with trolls.\\n\\nElot has strength 60 fights with trolls.\\nLinton has strength 90 fights with trolls.",
4522 "1",
4523 "2",
4524 "57"
4525 ]
4526 },
4527 {
4528 "-name": "question307",
4529 "item": [
4530 "307",
4531 "62",
4532 "import java.util.ArrayList;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 100000);\\n\\t\\tCar car2 = new Car(\"KIA\", 80000);\\n\\n\\t\\tArrayList<Car> garage = new ArrayList<Car>();\\n\\t\\tgarage.add(car1);\\n\\t\\tgarage.add(car2);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tSystem.out.println(garage.get(0).name);\\n\\t\\tSystem.out.println(garage.get(1).name);\\n\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tCar car3 = new Car(\"Reno\", 90000);\\n\\t\\tgarage.remove(1);\\n\\t\\tgarage.add(0, car3);\\n\\t\\tSystem.out.println(garage.get(0).name);\\n\\t\\tSystem.out.println(garage.get(1).name);\\n\\n\\t\\tgarage.clear();\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t}\\n}\\n",
4533 "public class Car {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tpublic void bayCar() {\\n\\t\\tSystem.out.println( name + \", price \" + cost);\\n\\t}\\n}\\n",
4534 "This is an example of using methods remove (int index), add (int index, E object), get (int index) and clear in the collection ArrayList.\\n\\nOutput:\\n\\nToyota, price 100000\\nKIA, price 80000\\n\\nToyota\\nKIA\\n\\nReno\\nToyota\\n",
4535 "Toyota, price 100000\\nKIA, price 80000\\n\\nToyota\\nKIA\\n\\nReno\\nToyota\\n",
4536 "1",
4537 "3",
4538 "56"
4539 ]
4540 },
4541 {
4542 "-name": "question308",
4543 "item": [
4544 "308",
4545 "62",
4546 "import java.util.ArrayList;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 100000);\\n\\t\\tCar car2 = new Car(\"KIA\", 80000);\\n\\t\\tCar car3 = new Car(\"Reno\", 90000);\\n\\n\\t\\tArrayList<Car> garage = new ArrayList<Car>();\\n\\t\\tgarage.add(car1);\\n\\t\\tgarage.add(car2);\\n\\t\\tgarage.add(car3);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tArrayList<Car> garage2 = new ArrayList<Car>();\\n\\t\\tgarage2.add(car3);\\n\\t\\tgarage2.addAll(garage);\\n\\n\\t\\tfor (Car cars : garage2) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tCar car4 = new Car(Ford, 110000);\\n\\t\\tSystem.out.println(car4.name + \". Do you have such car? \"\\n\\t\\t\\t\\t+ garage2.contains(car4));\\n\\t\\tSystem.out.println(car3.name + \". Do you have such car? \"\\n\\t\\t\\t\\t+ garage2.contains(car3));\\n\\t}\\n}\\n",
4547 "public class Car {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tpublic void bayCar() {\\n\\t\\tSystem.out.println(\"We have \" + name + \", it costs \" + cost);\\n\\t}\\n}\\n",
4548 "This is an example of using methods addAll(Collection<? extends E>) and contains(object) in the ArrayList.\\n\\nOutput:\\n\\nWe have Toyota, it costs 100000\\nWe have KIA, it costs 80000\\nWe have Reno, it costs 90000\\n\\nWe have Reno, it costs 90000\\nWe have Toyota, it costs 100000\\nWe have KIA, it costs 80000\\nWe have Reno, it costs 90000\\n\\nFord. Do you have such car? false\\nReno. Do you have such car? true\\n",
4549 "We have Toyota, it costs 100000\\nWe have KIA, it costs 80000\\nWe have Reno, it costs 90000\\n\\nWe have Reno, it costs 90000\\nWe have Toyota, it costs 100000\\nWe have KIA, it costs 80000\\nWe have Reno, it costs 90000\\n\\nFord. Do you have such car? false\\nReno. Do you have such car? true\\n",
4550 "1",
4551 "2",
4552 "207"
4553 ]
4554 },
4555 {
4556 "-name": "question309",
4557 "item": [
4558 "309",
4559 "62",
4560 "import java.util.ArrayList;\\n\\npublic class Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tUnit(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tstr = strength;\\n\\t}\\n\\n\\tpublic void fight() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eliot\", 20);\\n\\t\\tElf elf2 = new Elf(\"Elot\", 100);\\n\\t\\tTroll troll1 = new Troll(\"Zizo\", 100);\\n\\t\\tTroll troll2 = new Troll(\"Kits\", 90);\\n\\n\\t\\tArrayList<Unit> battle = new ArrayList<Unit>();\\n\\t\\tbattle.add(elf1);\\n\\t\\tbattle.add(elf2);\\n\\t\\tbattle.add(troll1);\\n\\t\\tbattle.add(troll2);\\n\\t\\tfor (Unit unite : battle) {\\n\\t\\t\\tunite.fight();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tbattle.remove(elf1);\\n\\t\\tfor (Unit unite : battle) {\\n\\t\\t\\tunite.fight();\\n\\t\\t}\\n\\t}\\n}\\n",
4561 "public class Elf extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Elf(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t\\t+ \" fights with trolls.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died.\");\\n\\t\\t}\\n\\t}\\n}\\n",
4562 "public class Troll extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Troll(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t\\t+ \" fights with elves.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died.\");\\n\\t\\t}\\n\\t}\\n}\\n",
4563 "In the program trolls fight with elves, one elf died. All elves and trolls are in one ArrayList.\\n\\nOutput:\\n\\nEliot has strength 20 fights with trolls.\\nEliot died.\\nElot has strength 100 fights with trolls.\\nZizo has strength 100 fights with elves.\\nKits has strength 90 fights with elves.\\n\\nElot has strength 80 fights with trolls.\\nZizo has strength 80 fights with elves.\\nKits has strength 70 fights with elves.\\n",
4564 "Eliot has strength 20 fights with trolls.\\nEliot died.\\nElot has strength 100 fights with trolls.\\nZizo has strength 100 fights with elves.\\nKits has strength 90 fights with elves.\\n\\nElot has strength 80 fights with trolls.\\nZizo has strength 80 fights with elves.\\nKits has strength 70 fights with elves.\\n",
4565 "1",
4566 "2",
4567 "138"
4568 ]
4569 },
4570 {
4571 "-name": "question310",
4572 "item": [
4573 "310",
4574 "62",
4575 "import java.util.ArrayList;\\n\\npublic class Unit {\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eliot\", 30);\\n\\t\\tString song = \"La-la-la-la\";\\n\\t\\tTroll troll1 = new Troll(\"Zizo\", 100);\\n\\t\\tint f = 22;\\n\\n\\t\\tArrayList<Object> battle = new ArrayList<Object>();\\n\\t\\tbattle.add(elf1);\\n\\t\\tbattle.add(song);\\n\\t\\tbattle.add(troll1);\\n\\t\\tbattle.add(f);\\n\\n\\t\\t((Elf) battle.get(0)).fight();\\n\\t\\tSystem.out.println(battle.get(1));\\n\\t\\t((Troll) battle.get(2)).fight();\\n\\t\\tSystem.out.println(battle.get(3));\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
4576 "public class Elf extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Elf(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t\\t+ \" fights with trolls.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died.\");\\n\\t\\t}\\n\\t}\\n}\\n",
4577 "public class Troll extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Troll(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t\\t+ \" fights with elves.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died.\");\\n\\t\\t}\\n\\t}\\n}\\n",
4578 "Troll fights with elf. For example. ArrayList contains elf, trol, int variable and string variable.\\n\\nOutput:\\n\\nEliot has strength 30 fights with trolls.\\nLa-la-la-la\\nZizo has strength 100 fights with elves.\\n22\\n",
4579 "Eliot has strength 30 fights with trolls.\\nLa-la-la-la\\nZizo has strength 100 fights with elves.\\n22\\n",
4580 "1",
4581 "2",
4582 "72"
4583 ]
4584 },
4585 {
4586 "-name": "question311",
4587 "item": [
4588 "311",
4589 "63",
4590 "import java.util.HashMap;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 1000000);\\n\\t\\tCar car2 = new Car(\"KIA\", 800000);\\n\\n\\t\\tHashMap<String, Car> garage = new HashMap<String, Car>();\\n\\t\\tgarage.put(\"Favorite car \", car1);\\n\\t\\tgarage.put(\"Economical car \", car2);\\n\\t\\tgarage.put(\"Silver machine \", car2);\\n\\n\\t\\tSystem.out.println(garage.entrySet());\\n\\t\\tSystem.out.println(garage.values());\\n\\t\\tSystem.out.println(garage.keySet());\\n\\t\\tSystem.out.println();\\n\\t\\tgarage.remove(\"Economical car \");\\n\\t\\tSystem.out.println(garage.entrySet());\\n\\t\\tSystem.out.println();\\n\\t\\tgarage.clear();\\n\\t\\tSystem.out.println(garage.entrySet());\\n\\t}\\n}\\n",
4591 "public class Car {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n",
4592 "An example of using the put method, the remove method, the entrySet method, the values method, the keySet method and the clear method. HashMap collection.\\n\\nOutput:\\n\\n[Silver machine =Car@15b7986, Economical car =Car@15b7986, Favorite car =Car@87816d]\\n[Car@15b7986, Car@15b7986, Car@87816d]\\n[Silver machine , Economical car , Favorite car ]\\n\\n[Silver machine =Car@15b7986, Favorite car =Car@87816d]\\n\\n[]\\n",
4593 "[Silver machine =Car@15b7986, Economical car =Car@15b7986, Favorite car =Car@87816d]\\n[Car@15b7986, Car@15b7986, Car@87816d]\\n[Silver machine , Economical car , Favorite car ]\\n\\n[Silver machine =Car@15b7986, Favorite car =Car@87816d]\\n\\n[]\\n",
4594 "1",
4595 "2",
4596 "114"
4597 ]
4598 },
4599 {
4600 "-name": "question312",
4601 "item": [
4602 "312",
4603 "63",
4604 "import java.util.HashMap;\\nimport java.util.Map.Entry;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 1000000);\\n\\t\\tCar car2 = new Car(\"KIA\", 800000);\\n\\n\\t\\tHashMap<String, Car> garage = new HashMap<String, Car>();\\n\\t\\tgarage.put(\"Favorite car \", car1);\\n\\t\\tgarage.put(\"Economical car \", car2);\\n\\t\\tgarage.put(\"Silver machine \", car2);\\n\\n\\t\\tSystem.out.println(garage.get(\"Favorite car \").name + \" \"\\n\\t\\t\\t+ garage.get(\"Favorite car \").cost + \\n\\t\\t\\t+ garage.get(\"Favorite car \").getClass());\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(garage.get(\"Economical car \").name + \" \"\\n\\t\\t\\t+ garage.get(\"Economical car \").cost + \" \"\\n\\t\\t\\t+ garage.get(\"Economical car \").getClass());\\n\\t\\tSystem.out.println();\\n\\t\\tfor (Entry<String, Car> entry : garage.entrySet()) {\\n\\t\\t\\tSystem.out.println(entry.getKey() + \" \" + entry.getValue().name);\\n\\t\\t}\\n\\t}\\n}\\n",
4605 "public class Car {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n",
4606 "An example of using the get method, the getClass method, the entrySet() and the object Entry<String, Object>. HashMap collection.\\n\\nOutput:\\n\\nToyota 1000000 class Car\\n\\nKIA 800000 class Car\\n\\nSilver machine KIA\\nEconomical car KIA\\nFavorite car Toyota\\n\\n",
4607 "Toyota 1000000 class Car\\n\\nKIA 800000 class Car\\n\\nSilver machine KIA\\nEconomical car KIA\\nFavorite car Toyota\\n",
4608 "1",
4609 "2",
4610 "125"
4611 ]
4612 },
4613 {
4614 "-name": "question313",
4615 "item": [
4616 "313",
4617 "63",
4618 "import java.util.HashMap;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 1000000);\\n\\t\\tCar car2 = new Car(\"KIA\", 800000);\\n\\n\\t\\tHashMap<String, Car> garage = new HashMap<String, Car>();\\n\\t\\tgarage.put(\"Favorite car \", car1);\\n\\t\\tgarage.put(\"Economical car \", car2);\\n\\t\\tgarage.put(\"Silver machine \", car2);\\n\\n\\t\\tSystem.out.println(garage.entrySet());\\n\\t\\tSystem.out.println();\\n\\t\\tSystem.out.println(\"Favorite car \"\\n\\t\\t\\t+ garage.containsKey(\"Favorite car \"));\\n\\t\\tSystem.out.println(car1.name + \" \" + garage.containsValue(car1));\\n\\t\\tSystem.out.println(garage.size());\\n\\t\\tSystem.out.println(garage.isEmpty());\\n\\t}\\n}\\n",
4619 "public class Car {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n",
4620 "An example of using the entryset method, the containsKey method, the containsValue method, the size method and the isEmpty method. HashMap collection.\\n\\nOutput:\\n\\n[Silver machine =Car@87816d, Economical car =Car@87816d, Favorite car =Car@422ede]\\n\\nFavorite car true\\nToyota true\\n3\\nfalse\\n",
4621 "[Silver machine =Car@87816d, Economical car =Car@87816d, Favorite car =Car@422ede]\\n\\nFavorite car true\\nToyota true\\n3\\nfalse\\n",
4622 "1",
4623 "1",
4624 "115"
4625 ]
4626 },
4627 {
4628 "-name": "question314",
4629 "item": [
4630 "314",
4631 "63",
4632 "import java.util.HashMap;\\nimport java.util.Map.Entry;\\n\\npublic class Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tUnit(String name, int strength) {\\n\\t\\tthis.name = name;\\n\\t\\tstr = strength;\\n\\t}\\n\\n\\tpublic void fight() {\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eliot\", 20);\\n\\t\\tElf elf2 = new Elf(\"Elot\", 100);\\n\\t\\tTroll troll1 = new Troll(\"Zizo\", 100);\\n\\t\\tTroll troll2 = new Troll(\"Kits\", 90);\\n\\n\\t\\tHashMap<String, Unit> army = new HashMap<>();\\n\\t\\tarmy.put(\"soldier1\", elf1);\\n\\t\\tarmy.put(\"soldier2\", elf2);\\n\\t\\tarmy.put(\"soldier3\", troll1);\\n\\t\\tarmy.put(\"soldier4\", troll2);\\n\\t\\tfor (Entry<String, Unit> unit : army.entrySet()) {\\n\\t\\t\\tunit.getValue().fight();\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t\\tarmy.remove(\"soldier1\");\\n\\t\\tfor (Entry<String, Unit> unit : army.entrySet()) {\\n\\t\\t\\tunit.getValue().fight();\\n\\t\\t}\\n\\t}\\n}\\n",
4633 "public class Elf extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Elf(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t+ \". He fights trolls.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died\");\\n\\t\\t}\\n\\t}\\n}\\n",
4634 "public class Troll extends Unit {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Troll(String name, int str) {\\n\\t\\tsuper(name, str);\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(super.name + \" has strength \" + super.str\\n\\t\\t\\t+ \". He fights trolls.\");\\n\\t\\tsuper.str = super.str - 20;\\n\\t\\tif (super.str <= 0) {\\n\\t\\t\\tSystem.out.println(super.name + \" died\");\\n\\t\\t}\\n\\t}\\n}\\n",
4635 "Trolls fight elves and elves fight trolls. One elf died. All trolls and elves were added into one HashMap's array.\\n\\nOutput:\\n\\nEliot has strength 20. He fights trolls.\\nEliot died\\nZizo has strength 100. He fights trolls.\\nElot has strength 100. He fights trolls.\\nKits has strength 90. He fights trolls.\\n\\nZizo has strength 80. He fights trolls.\\nElot has strength 80. He fights trolls.\\nKits has strength 70. He fights trolls.\\n",
4636 "Eliot has strength 20. He fights trolls.\\nEliot died\\nZizo has strength 100. He fights trolls.\\nElot has strength 100. He fights trolls.\\nKits has strength 90. He fights trolls.\\n\\nZizo has strength 80. He fights trolls.\\nElot has strength 80. He fights trolls.\\nKits has strength 70. He fights trolls.\\n",
4637 "1",
4638 "3",
4639 "148"
4640 ]
4641 },
4642 {
4643 "-name": "question315",
4644 "item": [
4645 "315",
4646 "63",
4647 "import java.util.HashMap;\\nimport java.util.Map.Entry;\\n\\npublic class Unit {\\n\\tpublic static void main(String[] args) {\\n\\t\\tElf elf1 = new Elf(\"Eliot\", 60);\\n\\t\\tString stroka = \"Stump\";\\n\\t\\tTroll troll1 = new Troll(\"Zizo\", 100);\\n\\t\\tint i = 44;\\n\\n\\t\\tHashMap<String, Object> army = new HashMap<>();\\n\\t\\tarmy.put(\"soldier1\", elf1);\\n\\t\\tarmy.put(\"soldier2\", stroka);\\n\\t\\tarmy.put(\"soldier3\", troll1);\\n\\t\\tarmy.put(\"soldier4\", i);\\n\\t\\tfor (Entry<String, Object> unit : army.entrySet()) {\\n\\t\\t\\tSystem.out.println(unit.getValue());\\n\\t\\t}\\n\\t\\tSystem.out.println();\\n\\t\\t((Elf) army.get(\"soldier1\")).fight();\\n\\t\\tSystem.out.println(army.get(\"soldier2\"));\\n\\t\\t((Troll) army.get(\"soldier3\")).fight();\\n\\t\\tSystem.out.println(army.get(\"soldier4\"));\\n\\t}\\n}\\n",
4648 "public class Elf {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Elf(String name, int str) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.str = str;\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(name + \" has strength \" + str\\n\\t\\t\\t+ \". He fights trolls.\");\\n\\t\\tstr = str - 20;\\n\\t\\tif (str <= 0) {\\n\\t\\t\\tSystem.out.println(name + \" died\");\\n\\t\\t}\\n\\t}\\n}\\n",
4649 "public class Troll {\\n\\tString name;\\n\\tint str;\\n\\n\\tpublic Troll(String name, int str) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.str = str;\\n\\t}\\n\\n\\tpublic void fight() {\\n\\n\\t\\tSystem.out.println(name + \" has strength \" + str\\n\\t\\t\\t+ \". He fights elves. \");\\n\\t\\tstr = str - 20;\\n\\t\\tif (str <= 0) {\\n\\t\\t\\tSystem.out.println(name + \" died\");\\n\\t\\t}\\n\\t}\\n}\\n",
4650 "Troll fights elf and elf fights troll. String and int variables were added into the HashMap's array.\\n\\nOutput:\\n\\nElf@22c95b\\nTroll@1d1acd3\\nStump\\n44\\n\\nEliot has strength 60. He fights trolls.\\nStump\\nZizo has strength 100. He fights elves.\\n44\\n",
4651 "Elf@22c95b\\nTroll@1d1acd3\\nStump\\n44\\n \\nEliot has strength 60. He fights trolls.\\nStump\\nZizo has strength 100. He fights elves.\\n44\\n",
4652 "1",
4653 "2",
4654 "142"
4655 ]
4656 },
4657 {
4658 "-name": "question316",
4659 "item": [
4660 "316",
4661 "64",
4662 "import java.util.TreeSet;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 100000);\\n\\t\\tCar car2 = new Car(\"KIA\", 80000);\\n\\t\\tCar car3 = new Car(\"Reno\", 95000);\\n\\t\\tCar car4 = new Car(\"Alfa\", 125000);\\n\\n\\t\\tTreeSet<Car> garage = new TreeSet<Car>();\\n\\t\\tgarage.add(car1);\\n\\t\\tgarage.add(car2);\\n\\t\\tgarage.add(car3);\\n\\t\\tgarage.add(car4);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tCar car5 = new Car(\"Audi\", 90000);\\n\\t\\tgarage.remove(car1);\\n\\t\\tgarage.add(car5);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tgarage.clear();\\n\\t}\\n}\\n",
4663 "public class Car implements Comparable<Object> {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tpublic void bayCar() {\\n\\t\\tSystem.out.println(\"We have \" + name + \". It costs \" + cost);\\n\\t}\\n\\n\\tpublic int compareTo(Object b) {\\n\\t\\tCar car = (Car) b;\\n\\t\\treturn (name.compareTo(car.name));\\n\\t}\\n}\\n",
4664 "This is an example of using methods add, remove, and clear in the TreeSet collection.\\n\\nOutput:\\n\\nWe have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 95000\\nWe have Toyota. It costs 100000\\n\\nWe have Alfa. It costs 125000\\nWe have Audi. It costs 90000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 95000\\n",
4665 "We have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 95000\\nWe have Toyota. It costs 100000\\n\\nWe have Alfa. It costs 125000\\nWe have Audi. It costs 90000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 95000\\n",
4666 "1",
4667 "2",
4668 "136"
4669 ]
4670 },
4671 {
4672 "-name": "question317",
4673 "item": [
4674 "317",
4675 "64",
4676 "import java.util.TreeSet;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 100000);\\n\\t\\tCar car2 = new Car(\"KIA\", 80000);\\n\\t\\tCar car3 = new Car(\"Reno\", 80000);\\n\\t\\tCar car4 = new Car(\"Alfa\", 125000);\\n\\n\\t\\tTreeSet<Car> garage = new TreeSet<Car>();\\n\\t\\tgarage.add(car1);\\n\\t\\tgarage.add(car2);\\n\\t\\tgarage.add(car3);\\n\\t\\tgarage.add(car4);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tSystem.out.println(\"The first car is \" + garage.first().name);\\n\\t\\tSystem.out.println(\"The last car is \" + garage.last().name);\\n\\t\\tSystem.out.println(garage.pollFirst().name + \" is removed \");\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t}\\n}\\n",
4677 "public class Car implements Comparable<Object> {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tpublic void bayCar() {\\n\\t\\tSystem.out.println(\"We have \" + name + \". It costs \" + cost);\\n\\t}\\n\\n\\tpublic int compareTo(Object b) {\\n\\t\\tCar car = (Car) b;\\n\\t\\treturn (name.compareTo(car.name));\\n\\t}\\n}\\n",
4678 "This is an example of using methods first, last and pollFirst in the TreeSet collection.\\n\\nOutput:\\n\\nWe have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n\\nThe first car is Alfa\\nThe last car is Toyota\\nAlfa is removed\\n\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n",
4679 "We have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n\\nThe first car is Alfa\\nThe last car is Toyota\\nAlfa is removed\\n\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n",
4680 "1",
4681 "2",
4682 "174"
4683 ]
4684 },
4685 {
4686 "-name": "question318",
4687 "item": [
4688 "318",
4689 "64",
4690 "import java.util.TreeSet;\\n\\npublic class Main {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Toyota\", 100000);\\n\\t\\tCar car2 = new Car(\"KIA\", 80000);\\n\\t\\tCar car3 = new Car(\"Reno\", 80000);\\n\\t\\tCar car4 = new Car(\"Alfa\", 1250000);\\n\\n\\t\\tTreeSet<Car> garage = new TreeSet<Car>();\\n\\t\\tgarage.add(car1);\\n\\t\\tgarage.add(car2);\\n\\t\\tgarage.add(car3);\\n\\t\\tgarage.add(car4);\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tSystem.out.println(\"Do you have \" + car2.name + \" ? \" + garage.contains(car2));\\n\\t\\tSystem.out.println(\"The size is \" + garage.size());\\n\\t\\tSystem.out.println(\"The 3rd car is \" + garage.tailSet(car3).first().name);\\n\\t\\tSystem.out.println(\"The 2nd car is \" + garage.tailSet(car2).first().name);\\n\\t\\tSystem.out.println(\" \");\\n\\t\\tfor (Car cars : garage) {\\n\\t\\t\\tcars.bayCar();\\n\\t\\t}\\n\\t}\\n}\\n",
4691 "public class Car implements Comparable<Object> {\\n\\tString name;\\n\\tint cost;\\n\\n\\tCar(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tpublic void bayCar() {\\n\\t\\tSystem.out.println(\"We have \" + name + \". It costs \" + cost);\\n\\t}\\n\\n\\tpublic int compareTo(Object b) {\\n\\t\\tCar car = (Car) b;\\n\\t\\treturn (name.compareTo(car.name));\\n\\t}\\n}\\n",
4692 "This is an example of using methods contains, size, tailSet and first in the TreeSet collection.\\n\\nOutput:\\n\\nDo you have KIA ? true\\nThe size is 4\\nThe 3rd car is Reno\\nThe 2nd car is KIA\\n\\nWe have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n",
4693 "Do you have KIA ? true\\nThe size is 4\\nThe 3rd car is Reno\\nThe 2nd car is KIA\\n\\nWe have Alfa. It costs 125000\\nWe have KIA. It costs 80000\\nWe have Reno. It costs 80000\\nWe have Toyota. It costs 100000\\n",
4694 "1",
4695 "2",
4696 "174"
4697 ]
4698 },
4699 {
4700 "-name": "question319",
4701 "item": [
4702 "319",
4703 "64",
4704 "import java.util.TreeSet;\\n\\npublic class Exam {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tGirl student1 = new Girl(\"Brown\", 4);\\n\\t\\tGirl student2 = new Girl(\"Davies\", 3);\\n\\t\\tGirl student3 = new Girl(\"Miller\", 5);\\n\\n\\t\\tTreeSet<Girl> group = new TreeSet<Girl>();\\n\\t\\tgroup.add(student1);\\n\\t\\tgroup.add(student2);\\n\\t\\tgroup.add(student3);\\n\\t\\tfor (Girl students : group) {\\n\\t\\t\\tstudents.getMark();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
4705 "public class Girl implements Comparable<Object> {\\n\\tString name;\\n\\tint mark;\\n\\n\\tGirl(String name, int mark) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.mark = mark;\\n\\t}\\n\\n\\tpublic void getMark() {\\n\\t\\tSystem.out.println(name + \" received \" + mark);\\n\\t}\\n\\n\\tpublic int compareTo(Object b) {\\n\\t\\tGirl car = (Girl) b;\\n\\t\\treturn (name.compareTo(car.name));\\n\\t}\\n}\\n",
4706 "This is an example of using the add method in the TreeSet collection.\\n\\nOutput:\\n\\nBrown received 5\\nDavies received 3\\nMiller received 4\\n",
4707 "Brown received 5\\nDavies received 3\\nMiller received 4\\n",
4708 "1",
4709 "1",
4710 "112"
4711 ]
4712 },
4713 {
4714 "-name": "question320",
4715 "item": [
4716 "320",
4717 "64",
4718 "public class Girl implements Comparable<Object> {\\n\\tString name;\\n\\tint mark;\\n\\n\\tGirl(String name, int mark) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.mark = mark;\\n\\t}\\n\\n\\tpublic void getMark() {\\n\\t\\tSystem.out.println(name + \" received \" + mark);\\n\\t}\\n\\n\\tpublic int compareTo(Object b) {\\n\\t\\tGirl car = (Girl) b;\\n\\t\\treturn (name.compareTo(car.name));\\n\\t}\\n}\\n",
4719 "import java.util.TreeSet;\\n\\npublic class Exam {\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tGirl student1 = new Girl(\"Brown\", 4);\\n\\t\\tGirl student2 = new Girl(\"Davies\", 3);\\n\\t\\tGirl student3 = new Girl(\"Miller\", 5);\\n\\n\\t\\tTreeSet<Girl> group = new TreeSet<Girl>();\\n\\t\\tgroup.add(student1);\\n\\t\\tgroup.add(student2);\\n\\t\\tgroup.add(student3);\\n\\t\\tfor (Girl students : group) {\\n\\t\\t\\tstudents.getMark();\\n\\t\\t}\\n\\t\\tSystem.out.println(\" \");\\n\\t}\\n}\\n",
4720 "This is an example of the implementation class in the TreeSet collection.\\n\\nOutput:\\n\\nBrown received 5\\nDavies received 3\\nMiller received 4\\n",
4721 "Brown received 5\\nDavies received 3\\nMiller received 4\\n",
4722 "1",
4723 "3",
4724 "1"
4725 ]
4726 },
4727 {
4728 "-name": "question321",
4729 "item": [
4730 "321",
4731 "65",
4732 "import java.util.ArrayList;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tInteger number1 = new Integer(99);\\n\\t\\tSystem.out.println(number1);\\n\\t\\tInteger number2 = 100;\\n\\t\\tSystem.out.println(number2);\\n\\t\\tint a1 = number1.intValue();\\n\\t\\tSystem.out.println(a1);\\n\\t\\tint a2 = number2;\\n\\t\\tSystem.out.println(a2);\\n\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tarray1.add(car1);\\n\\t\\tarray1.add(number1);\\n\\t\\tarray1.add(number2);\\n\\t\\tarray1.add(a1);\\n\\t\\tSystem.out.println(array1.toString());\\n\\t}\\n}\\n",
4733 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"This is the car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4734 "The program shows the converting and autoboxing variables of type int in the Integer object and back. The program shows the using of Integer objects in the ArrayList.\\n\\nOutput:\\n\\n99\\n100\\n99\\n100\\n[This is the car KIA., 99, 100, 99]\\n",
4735 "99\\n100\\n99\\n100\\n[This is the car KIA., 99, 100, 99]\\n",
4736 "1",
4737 "2",
4738 "28"
4739 ]
4740 },
4741 {
4742 "-name": "question322",
4743 "item": [
4744 "322",
4745 "65",
4746 "import java.util.ArrayList;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tDouble numer1 = new Double(99);\\n\\t\\tSystem.out.println(numer1);\\n\\t\\tDouble numer2 = 5.666666666;\\n\\t\\tSystem.out.println(numer2);\\n\\t\\tdouble a1 = numer1.doubleValue();\\n\\t\\tSystem.out.println(a1);\\n\\t\\tdouble a2 = numer2;\\n\\t\\tSystem.out.println(a2);\\n\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tarray1.add(car1);\\n\\t\\tarray1.add(numer1);\\n\\t\\tarray1.add(numer2);\\n\\t\\tarray1.add(a1);\\n\\t\\tSystem.out.println(array1.toString());\\n\\t}\\n}\\n",
4747 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"This is the car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4748 "The program shows the converting and autoboxing variables of type double in the Double object and back. The program shows the using of Double objects in the ArrayList.\\n\\nOutput:\\n\\n99.0\\n5.666666666\\n99.0\\n5.666666666\\n[This is the car KIA., 99.0, 5.666666666, 99.0]\\n",
4749 "99.0\\n5.666666666\\n99.0\\n5.666666666\\n[This is the car KIA., 99.0, 5.666666666, 99.0]\\n",
4750 "1",
4751 "2",
4752 "61"
4753 ]
4754 },
4755 {
4756 "-name": "question323",
4757 "item": [
4758 "323",
4759 "65",
4760 "import java.util.ArrayList;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCharacter char1 = new Character('b');\\n\\t\\tSystem.out.println(char1);\\n\\t\\tCharacter char2 = 'd';\\n\\t\\tSystem.out.println(char2);\\n\\t\\tchar a1 = char1.charValue();\\n\\t\\tSystem.out.println(a1);\\n\\t\\tchar a2 = char2;\\n\\t\\tSystem.out.println(a2);\\n\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tarray1.add(car1);\\n\\t\\tarray1.add(char1);\\n\\t\\tarray1.add(char2);\\n\\t\\tarray1.add(a1);\\n\\t\\tSystem.out.println(array1.toString());\\n\\t}\\n}\\n",
4761 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"This is the car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4762 "The program shows the converting and autoboxing variables of type char in the Character object and back. The program shows the using of Character objects in the ArrayList.\\n\\nOutput:\\n\\nb\\nd\\nb\\nd\\n[This is the car KIA., b, d, b]\\n",
4763 "b\\nd\\nb\\nd\\n[This is the car KIA., b, d, b]\\n",
4764 "1",
4765 "2",
4766 "28"
4767 ]
4768 },
4769 {
4770 "-name": "question324",
4771 "item": [
4772 "324",
4773 "65",
4774 "import java.util.ArrayList;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tBoolean bool1 = new Boolean(true);\\n\\t\\tSystem.out.println(bool1);\\n\\t\\tBoolean bool2 = false;\\n\\t\\tSystem.out.println(bool2);\\n\\t\\tboolean b1 = bool1.booleanValue();\\n\\t\\tSystem.out.println(b1);\\n\\t\\tboolean b2 = bool2;\\n\\t\\tSystem.out.println(b2);\\n\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tarray1.add(car1);\\n\\t\\tarray1.add(bool1);\\n\\t\\tarray1.add(bool2);\\n\\t\\tarray1.add(b1);\\n\\t\\tSystem.out.println(array1.toString());\\n\\t}\\n}\\n",
4775 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"This is the car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4776 "The program shows the converting and autoboxing variables of type boolean in the Boolean object and back. The program shows the using of Boolean objects in the ArrayList.\\n\\nOutput:\\n\\ntrue\\nfalse\\ntrue\\nfalse\\n[This is the car KIA., true, false, true]\\n",
4777 "true\\nfalse\\ntrue\\nfalse\\n[This is the car KIA., true, false, true]\\n",
4778 "1",
4779 "2",
4780 "28"
4781 ]
4782 },
4783 {
4784 "-name": "question325",
4785 "item": [
4786 "325",
4787 "65",
4788 "import java.util.ArrayList;\\n\\npublic class Test {\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tByte byte1 = new Byte((byte) 9);\\n\\t\\tSystem.out.println(byte1);\\n\\t\\tByte byte2 = 100;\\n\\t\\tSystem.out.println(byte2);\\n\\t\\tbyte a1 = byte1.byteValue();\\n\\t\\tSystem.out.println(a1);\\n\\t\\tbyte a2 = byte2;\\n\\t\\tSystem.out.println(a2);\\n\\n\\t\\tArrayList<Object> array1 = new ArrayList<Object>();\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tarray1.add(car1);\\n\\t\\tarray1.add(byte1);\\n\\t\\tarray1.add(byte2);\\n\\t\\tarray1.add(a1);\\n\\t\\tSystem.out.println(array1.toString());\\n\\t}\\n}\\n",
4789 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"This is the car \" + name + \".\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4790 "The program shows the converting and autoboxing variables of type byte in the Byte object and back. The program shows the using of Byte objects in the ArrayList.\\n\\nOutput:\\n\\n9\\n100\\n9\\n100\\n[This is the car KIA., 9, 100, 9]\\n",
4791 "9\\n100\\n9\\n100\\n[This is the car KIA., 9, 100, 9]\\n",
4792 "1",
4793 "2",
4794 "65"
4795 ]
4796 },
4797 {
4798 "-name": "question326",
4799 "item": [
4800 "326",
4801 "66",
4802 "public class Fig <T> {\\n\\tT figure;\\n\\n\\tFig(T figure) {\\n\\t\\tthis.figure = figure;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(5);\\n\\t\\tRect rectangle1 = new Rect(12, 7);\\n\\t\\tCirc circle2 = new Circ(4);\\n\\t\\tRect rectangle2 = new Rect(11, 8);\\n\\t\\tFig<Circ> figure1 = new Fig<>(circle1);\\n\\t\\tFig<Rect> figure2 = new Fig<>(rectangle1);\\n\\t\\tFig<Circ> figure3 = new Fig<>(circle2);\\n\\t\\tFig<Rect> figure4 = new Fig<>(rectangle2);\\n\\t\\tSystem.out.println(\"The figure is \" + figure1.figure.getClass().getName());\\n\\t\\tSystem.out.println(\"The area is \" + figure1.figure.getSquare());\\n\\t\\tSystem.out.println(\"The figure is \" + figure2.figure.getClass().getName());\\n\\t\\tSystem.out.println(\"The area is \" + figure2.figure.getSquare());\\n\\t\\tSystem.out.println(\"The figure is \" + figure3.figure.getClass().getName());\\n\\t\\tSystem.out.println(\"The area is \" + figure3.figure.getSquare());\\n\\t\\tSystem.out.println(\"The figure is \" + figure4.figure.getClass().getName());\\n\\t\\tSystem.out.println(\"The area is \" + figure4.figure.getSquare());\\n\\t}\\n}\\n",
4803 "public class Rect {\\n\\tString name = \"Rectangle\";\\n\\tint length;\\n\\tint width;\\n\\n\\tRect(int length, int width) {\\n\\t\\tthis.length = length;\\n\\t\\tthis.width = width;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = length * width;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4804 "public class Circ {\\n\\tString name = \"Circle\";\\n\\tint radius;\\n\\n\\tCirc(int radius) {\\n\\t\\tthis.radius = radius;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4805 "The program displays the class type of the figure and the area of this figure.\\n\\nOutput:\\n\\nThe figure is Circ\\nThe area is 78.53981633974483\\nThe figure is Rect\\nThe area is 84.0\\nThe figure is Circ\\nThe area is 50.26548245743669\\nThe figure is Rect\\nThe area is 88.0\\n",
4806 "The figure is Circ\\nThe area is 78.53981633974483\\nThe figure is Rect\\nThe area is 84.0\\nThe figure is Circ\\nThe area is 50.26548245743669\\nThe figure is Rect\\nThe area is 88.0\\n",
4807 "1",
4808 "2",
4809 "97"
4810 ]
4811 },
4812 {
4813 "-name": "question327",
4814 "item": [
4815 "327",
4816 "66",
4817 "public class Prof <T> {\\n\\tT profession;\\n\\n\\tProf(T ob) {\\n\\t\\tprofession = ob;\\n\\t}\\n\\n\\tpublic void discribe() {\\n\\t\\tSystem.out.println(\"The type of the profession is \" + profession.getClass().getName());\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tDoct doc1 = new Doct();\\n\\t\\tMil mil1 = new Mil();\\n\\t\\tMil mil2 = new Mil();\\n\\t\\tProf<Doct> man1 = new Prof<>(doc1);\\n\\t\\tProf<Mil> man2 = new Prof<>(mil1);\\n\\t\\tProf<Mil> man3 = new Prof<>(mil2);\\n\\t\\tman1.discribe();\\n\\t\\tman1.profession.work();\\n\\t\\tman2.discribe();\\n\\t\\tman2.profession.work();\\n\\t\\tman3.discribe();\\n\\t\\tman3.profession.work();\\n\\t}\\n}\\n",
4818 "public class Doct {\\n\\n\\tString name = \"A doctor\";\\n\\n\\tpublic void work() {\\n\\t\\tSystem.out.println(name + \" treats patients\");\\n\\t}\\n}\\n",
4819 "public class Mil {\\n\\tString name = \"A militarian\";\\n\\n\\tpublic void work() {\\n\\t\\tSystem.out.println(name + \" shoots PIF-PAF\");\\n\\t}\\n}\\n",
4820 "The program displays the class type of the profession and what do the people of these professions.\\n\\nOutput:\\n\\nThe type of the profession is Doct\\nA doctor treats patients\\nThe type of the profession is Mil\\nA militarian shoots PIF-PAF\\nThe type of the profession is Mil\\nA militarian shoots PIF-PAF\\n",
4821 "The type of the profession is Doct\\nA doctor treats patients\\nThe type of the profession is Mil\\nA militarian shoots PIF-PAF\\nThe type of the profession is Mil\\nA militarian shoots PIF-PAF\\n",
4822 "1",
4823 "3",
4824 "1"
4825 ]
4826 },
4827 {
4828 "-name": "question328",
4829 "item": [
4830 "328",
4831 "66",
4832 "public class Home <T> {\\n\\tT number;\\n\\n\\tHome(T ob) {\\n\\t\\tnumber = ob;\\n\\t}\\n\\n\\tpublic T getNumber() {\\n\\t\\treturn number;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHome<Integer> attempt1 = new Home<>(12);\\n\\t\\tSystem.out.println(\"The home â„– is \" + attempt1.getNumber());\\n\\t\\tHome<Double> attempt2 = new Home<>(12.0);\\n\\t\\tSystem.out.println(\"The home â„– is \" + attempt2.getNumber());\\n\\t\\tHome<String> attempt3 = new Home<>(\"25\");\\n\\t\\tSystem.out.println(\"The home â„– is \" + attempt3.getNumber());\\n\\t\\tHome<Character> attempt4 = new Home<>('8');\\n\\t\\tSystem.out.println(\"The home â„– is \" + attempt4.getNumber());\\n\\t}\\n}\\n",
4833 "The program displays the number of the house, regardless of data types, in which the number was recorded (int, double, String, char).\\n\\nOutput:\\n\\nThe home â„– is 12\\nThe home â„– is 12.0\\nThe home â„– is 25\\nThe home â„– is 8\\n",
4834 "The home â„– is 12\\nThe home â„– is 12.0\\nThe home â„– is 25\\nThe home â„– is 8\\n",
4835 "1",
4836 "3",
4837 "1"
4838 ]
4839 },
4840 {
4841 "-name": "question329",
4842 "item": [
4843 "329",
4844 "66",
4845 "public class Car <T> {\\n\\tT car;\\n\\n\\tCar(T ob) {\\n\\t\\tcar = ob;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar<BMW> car1 = new Car<BMW>(new BMW(2011, \"x5\"));\\n\\t\\tCar<BMW> car2 = new Car<BMW>(new BMW(2012, \"x4\"));\\n\\t\\tCar<KIA> car3 = new Car<KIA>(new KIA(2013, \"sportage\"));\\n\\t\\tCar<KIA> car4 = new Car<KIA>(new KIA(2009, \"elza\"));\\n\\t\\tSystem.out.println(car1.car.toString());\\n\\t\\tSystem.out.println(car2.car.toString());\\n\\t\\tSystem.out.println(car3.car.toString());\\n\\t\\tSystem.out.println(car4.car.toString());\\n\\t}\\n}\\n",
4846 "public class BMW {\\n\\tString name = \"BMW\";\\n\\tString model;\\n\\tint year;\\n\\n\\tBMW(int year, String n) {\\n\\t\\tthis.year = year;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Car \" + name + model + \" year-\" + year + \" Germany\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4847 "public class KIA {\\n\\tString name = \"KIA\";\\n\\tString model;\\n\\tint year;\\n\\n\\tKIA(int year, String n) {\\n\\t\\tthis.year = year;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Car \" + name + model + \" year-\" + year + \" Korea\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4848 "The program displays messages about the name of the car, the year and the country of production.\\n\\nOutput:\\n\\nCar BMWx5 year-2011 Germany\\nCar BMWx4 year-2012 Germany\\nCar KIAsportage year-2013 Korea\\nCar KIAelza year-2009 Korea\\n",
4849 "Car BMWx5 year-2011 Germany\\nCar BMWx4 year-2012 Germany\\nCar KIAsportage year-2013 Korea\\nCar KIAelza year-2009 Korea\\n",
4850 "1",
4851 "3",
4852 "1"
4853 ]
4854 },
4855 {
4856 "-name": "question330",
4857 "item": [
4858 "330",
4859 "66",
4860 "public class Prod <T> {\\n\\tT typeProd;\\n\\n\\tProd(T ob) {\\n\\t\\ttypeProd = ob;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tProd<Tel> prod1 = new Prod<Tel>(new Tel(200, \"15gt\"));\\n\\t\\tProd<Tel> prod2 = new Prod<Tel>(new Tel(350, \"300s\"));\\n\\t\\tProd<Cam> prod3 = new Prod<Cam>(new Cam(185, \"Cam-12-l\"));\\n\\t\\tProd<Cam> prod4 = new Prod<Cam>(new Cam(93, \"Cam-12-nm\"));\\n\\t\\tSystem.out.println(prod1.typeProd.toString());\\n\\t\\tSystem.out.println(prod2.typeProd.toString());\\n\\t\\tSystem.out.println(prod3.typeProd.toString());\\n\\t\\tSystem.out.println(prod4.typeProd.toString());\\n\\t}\\n}\\n",
4861 "public class Tel {\\n\\tString model;\\n\\tint cost;\\n\\n\\tTel(int cost, String n) {\\n\\t\\tthis.cost = cost;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Phone \" + model + \" price \" + cost + \" dol.\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4862 "public class Cam {\\n\\tString model;\\n\\tint cost;\\n\\n\\tCam(int cost, String n) {\\n\\t\\tthis.cost = cost;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Camera \" + model + \" price \" + cost + \" dol.\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4863 "The program displays messages about names of goods in the store and their prices.\\n\\nOutput:\\n\\nPhone 15gt price 200 dol.\\nPhone 300s price 350 dol.\\nCamera Cam-12-l price 185 dol.\\nCamera Cam-12-nm price 93 dol.\\n",
4864 "Phone 15gt price 200 dol.\\nPhone 300s price 350 dol.\\nCamera Cam-12-l price 185 dol.\\nCamera Cam-12-nm price 93 dol.\\n",
4865 "1",
4866 "3",
4867 "1"
4868 ]
4869 },
4870 {
4871 "-name": "question331",
4872 "item": [
4873 "331",
4874 "67",
4875 "public class Fig <T, E> {\\n\\tT figure;\\n\\tE numer;\\n\\n\\tFig(T figure, E numer) {\\n\\t\\tthis.figure = figure;\\n\\t\\tthis.numer = numer;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(5);\\n\\t\\tRect rectangle1 = new Rect(12, 7);\\n\\t\\tCirc circle2 = new Circ(4);\\n\\t\\tRect rectangle2 = new Rect(11, 8);\\n\\t\\tFig<Circ, Integer> figure1 = new Fig<>(circle1, 5);\\n\\t\\tFig<Rect, Integer> figure2 = new Fig<>(rectangle1, 10);\\n\\t\\tFig<Circ, Double> figure3 = new Fig<>(circle2, 11.5);\\n\\t\\tFig<Rect, Double> figure4 = new Fig<>(rectangle2, 10.5);\\n\\t\\tSystem.out.println(figure1.figure.getClass().getName() + \", \"\\n\\t\\t\\t\\t+ figure1.numer + \" шт.\");\\n\\t\\tSystem.out.println(\"ÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ \" + figure1.figure.getSquare()\\n\\t\\t\\t\\t* figure1.numer);\\n\\t\\tSystem.out.println(figure2.figure.getClass().getName() + \", \"\\n\\t\\t\\t\\t+ figure1.numer + \" шт.\");\\n\\t\\tSystem.out.println(\"ÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ \" + figure2.figure.getSquare()\\n\\t\\t\\t\\t* figure2.numer);\\n\\t\\tSystem.out.println(figure3.figure.getClass().getName() + \", \"\\n\\t\\t\\t\\t+ figure1.numer + \" шт.\");\\n\\t\\tSystem.out.println(\"ÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ \" + figure3.figure.getSquare()\\n\\t\\t\\t\\t* figure3.numer);\\n\\t\\tSystem.out.println(figure4.figure.getClass().getName() + \", \"\\n\\t\\t\\t\\t+ figure1.numer + \" шт.\");\\n\\t\\tSystem.out.println(\"ÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ \" + figure4.figure.getSquare()\\n\\t\\t\\t\\t* figure4.numer);\\n\\t\\t}\\n}\\n",
4876 "public class Circ {\\n\\tString name = \"Круг\";\\n\\tint radius;\\n\\n\\tCirc(int radius) {\\n\\t\\tthis.radius = radius;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4877 "public class Rect {\\n\\tString name = \"ПрÑмоугольник\";\\n\\tint length;\\n\\tint width;\\n\\n\\tRect(int length, int width) {\\n\\t\\tthis.length = length;\\n\\t\\tthis.width = width;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = length * width;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4878 "Программа выводит ÑÐ¾Ð¾Ð±Ñ‰ÐµÐ½Ð¸Ñ Ð¾ названии клаÑÑа фигуры, количеÑтве фигур и общей площади Ñтих фигур.\\n\\nОтвет:\\n\\nCirc, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 392.69908169872417\\nRect, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 840.0\\nCirc, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 578.0530482605219\\nRect, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 924.0\\n",
4879 "Circ, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 392.69908169872417\\nRect, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 840.0\\nCirc, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 578.0530482605219\\nRect, 5 шт.\\nÐžÐ±Ñ‰Ð°Ñ Ð¿Ð»Ð¾Ñ‰Ð°Ð´ÑŒ 924.0\\n",
4880 "1",
4881 "2",
4882 "257"
4883 ]
4884 },
4885 {
4886 "-name": "question332",
4887 "item": [
4888 "332",
4889 "67",
4890 "public class Prof <T, E> {\\n\\tT profession;\\n\\tE mark;\\n\\n\\tProf(T ob1, E ob2) {\\n\\t\\tprofession = ob1;\\n\\t\\tmark = ob2;\\n\\t}\\n\\n\\tpublic void discribe() {\\n\\t\\tSystem.out.println(\"The profession is \" + profession.getClass().getName());\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tDoct doc1 = new Doct();\\n\\t\\tMil mil1 = new Mil();\\n\\t\\tMil mil2 = new Mil();\\n\\t\\tProf<Doct, String> man1 = new Prof<>(doc1, \"It's a good job\");\\n\\t\\tProf<Mil, String> man2 = new Prof<>(mil1, \"This is important work\");\\n\\t\\tProf<Mil, Integer> man3 = new Prof<>(mil2, 5);\\n\\t\\tman1.discribe();\\n\\t\\tman1.profession.work();\\n\\t\\tSystem.out.println(man1.mark);\\n\\t\\tman2.discribe();\\n\\t\\tman2.profession.work();\\n\\t\\tSystem.out.println(man2.mark);\\n\\t\\tman3.discribe();\\n\\t\\tman3.profession.work();\\n\\t\\tSystem.out.println(man3.mark);\\n\\t}\\n}\\n",
4891 "public class Doct {\\n\\n\\tString name = \"A doctor\";\\n\\n\\tpublic void work() {\\n\\t\\tSystem.out.println(name + \" treats patients\");\\n\\t}\\n}\\n",
4892 "public class Mil {\\n\\tString name = \"A militarian\";\\n\\n\\tpublic void work() {\\n\\t\\tSystem.out.println(name + \" shoots PIF-PAF\");\\n\\t}\\n}\\n",
4893 "The program displays the class type of professions and what do people of these professions.The program evaluates work of people of these professions.\\n\\nOutput:\\n\\nThe profession is Doct\\nA doctor treats patients\\nIt's a good job\\nThe profession is Mil\\nA militarian shoots PIF-PAF\\nThis is important work\\nThe profession is Mil\\nA militarian shoots PIF-PAF\\n5\\n",
4894 "The profession is Doct\\nA doctor treats patients\\nIt's a good job\\nThe profession is Mil\\nA militarian shoots PIF-PAF\\nThis is important work\\nThe profession is Mil\\nA militarian shoots PIF-PAF\\n5\\n",
4895 "1",
4896 "3",
4897 "1"
4898 ]
4899 },
4900 {
4901 "-name": "question333",
4902 "item": [
4903 "333",
4904 "67",
4905 "public class Home<T, E> {\\n\\tT numer;\\n\\tE street;\\n\\n\\tHome(T ob1, E ob2) {\\n\\t\\tnumer = ob1;\\n\\t\\tstreet = ob2;\\n\\t}\\n\\n\\tpublic T getNumber() {\\n\\t\\treturn numer;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tHome<Integer, String> attempt1 = new Home<>(12, \"Milk St.\");\\n\\t\\tSystem.out.println(attempt1.getNumber() + \" \" + attempt1.street);\\n\\t\\tHome<Double, String> attempt2 = new Home<>(12.0, \"Lenin Avenue\");\\n\\t\\tSystem.out.println(attempt2.getNumber() + \" \" + attempt2.street);\\n\\t\\tHome<String, String> attempt3 = new Home<>(\"25\", \"Atlantic Avenue\");\\n\\t\\tSystem.out.println(attempt3.getNumber() + \" \" + attempt3.street);\\n\\t\\tHome<Character, String> attempt4 = new Home<>('8', \"Federal St.\");\\n\\t\\tSystem.out.println(attempt4.getNumber() + \" \" + attempt4.street);\\n\\t}\\n}\\n",
4906 "The program displays a message about the name of the street and house number. Data are stored in different data types.\\n\\nOutput:\\n\\n12 Milk St.\\n12.0 Lenin Avenue\\n25 Atlantic Avenue\\n8 Federal St.\\n",
4907 "12 Milk St.\\n12.0 Lenin Avenue\\n25 Atlantic Avenue\\n8 Federal St.\\n",
4908 "1",
4909 "3",
4910 "1"
4911 ]
4912 },
4913 {
4914 "-name": "question334",
4915 "item": [
4916 "334",
4917 "67",
4918 "public class Car <T, E> {\\n\\tT car;\\n\\tE cost;\\n\\n\\tCar(T ob1, E ob2) {\\n\\t\\tcar = ob1;\\n\\t\\tcost = ob2;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCar<BMW, Integer> car1 = new Car<>(new BMW(2011, \"x5\"), 80000);\\n\\t\\tCar<BMW, String> car2 = new Car<>(new BMW(2012, \"x4\"), \" hundred thousand\");\\n\\t\\tCar<KIA, Double> car3 = new Car<>(new KIA(2013, \"sportage\"), 30000.0);\\n\\t\\tCar<KIA, Character> car4 = new Car<>(new KIA(2009, \"elza\"), '1');\\n\\t\\tSystem.out.println(car1.car.toString() + \" \" + car1.cost);\\n\\t\\tSystem.out.println(car2.car.toString() + \" \" + car2.cost);\\n\\t\\tSystem.out.println(car3.car.toString() + \" \" + car3.cost);\\n\\t\\tSystem.out.println(car4.car.toString() + \" \" + car4.cost + \" hundred thousand\");\\n\\t}\\n}\\n",
4919 "public class KIA {\\n\\tString name = \"KIA\";\\n\\tString model;\\n\\tint year;\\n\\n\\tKIA(int year, String n) {\\n\\t\\tthis.year = year;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Car \" + name + model + \" year-\" + year + \" Korea\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4920 "public class BMW {\\n\\tString name = \"BMW\";\\n\\tString model;\\n\\tint year;\\n\\n\\tBMW(int year, String n) {\\n\\t\\tthis.year = year;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Car \" + name + model + \" year-\" + year + \" Germany\";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4921 "The program displays messages about names of cars, years of manufacture, countries of production and prices.\\n\\nOutput:\\n\\nCar BMWx5 year-2011 Germany 80000\\nCar BMWx4 year-2012 Germany hundred thousand\\nCar KIAsportage year-2013 Korea 30000.0\\nCar KIAelza year-2009 Korea 1 hundred thousand\\n",
4922 "Car BMWx5 year-2011 Germany 80000\\nCar BMWx4 year-2012 Germany hundred thousand\\nCar KIAsportage year-2013 Korea 30000.0\\nCar KIAelza year-2009 Korea 1 hundred thousand\\n",
4923 "1",
4924 "3",
4925 "61"
4926 ]
4927 },
4928 {
4929 "-name": "question335",
4930 "item": [
4931 "335",
4932 "67",
4933 "public class Prod <T, E> {\\n\\tT typeProd;\\n\\tE hit;\\n\\n\\tProd(T ob1, E ob2) {\\n\\t\\ttypeProd = ob1;\\n\\t\\thit = ob2;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tProd<Tel, String> prod1 = new Prod<>(new Tel(200, \"15gt\"), \"It is a sales leader\");\\n\\t\\tProd<Tel, Boolean> prod2 = new Prod<>(new Tel(350, \"300s\"), false);\\n\\t\\tProd<Cam, Boolean> prod3 = new Prod<>(new Cam(185, \"Cam-12-l\"), true);\\n\\t\\tProd<Cam, String> prod4 = new Prod<>(new Cam(93, \"Cam-12-nm\"),\\n\\t\\t\\t\\t\"It is not a sales leader\");\\n\\t\\tSystem.out.println(prod1.typeProd.toString() + prod1.hit);\\n\\t\\tSystem.out.println(prod2.typeProd.toString() + \"Is it a sales leader? \" + prod2.hit);\\n\\t\\tSystem.out.println(prod3.typeProd.toString() + \"Is it a sales leader? \" + prod3.hit);\\n\\t\\tSystem.out.println(prod4.typeProd.toString() + prod4.hit);\\n\\t}\\n}\\n",
4934 "public class Cam {\\n\\tString model;\\n\\tint cost;\\n\\n\\tCam(int cost, String n) {\\n\\t\\tthis.cost = cost;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Camera \" + model + \" price \" + cost + \" dol. \";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4935 "public class Tel {\\n\\tString model;\\n\\tint cost;\\n\\n\\tTel(int cost, String n) {\\n\\t\\tthis.cost = cost;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Phone \" + model + \" price \" + cost + \" dol. \";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
4936 "The program displays messages about names of goods in the store, their prices. The program displays a message if the product is a sales leader.\\n \\nOutput:\\n\\nPhone 15gt price 200 dol. It is a sales leader\\nPhone 300s price 350 dol. Is it a sales leader? false\\nCamera Cam-12-l price 185 dol. Is it a sales leader? true\\nCamera Cam-12-nm price 93 dol. It is not a sales leader\\n",
4937 "Phone 15gt price 200 dol. It is a sales leader\\nPhone 300s price 350 dol. Is it a sales leader? false\\nCamera Cam-12-l price 185 dol. Is it a sales leader? true\\nCamera Cam-12-nm price 93 dol. It is not a sales leader\\n",
4938 "1",
4939 "3",
4940 "1"
4941 ]
4942 },
4943 {
4944 "-name": "question336",
4945 "item": [
4946 "336",
4947 "68",
4948 "public class Main <T extends Fig> {\\n\\tT figure;\\n\\n\\tMain(T figure) {\\n\\t\\tthis.figure = figure;\\n\\t}\\n\\n\\tpublic String getInfo() {\\n\\t\\tString s = \"The figure is a \" + figure.name + \", the color is \" + figure.color\\n\\t\\t\\t\\t+ \", the perimeter is \" + figure.getLength() + \", the area is \"\\n\\t\\t\\t\\t+ figure.getSquare();\\n\\t\\treturn s;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(\"circle\", \"blue\", 5);\\n\\t\\tFig fig2 = new Fig();\\n\\t\\tMain<Circ> main1 = new Main<>(circle1);\\n\\t\\tMain<Fig> main2 = new Main<>(fig2);\\n\\t\\tSystem.out.println(main1.getInfo());\\n\\t\\tSystem.out.println(main2.getInfo());\\n\\t}\\n}\\n",
4949 "public class Circ extends Fig {\\n\\tint radius;\\n\\n\\tCirc(String name, String color, int radius) {\\n\\t\\tthis.color = color;\\n\\t\\tthis.name = name;\\n\\t\\tthis.radius = radius;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double getLength() {\\n\\t\\tdouble area = 2 * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4950 "public class Fig {\\n\\tString name = \"some figure\";\\n\\tString color = \"no color\";\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = 0;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic double getLength() {\\n\\t\\tdouble area = 0;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4951 "The program displays messages about the name of a figure, its color, its perimeter, and its area.\\n\\nOutput:\\n\\nThe figure is a circle, the color is blue, the perimeter is 31.41592653589793, the area is 78.53981633974483\\nThe figure is a some figure, the color is no color, the perimeter is 0.0, the area is 0.0\\n",
4952 "The figure is a circle, the color is blue, the perimeter is 31.41592653589793, the area is 78.53981633974483\\nThe figure is a some figure, the color is no color, the perimeter is 0.0, the area is 0.0\\n",
4953 "1",
4954 "3",
4955 "1"
4956 ]
4957 },
4958 {
4959 "-name": "question337",
4960 "item": [
4961 "337",
4962 "68",
4963 "public class Fig <T extends Fig<?>> {\\n\\tT figure = null;\\n\\tString name;\\n\\tString color;\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = 0;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic String getInfo() {\\n\\t\\tString s = \"The figure is a\" + figure.name + \", the color is \" + figure.color\\n\\t\\t\\t\\t+ \", the area is \" + figure.getSquare();\\n\\t\\treturn s;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(\"circle\", \"blue\", 5);\\n\\t\\tRect rectangl1 = new Rect(\"rectangle\", \"yellow \", 7, 8);\\n\\t\\tFig<Circ> figure1 = new Fig<>();\\n\\t\\tFig<Rect> figure2 = new Fig<>();\\n\\t\\tfigure1.figure = circle1;\\n\\t\\tfigure2.figure = rectangl1;\\n\\t\\tSystem.out.println(figure1.getInfo());\\n\\t\\tSystem.out.println(figure2.getInfo());\\n\\t}\\n}\\n",
4964 "public class Circ extends Fig {\\n\\tint radius;\\n\\n\\tCirc(String name, String color, int radius) {\\n\\t\\tthis.color = color;\\n\\t\\tthis.name = name;\\n\\t\\tthis.radius = radius;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4965 "public class Rect extends Fig {\\n\\tint width;\\n\\tint length;\\n\\n\\tRect(String name, String color, int width, int length) {\\n\\t\\tthis.color = color;\\n\\t\\tthis.name = name;\\n\\t\\tthis.width = width;\\n\\t\\tthis.length = length;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = width * length;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
4966 "The program displays messages about names of figures, their colors and areas.\\n\\nOutput:\\n\\nThe figure is a circle, the color is blue, the area is 78.53981633974483\\nThe figure is a rectangle, the color is yellow , the area is 56.0\\n",
4967 "The figure is a circle, the color is blue, the area is 78.53981633974483\\nThe figure is a rectangle, the color is yellow , the area is 56.0\\n",
4968 "1",
4969 "3",
4970 "1"
4971 ]
4972 },
4973 {
4974 "-name": "question338",
4975 "item": [
4976 "338",
4977 "68",
4978 "public class Task <T extends Number> {\\n\\tT objectNum;\\n\\tdouble sum = 0;\\n\\n\\tTask(T ob) {\\n\\t\\tobjectNum = ob;\\n\\t}\\n\\n\\tpublic void summa() {\\n\\t\\tsum = sum + objectNum.doubleValue();\\n\\t}\\n\\n\\tpublic void showSum() {\\n\\t\\tSystem.out.println(objectNum.getClass().getName() + \" \" + sum);\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tTask<?> slog1 = new Task<>(15);\\n\\t\\tslog1.summa();\\n\\t\\tslog1.showSum();\\n\\t\\tTask<?> slog2 = new Task<>(1.7);\\n\\t\\tslog2.summa();\\n\\t\\tslog2.showSum();\\n\\t\\tTask<?> slog3 = new Task<>(5.3f);\\n\\t\\tslog3.summa();\\n\\t\\tslog3.showSum();\\n\\t}\\n}\\n",
4979 "The program displays messages about names of the Class numbers and numbers.\\n\\nOutput:\\n\\njava.lang.Integer 15.0\\njava.lang.Double 1.7\\njava.lang.Float 5.300000190734863\\n",
4980 "java.lang.Integer 15.0\\njava.lang.Double 1.7\\njava.lang.Float 5.300000190734863\\n",
4981 "1",
4982 "3",
4983 "1"
4984 ]
4985 },
4986 {
4987 "-name": "question339",
4988 "item": [
4989 "339",
4990 "68",
4991 "public class Task <T extends Number> {\\n\\tT[] objectNum;\\n\\n\\tTask(T[] ob) {\\n\\t\\tobjectNum = ob;\\n\\t}\\n\\n\\tpublic double summa() {\\n\\t\\tdouble s = 0;\\n\\t\\tdouble count = 0;\\n\\t\\tfor (T a : objectNum) {\\n\\t\\t\\ts = s + a.doubleValue();\\n\\t\\t\\tcount++;\\n\\t\\t}\\n\\t\\treturn s / count;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tInteger massiveI[] = { 54, 8, 65, 2, -54 };\\n\\t\\tDouble massiveD[] = { 4.5, 5.9, 8.0, 3.1, -16.2 };\\n\\t\\tTask<?> slog1 = new Task<>(massiveI);\\n\\t\\tSystem.out.println(\"The average number of the array is \" + slog1.summa());\\n\\t\\tTask<Double> slog2 = new Task<>(massiveD);\\n\\t\\tSystem.out.println(\"The average number of the array is \" + slog2.summa());\\n\\t}\\n}\\n",
4992 "The program displays the average of numbers in two arrays.\\n\\nOutput:\\n\\nThe average number of the array is 15.0\\nThe average number of the array is 1.06\\n",
4993 "The average number of the array is 15.0\\nThe average number of the array is 1.06\\n",
4994 "1",
4995 "3",
4996 "1"
4997 ]
4998 },
4999 {
5000 "-name": "question340",
5001 "item": [
5002 "340",
5003 "68",
5004 "public class Main <T extends Car, E extends Number> {\\n\\tT ob1;\\n\\tE ob2;\\n\\n\\tMain(T o1, E o2) {\\n\\t\\tob1 = o1;\\n\\t\\tob2 = o2;\\n\\t}\\n\\n\\tpublic void distance() {\\n\\t\\tif (ob2.doubleValue() < (ob1.fuel / ob1.capacity * 100)) {\\n\\t\\t\\tSystem.out.println(\"The car will pass these \" + ob2 + \" km.\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"The car does not have enough fuel to \" + ob2 + \" km.\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Sportage\", 60, 7);\\n\\t\\tMain<?, ?> main1 = new Main<>(car1, 600);\\n\\t\\tmain1.distance();\\n\\t\\tMain<?, ?> main2 = new Main<>(car1, 700);\\n\\t\\tmain2.distance();\\n\\t\\tKIA car2 = new KIA(\"Elantra\", 50, 8);\\n\\t\\tMain<?, ?> main3 = new Main<>(car2, 700);\\n\\t\\tmain3.distance();\\n\\t}\\n}\\n",
5005 "public class Car {\\n\\tString name;\\n\\tint fuel;\\n\\tint capacity;\\n\\n\\tCar(String name, int fuel, int capacity) {\\n\\t\\tthis.fuel = fuel;\\n\\t\\tthis.name = name;\\n\\t\\tthis.capacity = capacity;\\n\\t}\\n}\\n",
5006 "public class KIA extends Car {\\n\\tKIA(String name, int fuel, int capacity) {\\n\\t\\tsuper(name, fuel, capacity);\\n\\t}\\n}\\n",
5007 "The program reports whether the car will pass a given distance, taking into account the capacity of the fuel tank and fuel consumption.\\n\\nOutput:\\n\\nThe car will pass these 600 km.\\nThe car will pass these 600 km.\\nThe car does not have enough fuel to 700 km.\\n",
5008 "The car will pass these 600 km.\\nThe car will pass these 600 km.\\nThe car does not have enough fuel to 700 km.\\n",
5009 "1",
5010 "3",
5011 "1"
5012 ]
5013 },
5014 {
5015 "-name": "question341",
5016 "item": [
5017 "341",
5018 "69",
5019 "public class Area {\\n\\tstatic public <T, E> String equalClass(T ob1, E ob2) {\\n\\t\\tString area;\\n\\t\\tif (ob1.getClass().getName().equals(ob2.getClass().getName())) {\\n\\t\\t\\tarea = \"Classes of objects are equal\";\\n\\t\\t} else {\\n\\t\\t\\tarea = \"Classes of objects are not equal\";\\n\\t\\t}\\n\\t\\treturn area;\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(5);\\n\\t\\tRect rectangle1 = new Rect(12, 7);\\n\\t\\tCirc circle2 = new Circ(4);\\n\\t\\tRect rectangle2 = new Rect(11, 8);\\n\\n\\t\\tSystem.out.println(Area.equalClass(circle1, circle2));\\n\\t\\tSystem.out.println(Area.equalClass(circle1, rectangle1));\\n\\t\\tSystem.out.println(Area.equalClass(circle2, rectangle2));\\n\\t\\tSystem.out.println(Area.equalClass(rectangle1, rectangle2));\\n\\t}\\n}\\n",
5020 "public class Circ {\\n\\tString name = \"Circle\";\\n\\tint radius;\\n\\n\\tCirc(int radius) {\\n\\t\\tthis.radius = radius;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
5021 "public class Rect {\\n\\tString name = \"Rectangle\";\\n\\tint length;\\n\\tint width;\\n\\n\\tRect(int length, int width) {\\n\\t\\tthis.length = length;\\n\\t\\tthis.width = width;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = length * width;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
5022 "The program compares classes of objects.\\n\\nOutput:\\n\\nClasses of objects are equal\\nClasses of objects are not equal\\nClasses of objects are not equal\\nClasses of objects are equal\\n",
5023 "Classes of objects are equal\\nClasses of objects are not equal\\nClasses of objects are not equal\\nClasses of objects are equal\\n",
5024 "1",
5025 "3",
5026 "1"
5027 ]
5028 },
5029 {
5030 "-name": "question342",
5031 "item": [
5032 "342",
5033 "69",
5034 "public class Area {\\n\\tString name;\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = 0;\\n\\t\\treturn area;\\n\\t}\\n\\n\\tstatic public <T extends Area> void equalClass(T ob1, T ob2) {\\n\\t\\tif (ob1.getSquare() < ob2.getSquare()) {\\n\\t\\t\\tSystem.out.println(ob1.name + \" < \" + ob2.name);\\n\\t\\t} else if (ob1.getSquare() == ob2.getSquare()) {\\n\\t\\t\\tSystem.out.println(ob1.name + \" = \" + ob2.name);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(ob1.name + \" > \" + ob2.name);\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCirc circle1 = new Circ(6, \"circle1\");\\n\\t\\tRect rectangle1 = new Rect(12, 7, \"rectangle1\");\\n\\t\\tCirc circle2 = new Circ(6, \"circle2\");\\n\\t\\tRect rectangle2 = new Rect(11, 8, \"rectangle2\");\\n\\n\\t\\tArea.equalClass(circle1, circle2);\\n\\t\\tArea.equalClass(circle1, rectangle1);\\n\\t\\tArea.equalClass(circle2, rectangle2);\\n\\t\\tArea.equalClass(rectangle1, rectangle2);\\n\\t}\\n}\\n",
5035 "public class Circ extends Area{\\n\\tint radius;\\n\\n\\tCirc(int radius, String name) {\\n\\t\\tthis.radius = radius;\\n\\t\\tthis.name=name;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = radius * radius * Math.PI;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
5036 "public class Rect extends Area{\\n\\tint length;\\n\\tint width;\\n\\n\\tRect(int length, int width, String name) {\\n\\t\\tthis.length = length;\\n\\t\\tthis.width = width;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic double getSquare() {\\n\\t\\tdouble area = length * width;\\n\\t\\treturn area;\\n\\t}\\n}\\n",
5037 "The program compares figures by their areas.\\n\\nOutput:\\n\\ncircle1 = circle2\\ncircle1 > rectangle1\\ncircle2 > rectangle2\\nrectangle1 < rectangle2\\n",
5038 "circle1 = circle2\\ncircle1 > rectangle1\\ncircle2 > rectangle2\\nrectangle1 < rectangle2\\n",
5039 "1",
5040 "3",
5041 "1"
5042 ]
5043 },
5044 {
5045 "-name": "question343",
5046 "item": [
5047 "343",
5048 "69",
5049 "public class Task <T extends Number> {\\n\\tT[] objectNum;\\n\\n\\tTask(T[] ob) {\\n\\t\\tobjectNum = ob;\\n\\t}\\n\\n\\tpublic double summa() {\\n\\t\\tdouble s = 0;\\n\\t\\tfor (int i = 0; i < objectNum.length; i++)\\n\\t\\t\\tfor (T a : objectNum) {\\n\\t\\t\\t\\ts = s + a.doubleValue();\\n\\t\\t\\t}\\n\\t\\treturn s / objectNum.length;\\n\\t}\\n\\n\\tpublic void equelsAv(Task<?> ob3) {\\n\\t\\tif (this.summa() == ob3.summa()) {\\n\\t\\t\\tSystem.out.println(\"The average values are equal\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"The average values are not equal\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tInteger massiveI2[] = { 2, 3, 4 };\\n\\t\\tDouble massiveD2[] = { 2.0, 3.0, 4.0 };\\n\\t\\tTask<?> slog3 = new Task<>(massiveI2);\\n\\t\\tTask<Double> slog4 = new Task<>(massiveD2);\\n\\t\\tslog3.equelsAv(slog4);\\n\\t}\\n}\\n",
5050 "The program compares average values of different arrays.\\n\\nOutput:\\n\\nThe average values are equal\\n",
5051 "The average values are equal\\n",
5052 "1",
5053 "3",
5054 "1"
5055 ]
5056 },
5057 {
5058 "-name": "question344",
5059 "item": [
5060 "344",
5061 "69",
5062 "public class Main {\\n\\tpublic static <T extends Car, E extends Number> void distance(T ob1, E ob2) {\\n\\t\\tif (ob2.doubleValue() < (ob1.fuel / ob1.capacity * 100)) {\\n\\t\\t\\tSystem.out.println(\"The car will pass \" + ob2 + \" km.\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\"The car does not have enough petrol to \" + ob2 + \" km.\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"Sportage\", 60, 7.7);\\n\\t\\tMain.distance(car1, 600);\\n\\t\\tMain.distance(car1, 700);\\n\\t\\tKIA car2 = new KIA(\"Elantra\", 50, 7.3);\\n\\t\\tMain.distance(car2, 700);\\n\\t}\\n}\\n",
5063 "public class Car {\\n\\tString name;\\n\\tint fuel;\\n\\tdouble capacity;\\n\\n\\tCar(String name, int fuel, double capacity) {\\n\\t\\tthis.fuel = fuel;\\n\\t\\tthis.name = name;\\n\\t\\tthis.capacity = capacity;\\n\\t}\\n}\\n",
5064 "public class KIA extends Car {\\n\\tKIA(String name, int fuel, double capacity) {\\n\\t\\tsuper(name, fuel, capacity);\\n\\t}\\n}\\n",
5065 "The program informs whether the vehicle will pass a predetermined distance, taking into account the capacity of the fuel tank and the fuel consumption.\\n\\nOutput:\\n\\nThe car will pass 600 km.\\nThe car will pass 700 km.\\nThe car does not have enough petrol to 700 km.\\n",
5066 "The car will pass 600 km.\\nThe car will pass 700 km.\\nThe car does not have enough petrol to 700 km.\\n",
5067 "1",
5068 "3",
5069 "4"
5070 ]
5071 },
5072 {
5073 "-name": "question345",
5074 "item": [
5075 "345",
5076 "69",
5077 "public class Prod {\\n\\tString model;\\n\\tint cost;\\n\\n\\tProd(int cost, String n) {\\n\\t\\tthis.cost = cost;\\n\\t\\tmodel = n;\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Product \" + model + \" price \" + cost + \" $ \";\\n\\t\\treturn s;\\n\\t}\\n\\n\\tpublic <T extends Prod> void compareProd(T ob) {\\n\\t\\tif (cost < ob.cost) {\\n\\t\\t\\tSystem.out.println(model + \" is cheaper than \" + ob.model);\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(model + \" is more expensive than \" + ob.model);\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tProd prod1 = new Prod(3, \"Set of soldiers\");\\n\\t\\tTel prod2 = new Tel(15, \"Samsung-S300\");\\n\\t\\tCam prod3 = new Cam(13, \"LOGITECH-20\");\\n\\n\\t\\tprod1.compareProd(prod2);\\n\\t\\tSystem.out.println(prod1);\\n\\t\\tprod2.compareProd(prod3);\\n\\t\\tSystem.out.println(prod2);\\n\\t\\tprod3.compareProd(prod1);\\n\\t\\tSystem.out.println(prod3);\\n\\t}\\n}\\n",
5078 "public class Cam extends Prod {\\n\\n\\tCam(int cost, String n) {\\n\\t\\tsuper(cost, n);\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Сamera \" + model + \" price \" + cost + \" $ \";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
5079 "public class Tel extends Prod {\\n\\n\\tTel(int cost, String n) {\\n\\t\\tsuper(cost, n);\\n\\t}\\n\\n\\tpublic String toString() {\\n\\t\\tString s = \"Phone \" + model + \" price \" + cost + \" $ \";\\n\\t\\treturn s;\\n\\t}\\n}\\n",
5080 "The program compares prices of goods and prints price tags.\\n\\nOutput:\\n\\nSet of soldiers is cheaper than Samsung-S300\\nProduct Set of soldiers price 3 $ \\nSamsung-S300 is more expensive than LOGITECH-20\\nPhone Samsung-S300 price 15 $ \\nLOGITECH-20 is more expensive than Set of soldiers\\nСamera LOGITECH-20 price 13 $\\n",
5081 "Set of soldiers is cheaper than Samsung-S300\\nProduct Set of soldiers price 3 $ \\nSamsung-S300 is more expensive than LOGITECH-20\\nPhone Samsung-S300 price 15 $ \\nLOGITECH-20 is more expensive than Set of soldiers\\nСamera LOGITECH-20 price 13 $\\n",
5082 "1",
5083 "3",
5084 "85"
5085 ]
5086 },
5087 {
5088 "-name": "question346",
5089 "item": [
5090 "346",
5091 "70",
5092 "import java.util.ArrayList;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tCar car2 = new Car(\"AUDI\");\\n\\t\\tCar car3 = new Car(\"RENO\");\\n\\t\\tBMW bmw1 = new BMW(\"BMW 5x\", 10000);\\n\\t\\tBMW bmw2 = new BMW(\"BMW 4x\", 9000);\\n\\t\\tBMW bmw3 = new BMW(\"BMW 3x\", 8000);\\n\\t\\tArrayList<Car> carArray = new ArrayList<>();\\n\\t\\tcarArray.add(car2);\\n\\t\\tcarArray.add(car1);\\n\\t\\tcarArray.add(bmw2);\\n\\t\\tcarArray.add(car3);\\n\\t\\tArrayList<BMW> bmwArray = new ArrayList<>();\\n\\t\\tbmwArray.add(bmw3);\\n\\t\\tbmwArray.add(bmw1);\\n\\t\\tbmwArray.add(bmw2);\\n\\n\\t\\tMain.outArray1(carArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray1(bmwArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray2(bmwArray);\\n\\t}\\n\\n\\tstatic public void outArray1(ArrayList<? extends Car> carAr) {\\n\\t\\tfor (Car c : carAr) {\\n\\t\\t\\tSystem.out.println(c.name);\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public void outArray2(ArrayList<BMW> carA) {\\n\\t\\tfor (BMW c : carA) {\\n\\t\\t\\tSystem.out.println(c.name + \" \" + c.cost + \" $\");\\n\\t\\t}\\n\\t}\\n}\\n",
5093 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
5094 "public class BMW extends Car {\\n\\tint cost;\\n\\n\\tBMW(String name, int cost) {\\n\\t\\tsuper(name);\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n",
5095 "The program displays a list of cars. Then, the program displays a list of vehicles consisting of only car brand BMW. Then, the program displays a list of cars BMW. \\n\\nOutput:\\n\\nAUDI\\nKIA\\nBMW 4x\\nRENO\\n\\nBMW 3x\\nBMW 5x\\nBMW 4x\\n\\nBMW 3x 8000 $\\nBMW 5x 10000 $\\nBMW 4x 9000 $\\n",
5096 "AUDI\\nKIA\\nBMW 4x\\nRENO\\n\\nBMW 3x\\nBMW 5x\\nBMW 4x\\n\\nBMW 3x 8000 $\\nBMW 5x 10000 $\\nBMW 4x 9000 $\\n",
5097 "1",
5098 "3",
5099 "108"
5100 ]
5101 },
5102 {
5103 "-name": "question347",
5104 "item": [
5105 "347",
5106 "70",
5107 "import java.util.ArrayList;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tCar car1 = new Car(\"KIA\");\\n\\t\\tCar car2 = new Car(\"AUDI\");\\n\\t\\tBMW bmw1 = new BMW(\"BMW 5x\", 10000);\\n\\t\\tBMW bmw2 = new BMW(\"BMW 4x\", 9000);\\n\\t\\tArrayList<Car> carArray = new ArrayList<>();\\n\\t\\tcarArray.add(car2);\\n\\t\\tcarArray.add(car1);\\n\\t\\tcarArray.add(bmw2);\\n\\t\\tArrayList<BMW> bmwArray = new ArrayList<>();\\n\\t\\tbmwArray.add(bmw1);\\n\\t\\tbmwArray.add(bmw2);\\n\\n\\t\\tMain.outArray1(carArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray1(bmwArray);\\n\\t\\tSystem.out.println();\\n\\t\\tMain.outArray2(bmwArray);\\n\\t}\\n\\n\\tstatic public <T extends Car> void outArray1(ArrayList<T> carAr) {\\n\\t\\tfor (T c : carAr) {\\n\\t\\t\\tSystem.out.println(c.name);\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public <T extends BMW> void outArray2(ArrayList<T> carA) {\\n\\t\\tfor (T c : carA) {\\n\\t\\t\\tSystem.out.println(c.name + \" \" + c.cost + \" $\");\\n\\t\\t}\\n\\t}\\n}\\n",
5108 "public class Car {\\n\\tString name;\\n\\n\\tCar(String name) {\\n\\t\\tthis.name = name;\\n\\t}\\n}\\n",
5109 "public class BMW extends Car {\\n\\tint cost;\\n\\n\\tBMW(String name, int cost) {\\n\\t\\tsuper(name);\\n\\t\\tthis.cost = cost;\\n\\t}\\n}\\n",
5110 "The program displays a list of cars. Then, the program displays a list of vehicles consisting of only car brand BMW. Then, the program displays a list of cars BMW. \\n\\nOutput:\\n\\nAUDI\\nKIA\\nBMW 4x\\n\\nBMW 5x\\nBMW 4x\\n\\nBMW 5x 10000 рублей\\nBMW 4x 9000 рублей\\n",
5111 "AUDI\\nKIA\\nBMW 4x\\n\\nBMW 5x\\nBMW 4x\\n\\nBMW 5x 10000 $\\nBMW 4x 9000 $\\n",
5112 "1",
5113 "3",
5114 "81"
5115 ]
5116 },
5117 {
5118 "-name": "question348",
5119 "item": [
5120 "348",
5121 "70",
5122 "import java.util.ArrayList;\\n\\npublic class Unit {\\n\\tString name;\\n\\tint strength;\\n\\n\\tUnit(int strength, String name) {\\n\\t\\tthis.strength = strength;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void fight(Unit enemy) {\\n\\t\\tSystem.out.print(name + \" is fighting, his enemy is \" + enemy.name + \". \");\\n\\t}\\n\\n\\tpublic <T extends Unit> void outArray1(ArrayList<T> unitAr) {\\n\\t\\tfor (T Ñ : unitAr) {\\n\\t\\t\\tfight(Ñ);\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public <T extends Unit> void allArray(ArrayList<T> allU) {\\n\\t\\tfor (T Ñ : allU) {\\n\\t\\t\\tSystem.out.print(Ñ.getClass().getName() + \" \" + Ñ.name + \". \");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc unit1 = new Orc(100, \"Zozo\");\\n\\t\\tOrc unit2 = new Orc(100, \"Korch\");\\n\\t\\tElf unit3 = new Elf(100, \"Ebin\");\\n\\t\\tElf unit4 = new Elf(100, \"Fienor\");\\n\\t\\tArrayList<Elf> red = new ArrayList<>();\\n\\t\\tred.add(unit3);\\n\\t\\tred.add(unit4);\\n\\t\\tArrayList<Orc> blue = new ArrayList<>();\\n\\t\\tblue.add(unit1);\\n\\t\\tblue.add(unit2);\\n\\t\\tArrayList<Unit> all = new ArrayList<>();\\n\\t\\tall.addAll(red);\\n\\t\\tall.addAll(blue);\\n\\n\\t\\tunit3.outArray1(blue);\\n\\t\\tSystem.out.println();\\n\\t\\tunit4.outArray1(blue);\\n\\t\\tSystem.out.println();\\n\\t\\tUnit.allArray(all);\\n\\t}\\n}\\n",
5123 "public class Elf extends Unit {\\n\\tElf(int strength, String name) {\\n\\t\\tsuper(strength, name);\\n\\t}\\n}\\n",
5124 "public class Orc extends Unit {\\n\\tOrc(int strength, String name) {\\n\\t\\tsuper(strength, name);\\n\\t}\\n}\\n",
5125 "The program displays a list of enemies, who are fighting with some elves, and then displays a list of all soldiers.\\n\\nOutput:\\n\\nEbin is fighting, his enemy is Zozo. Ebin is fighting, his enemy is Korch.\\nFienor is fighting, his enemy is Zozo. Fienor is fighting, his enemy is Korch.\\nElf Ebin. Elf Fienor. Orc Zozo. Orc Korch.\\n",
5126 "Ebin is fighting, his enemy is Zozo. Ebin is fighting, his enemy is Korch.\\nFienor is fighting, his enemy is Zozo. Fienor is fighting, his enemy is Korch.\\nElf Ebin. Elf Fienor. Orc Zozo. Orc Korch.\\n",
5127 "1",
5128 "3",
5129 "100"
5130 ]
5131 },
5132 {
5133 "-name": "question349",
5134 "item": [
5135 "349",
5136 "70",
5137 "import java.util.ArrayList;\\n\\npublic class Unit {\\n\\tString name;\\n\\tint strength;\\n\\n\\tUnit(int strenght, String name) {\\n\\t\\tthis.strength = strength;\\n\\t\\tthis.name = name;\\n\\t}\\n\\n\\tpublic void fight(Unit enemy) {\\n\\t\\tSystem.out.print(name + \" is fighting, his enemy is \" + enemy.name + \". \");\\n\\t}\\n\\n\\tpublic void outArray1(ArrayList<? extends Unit> unitAr) {\\n\\t\\tfor (Unit Ñ : unitAr) {\\n\\t\\t\\tfight(Ñ);\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public void allArray(ArrayList<? extends Unit> allU) {\\n\\t\\tfor (Unit Ñ : allU) {\\n\\t\\t\\tSystem.out.print(c.getClass().getName() + \" \" + Ñ.name + \". \");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\t\\tOrc unit1 = new Orc(100, \"Zozo\");\\n\\t\\tOrc unit2 = new Orc(100, \"Korch\");\\n\\t\\tElf unit3 = new Elf(100, \"Ebin\");\\n\\t\\tElf unit4 = new Elf(100, \"Fienor\");\\n\\t\\tArrayList<Elf> red = new ArrayList<>();\\n\\t\\tred.add(unit3);\\n\\t\\tred.add(unit4);\\n\\t\\tArrayList<Orc> blue = new ArrayList<>();\\n\\t\\tblue.add(unit1);\\n\\t\\tblue.add(unit2);\\n\\t\\tArrayList<Unit> all = new ArrayList<>();\\n\\t\\tall.addAll(red);\\n\\t\\tall.addAll(blue);\\n\\n\\t\\tunit3.outArray1(blue);\\n\\t\\tSystem.out.println();\\n\\t\\tunit4.outArray1(blue);\\n\\t\\tSystem.out.println();\\n\\t\\tUnit.allArray(all);\\n\\t}\\n}\\n",
5138 "public class Elf extends Unit {\\n\\tElf(int strength, String name) {\\n\\t\\tsuper(strength, name);\\n\\t}\\n}\\n",
5139 "public class Orc extends Unit {\\n\\tOrc(int strength, String name) {\\n\\t\\tsuper(strength, name);\\n\\t}\\n}\\n",
5140 "The program displays a list of enemies, who are fighting with some elves, and then displays a list of all soldiers.\\n\\nOutput:\\n\\nEbin is fighting, his enemy is Zozo. Ebin is fighting, his enemy is Korch.\\nFienor is fighting, his enemy is Zozo. Fienor is fighting, his enemy is Korch.\\nElf Ebin. Elf Fienor. Orc Zozo. Orc Korch.\\n",
5141 "Ebin is fighting, his enemy is Zozo. Ebin is fighting, his enemy is Korch.\\nFienor is fighting, his enemy is Zozo. Fienor is fighting, his enemy is Korch.\\nElf Ebin. Elf Fienor. Orc Zozo. Orc Korch.",
5142 "1",
5143 "3",
5144 "100"
5145 ]
5146 },
5147 {
5148 "-name": "question350",
5149 "item": [
5150 "350",
5151 "70",
5152 "import java.util.ArrayList;\\n\\npublic class Prod {\\n\\tString name;\\n\\tint cost;\\n\\n\\tProd(String name, int cost) {\\n\\t\\tthis.name = name;\\n\\t\\tthis.cost = cost;\\n\\t}\\n\\n\\tstatic public void printListOfProd(ArrayList<? extends Prod> arrProd) {\\n\\t\\tfor (Prod p : arrProd) {\\n\\t\\t\\tSystem.out.println(p.name + \" \" + p.cost + \" $\");\\n\\t\\t}\\n\\t}\\n\\n\\tstatic public <T extends Tel> void printListOfTel(ArrayList<T> arrTel) {\\n\\t\\tfor (T p : arrTel) {\\n\\t\\t\\tSystem.out.println(p.name + \" memory \" + p.memory + \" price \"\\n\\t\\t\\t\\t\\t+ p.cost + \" $\");\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tCam prod1 = new Cam(\"Logitech B300\", 25, 5);\\n\\t\\tCam prod2 = new Cam(\"Philips 25S\", 15, 4);\\n\\t\\tTel prod3 = new Tel(\"Samsung 30-Blue\", 75, 3);\\n\\t\\tTel prod4 = new Tel(\"Sony 54ff\", 63, 2);\\n\\t\\tArrayList<Cam> camList = new ArrayList<>();\\n\\t\\tcamList.add(prod1);\\n\\t\\tcamList.add(prod2);\\n\\t\\tArrayList<Tel> telList = new ArrayList<>();\\n\\t\\ttelList.add(prod3);\\n\\t\\ttelList.add(prod4);\\n\\t\\tArrayList<Prod> productList = new ArrayList<>();\\n\\t\\tproductList.addAll(camList);\\n\\t\\tproductList.addAll(telList);\\n\\t\\tProd.printListOfProd(productList);\\n\\t\\tSystem.out.println();\\n\\t\\tProd.printListOfProd(camList);\\n\\t\\tSystem.out.println();\\n\\t\\tProd.printListOfTel(telList);\\n\\t}\\n}\\n",
5153 "public class Cam extends Prod {\\n\\tint pixel;\\n\\n\\tCam(String name, int cost, int pixel) {\\n\\t\\tsuper(name, cost);\\n\\t\\tthis.pixel = pixel;\\n\\t}\\n}\\n",
5154 "public class Tel extends Prod {\\n\\tint memory;\\n\\n\\tTel(String name, int cost, int memory) {\\n\\t\\tsuper(name, cost);\\n\\t\\tthis.memory = memory;\\n\\t}\\n}\\n",
5155 "The program displays a list of all products. The program then displays a list of products containing only cameras. The program then displays a list of cameras.\\n\\nOutput:\\n\\nLogitech B300 25 $\\nPhilips 25S 15 $\\nSamsung 30-Blue 75 $\\nSony 54ff 63 $\\n\\nLogitech B300 25 $\\nPhilips 25S 15 $\\n\\nSamsung 30-Blue memory 3 price 75 $\\nSony 54ff memory 2 price 63 $\\n",
5156 "Logitech B300 25 $\\nPhilips 25S 15 $\\nSamsung 30-Blue 75 $\\nSony 54ff 63 $\\n\\nLogitech B300 25 $\\nPhilips 25S 15 $\\n\\nSamsung 30-Blue memory 3 price 75 $\\nSony 54ff memory 2 price 63 $\\n",
5157 "1",
5158 "3",
5159 "57"
5160 ]
5161 },
5162 {
5163 "-name": "color_list_settings",
5164 "item": [
5165 "Eclipse original - blue",
5166 "Eclipse green",
5167 "Eclipse yellow"
5168 ]
5169 },
5170 {
5171 "-name": "text_sixe_list_settings",
5172 "item": [
5173 "1",
5174 "2",
5175 "3",
5176 "4",
5177 "5",
5178 "6",
5179 "7",
5180 "8",
5181 "9",
5182 "10"
5183 ]
5184 }
5185 ]
5186 }
5187}