The tasks have to be done strictly
individually.
You are not allowed to discuss the problems with anybody.
The first problem must be completed in class today.
Solutions to the other two problems must be submitted before 11:59pm
of the day above.
For example, if n = 12, then it can be represented as the sum 3 + 9 with both 3 and 9 being powers of 3, so your program must output 12 = 3 + 9. Also, if n = 10 is given, your program must output 10 = 1 + 9 (here 1 = 30). Your code must work for any given n, not just for the above examples.
Implement the following method boolean isPowerOf3(int m) in your code to check if a given number m is a power of 3. If this is the case, the return value is true and false otherwise. Within this method divide the number several times by 3 till the quotient reaches 1 and check the remainder. The remainder must be zero in all steps.
For example: if n = 27 then
Another example: if n = 18 then
Your project class has to have 2 methods: main() (that takes the user input and prints the result) and isPowerOf3() to be called from main().
Name the project Ex1_1
Solution
a·x + b·y = c d·x + e·y = f |
where a,b,c,d,e,f are given integer numbers and x,y are unknowns (real numbers). The solutions to this system are given by the following formulas:
x = (c·e - b·f) / (a·e - b·d) y = (a·f - c·d) / (a·e - b·d) |
Your design has to have two classes: Ex1_2 and LinearSystem. The class LinearSystem should have a constructor accepting 6 parameters corresponding to the coefficients of the linear system. It has to have two public methods computeX() and computeY() for computing x and y, respectively. It also has to have a method isUnique() returning true or false depending on whether a unique solution exists (i.e., the denominators of the above formulas are non-zero). The coefficients of the system should be private instance variables.
The class Ex1_2 must ask the user to enter 6 real numbers a,b,c,d,e,f from the keyboard, check whether a unique solution exists and if it does, output x and y. If solution is not unique (that is, if a=k·d, b=k·e, and c=k·f for some non-zero k), one of solutions must be output. Otherwise, if no solution exists, the corresponding message must be printed.
Name the project Ex1_2
Solution
00011 00101 00110 01001 01010 01100 10001 10010 10100 11000
10 extra points for recursive implementation of method printSequences()
Name the project Ex1_3
Solution