IN C++ PLEASE
Write a class LuckyNumberChecker.
Include a constructor that accepts an integer named luckyDivisor
Add a virtual method named checkNumber that accept an integer named number and returns a string
If the number argument is evenly divisible by the luckyDivisor, return "This number is lucky"
otherwise, if the number is odd, return "This number might be lucky"
otherwise, return "this number is not lucky"
Write a class DoublyLuckyNumberChekcer that extends LuckyNumberChecker
Add a constructor that accepts two integers, luckyDivisor and superLuckyDivisor. Pass luckyDivisor to the LuckyNumberChecker constructor.
Override the checkNumber method to return "This number is super lucky" if it is evenly divisible by the superLuckyDivisor, otherwise return the same values as LuckyNumberChecker would have.
Write unit tests
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
class LuckyNumberChecker{
private:
int luckyDivisor;
public:
//Constructor
LuckyNumberChecker(int _luckyDivisor) : luckyDivisor(_luckyDivisor){}
virtual string checkNumber(int num){
if(num % luckyDivisor == 0)
return "This number is lucky";
else if(num % 2 == 1)
return "This number might be lucky";
else
return "This number is not lucky";
}
};
class DoublyLuckyNumber : public LuckyNumberChecker{
private:
int superLuckyDivisor;
public:
DoublyLuckyNumber(int _luckyDivisor, int _superLuckyDivisor) : LuckyNumberChecker(_luckyDivisor),
superLuckyDivisor(_superLuckyDivisor){}
string checkNumber(int num) override {
if(num % superLuckyDivisor == 0)
return "This number is super lucky";
else
return LuckyNumberChecker::checkNumber(num);
}
};
int main(){
DoublyLuckyNumber c1(5, 7);
/*Unit tests*/
//Test for super lucky number
assert(c1.checkNumber(21) == "This number is super lucky");
//Test for if condition
assert(c1.checkNumber(10) == "This number is lucky");
//Test for else-if condition
assert(c1.checkNumber(9) == "This number might be lucky");
//Test for else condition
assert(c1.checkNumber(6) == "This number is not lucky");
cout << "All test passed!";
return 0;
}
OUTPUT:
IN C++ PLEASE Write a class LuckyNumberChecker. Include a constructor that accepts an integer named luckyDivisor...
Java Programming Write a method named isEven that accepts an integer argument. The method should return true if the argument is even, or false if not. The program’s main method should use a loop to generate a random integer. The number of random integers is provided by a user, who must enter a number greater than 10. The loop should then invoke the isEven method to determine whether each integer is even or odd, display the random number and the...
Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for the month (1 = January, 2 February, etc). l An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if...
in java
Define a class named ComparableNames thats extends Person and
implements comparable
Define a class named ComparableNames that extends Person (defined below) and implements Comparable. Override the compare To method to compare the person on the basis of name. Write a test class to find the order of two ComparableNames. class Person String name; Person00 Person(String n) name=n: Hint: in class ComparableName, you only need a constructor with arg to initialize the data filed defined in the super class...
Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
Task 1: 1. Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of type T. Write the class constructor to create the ArrayList. 2. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, add it to the ArrayList. 3. Write a public method...
Write a class named DartSector. The constructor should accept a sector number and position {Single, Double, Treble, Outer & Inner} represented with the integers 1 – 5 respectively. The class should have 3 methods: • getSectorColor – method should return the pocket’s color (as a String) • singleThrow – method should generate 2 random numbers; one in the range (1..20) and another (1..5); and return the score for the throw. • throwThree – method should generate 3 sets of random...
Write a class named TestScores. The class constructor should accept an array test scores as its argument. The class should a method that returns the average of the test scores. If any test score is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate this with an array of five items. This is JAVA program.
WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...