|
Fun Number Assignments
The idea for this assignment(and many others!) came from Fran Trees of Drew University.
If you ever get a chance to take AP seminar with her, it's well worth it!
Create a new BlueJ class called FunNumber1 and paste the code below inside. Compile and run the class to see what it does. Your job is to
- 1) in the default constructor, you should set originalNumber to 15
- 2) create a 2nd constructor. Your 2nd overloaded constructor should take an int as a parameter and should originalNumber to the paramaters value
- 3) Make the sumInts() method work properly. sumInts() should return a sum of all numbers less than originalNum
- 4) Make all of the other methods in this class work!
FunNumber1 class (Code below image)
FunNumber1.java
public class FunNumber1
{
int originalNumber;
public FunNumber1() {; }
/**
* returns the value of this FunNumber
* @return value of this FunNumber
*/
public int getValue()
{
return originalNumber;
}
/**
* prints all of the factors of this FunNumber value
*/
public void printFactors()
{
// code goes here
}
/***
* determines the factorial of this FunNumber value
* @return this FunNumber value's factorial
*/
public int findFactorial()
{
// code goes here
return 1;
}
/** sums the integers that are less than or equal to this
* FunNumber value
* @return the sum of the integers <= this FunNumber value
*/
public int sumInts()
{
// code goes here
return 1;
}
public int sumOfMultiples(int upToWhatNum){
return 1;
}
}
Top
|