import java.util.Objects;
public class ChildClass extends ParentClass {
private int childI;
private char childC;
public ChildClass(int parentI, char parentC, int childI, char childC) {
super(parentI, parentC);
this.childI = childI;
this.childC = childC;
}
public int getChildI() {
return childI;
}
public void setChildI(int childI) {
this.childI = childI;
}
public char getChildC() {
return childC;
}
public void setChildC(char childC) {
this.childC = childC;
}
public String toString() {
return super.toString() + " & ChildClass [" +"childI=" + childI + ", childC=" + childC + "]";
}
public int hashCode() {
return Objects.hash(childC, childI);
}
public boolean equals(ChildClass otherChild)
{
if(super.equals(otherChild) && childI == otherChild.childI && childC == otherChild.childC)
return true;
return false;
}
public static void main(String[] args) {
CodeTester.testCode(args);
ChildClass c = new ChildClass(11, 'b', 22, 'a');
System.out.println(c);
}
}
Prompt the user for the purchase
b. Write a void function called display() to print the following headings:
The month number
The starting balance
The interest to pay
The principal to pay
The monthly payment
The ending balance for that month
c. Create a double function called creditcredit() that has the purchase price as its parameter.
The function must do the following (d to j):
d. Create two variables
annual interest rate = 12%
monthly rate = annual interest rate/12
e. The month number should begin with 1
f. Use a loop to display information for 12 months
g. Monthly payment is calculated at 5% of the purchase
h. The amount of interest for a month is calculated as the purchase price * month rate
i. The amount of principal for a month is equal to the monthly payment minus the interest owed.
j. The ending balance remaining after monthly payment is calculated as the starting balance
– the monthly payment.
k. Call the display function
public void add(int element) {
}
is the method
and the junit test is:
void testAddInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(3);
arr1.add(4);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(3);
lst1.add(4);
assertEquals(arr1.get(0), lst1.get(0));
assertEquals(arr1.get(1), lst1.get(1));
assertEquals(arr1.get(2), lst1.get(2));
i get the instance variable and constructor but it seems like as you can see above the junit test is creating its over arraylists which i can't find out how to manipulate
Hi good morning, I would like to have some feedback about this https://github.com/SaptakBhoumik/WebPlus
Is there something that can be done better?
thanks
We saw one method of creating a list of prime numbers by checking if the number in question could be divided by any number bigger than 1, but less than the number itself. If it could, then we printed it out and moved on. This method of prime number creation means that we divide with numbers that are themselves not prime. For example, when we checked if 7 is prime, we divided it by 2, then 3, then 4, then 5, then 6. We will have already seen that 4 and 6 are not prime though.
Another algorithm exists called the sieve of Eratosthenes, that comes from ancient Greece. It is modestly quicker than our standard algorithm*
In this algorithm you create a list of numbers from 1 up to your goal. Starting at 2 eliminate its multiples in the list and move to the next number that is still in the list. When you reach the end of the list, all the numbers must be prime.
For example, if I wished to check for all the primes below 10, my first list would be [1,2,3,4,5,6,7,8,9,10]. Starting at 2, I would cross off 4, 6, 8, and 10. The next remaining number is 3, I would cross off 9, remembering that 6 was already eliminated. The next number in the list is 5. No multiples of 5 are in the list since 10 was already eliminated. Finally we reach 7 and there are no multiples of 7 in the list, so you have reached the answer of [1,2,3,5,7].
Another way of looking at it, published on Wikipedia is shown here (Links to an external site.).
Create a program that asks the user for an integer greater than or equal to 100. Generate a list of primes up to and including this number. Print the list to the screen on a single line. You may assume that the user will enter valid numeric input in the correct range.
Hint: this algorithm requires you to pay close attention to your array index ranges when building your loops. You will not be going from the start to the end of both loops every time. Use your planning techniques or try doing it it on paper a couple of times to get the hang of it. If done correctly using functions like len() you will not need to do any special techniques to manage the list size potentially changing every iteration.
To help you check if your answer is correct, here is a list adapted version of our old algorithm that can return something for you to check against.
def makeprimes( upper ):
count = 2
primes = [1]
while count <= upper:
prime = True
for i in range(2, count):
if count % i == 0:
prime = False
break
if prime:
primes.append(count)
count = count + 1
return primes