In this code note, we will explore the sample answers to the seven methods implementation task from codquiz project. Make sure to watch and try out the code for each of the challenges.
packagechallenges.warmup;importstayaway.verify.WarmUpPart2Tests;importstayaway.verify.WarmUpTests;importjava.io.FileOutputStream;importjava.io.PrintStream;publicclassReturnSomethingPart2{// Run main method to verify your// challenge method implementationspublicstaticvoidmain(String[]args){WarmUpPart2Testsrun=newWarmUpPart2Tests();run.isEqualNumber();run.calculateAge();run.lessThanHundred();run.covertAgeToDays();run.isItTen();run.divisibleBy5();run.nextOf();}/** * INSTRUCTIONS: * ------------- * Modify this method so that given the two numbers, return [true] if they are equal, * return [false] boolean value if they are not equal. * * EXAMPLE: * isEqualNumber(3, 4) -> false * isEqualNumber(5, 5) -> true * isEqualNumber(12, 22) -> false * * RULES: * > Do not use sout inside this method */publicbooleanisEqualNumber(intfirst,intsecond){if(first==second)returntrue;elsereturnfalse;}/** * INSTRUCTIONS: * ------------- * Modify this method so that given the user's birth year, * return their current age. * * EXAMPLE: * calculateAge(1990) -> 32 * calculateAge(2000) -> 22 * calculateAge(1967) -> 55 * * RULES: * > Do not use sout inside this method * > birthYear cannot bigger than 2022 */publicintcalculateAge(intbirthYear){intcurrentYear=2022;intcurrentAge=currentYear-birthYear;returncurrentAge;}/** * INSTRUCTIONS: * ------------- * Modify this method so that given two numbers, return [true] if the sum of both * numbers is less than 100. Otherwise, return [false]. * * EXAMPLE: * lessThanHundred(22, 15) -> false * lessThanHundred(83, 34) -> false * lessThanHundred(3, 77) -> true * * RULES: * > Do not use sout inside this method */publicbooleanlessThanHundred(intfirst,intsecond){intsum=first+second;if(sum<100)returntrue;elsereturnfalse;}/** * INSTRUCTIONS: * ------------- * Modify this method so that given the user's age in years, it * calculates and returns the age in days. * * EXAMPLE: * covertAgeToDays(65) -> 23725 * covertAgeToDays(0) -> 0 * covertAgeToDays(20) -> 7300 * * RULES: * > Do not use sout inside this method * > parameter age is guaranteed to be positive */publicintcovertAgeToDays(intage){intdaysInYear=365;inttotalDays=age*daysInYear;returntotalDays;}/** * INSTRUCTIONS: * ------------- * Modify this method so that given two integer, it returns if one * of them is 10 or if their sum is equal to 10. * * EXAMPLE: * isItTen(9,10) -> true * isItTen(8,8) -> false * isItTen(10,2) -> true * isItTen(5,5) -> true * * RULES: * > Do not use sout inside this method */publicbooleanisItTen(inta,intb){intsum=a+b;booleanweHaveTen=sum==10||a==10||b==10;if(weHaveTen)returntrue;elsereturnfalse;}/** * INSTRUCTIONS: * ------------- * Modify this method so that given a number, it returns [true] if * the given number is divisible by 5, otherwise this method returns [false] * * EXAMPLE: * -------- * divisibleBy5(-55) -> true * divisibleBy5( 15) -> true * divisibleBy5( 37) -> false * * RULES: * ------ * > Do not use sout inside this method * */publicbooleandivisibleBy5(intnumber){intresult=number%5;if(result==0){returntrue;}else{returnfalse;}}/** * INSTRUCTIONS: * ------------- * Modify this method so that given a number, it returns the next number. * * EXAMPLE: * -------- * nextOf(0) -> 1 * nextOf(9) -> 10 * nextOf(-3) -> -2 * * RULES: * ------ * > Do not use sout inside this method */publicintnextOf(intnumber){intnextNumber=++number;returnnextNumber;}}//end::class
Given an integer number number, return true if it is divisible by 5, otherwise return false to the user. Note that if number is divisible by another number, their modulus will return zero.