Write a Java method to compute the future investment value at a given interest rate for a
specified number of years.
Input the investment amount: 1000
Input the rate of interest: 10
Input number of years: 5
Years FutureValue
1 1104.71
2 1220.39
3 1348.18
4 1489.35
5 1645.31
When a subclass inherits from a superclass, it also inherits its methods; however, it can
also override the superclass methods (as well as declare and implement new ones). Consider the following Sports class:
class Sports{
String getName(){
return "Generic Sports";
}
void getNumberOfTeamMembers(){
System.out.println( "Each team has n players in " + getName() );
}
}
Next, we create a Soccer class that inherits from the Sports class. We can override the getName method and return a different, subclass-specific string:
class Soccer extends Sports{
@Override
String getName(){
return "Soccer Class";
}
}
Note: When overriding a method, you should precede it with the @Override annotation. The parameter(s) and return type of an overridden method must be exactly the same as those of the method inherited from the supertype.
Finish the Teacher constructor. Use super to use the Person constructor to set the fields
inherited from Person. It should print “Destini 20” followed by “Erica 55 Masters in Teaching”.
public class Person
{
private String name;
private int age;
public Person(String name, int age)
{
this.name = name;
this.age = age;
}
public String getName() { return this.name; }
public int getAge() { return this.age; }
public String toString()
{
return getName() + " " + getAge();
}
public static void main(String[] args)
{
Person p = new Person("Destini", 20);
System.out.println(p);
Teacher p2 = new Teacher("Erica", 55, "Masters in Teaching");
System.out.println(p2);
}
}
class Teacher extends Person
{
String degree;
public String getDegree() { return this.degree; }
public String toString()
{
return getName() + " " + getAge() + " " + getDegree();
}
public Teacher(String name, int age, String theDegree)
{
A Java interface can only contain method signatures and fields. The interface can be used
to achieve polymorphism. In this problem, you will practice your knowledge on interfaces.
You are given an interface AdvancedArithmetic which contains a method signature int divisor_sum(int n). You need to write a class called MyCalculator which implements the interface.
divisorSum method just takes an integer as input and return the sum of all its divisors. For example divisors of 6 are 1, 2, 3 and 6, so divisor_sum should return 12. The value of n will be at most 1000.
Write iterative and recursive functions that return value of
b
n
,
the nth power of
We Filipinos are quite known for the habit of leaving at least one of the many pieces of food on the plate as it can't be equally divided among all at most times. Just like when 3 people decide to eat a pizza of 10 slices, there will often be at least one slice left on the box. To accurately show just how many pieces of things are left when divided by a certain number, we code it using modulo.
Care to do it for me?
Write a Java program to ask the user for their login and their password (both must be integer numbers) and repeat it as many times as necessary, until the entered login is "10" and the password is "0123".
Write a program that check and classify buttons pressed on the keyboard.
After pressing any button, the program
should display one of labels: - lowercase letter
- capital letter
- digit
- ENTER
- ESC
- Left Arrow
- Right arrow
- F1 function key
- Another (unrecognised) key
HINT: to retrieve the keyboard key code, use function getch() from the library <conio.h>.
Write a program in Java to display the armstrong numbers formed by the combination of the factors of the first ten natural numbers using the method prototype: String num(int a)