Professional Documents
Culture Documents
M Solution
PART A
b). (a*Math.pow(x,3)) + 5
c). ((3*x)+1)/(x+8)
PART B
N
23456
a 23456%10 = 6
b 23456/10 = 2345%10 = 5
c
23456/100 = 234%10 = 4
d
23456/1000 = 23%10 = 3
e
23456/10000 = 2
sum
6+5+4+3+2 = 20
/****************************************************************
* Filename: GravitationalForce.java
* @author Tallman Nkgau
* @version 1.0
* Lab Exercises: 3
*
* Program to read the masses of two bodies, the distance between them and display the gravitational
force between
* them.
* Compile: javac GravitationalForce.java
* Execute: java GravitationalForce
*/
import java.util.Scanner; // For keyboard input
/****************************************************************
* Filename: Investment.java
* @author Tallman Nkgau
* @version 1.0
* Lab Exercises: 3
*
* Program displays the value of your investment for the first five years
* Compile: javac Investment.java
* Execute: java Investment
*/
import java.util.Scanner;
public class Investment
{
public static void main (String[] args)
{
Scanner kBoard = new Scanner(System.in);
System.out.print("Please enter investment in pulas: ");
double P = kBoard.nextDouble(); //reading pulas from the keyboard
System.out.print("Please enter the interest rate: ");
double r = kBoard.nextDouble(); //reading percent interest from the keyboard
double firstYear = P*Math.pow((1 + r/100),1);
double secondYear = P*Math.pow((1 + r/100),2);
double thirdYear = P*Math.pow((1 + r/100),3);
double fourthYear = P*Math.pow((1 + r/100),4);
double fifthYear = P*Math.pow((1 + r/100),5);
System.out.printf("Investment: P%1.2f\n",P);
System.out.printf("Interest rate: %1.2f%1s\n",r,"%");
System.out.println("N(years) Total");
System.out.printf("1 %24.2f\n",firstYear);
System.out.printf("2 %24.2f\n",secondYear);
System.out.printf("3 %24.2f\n",thirdYear);
System.out.printf("4 %24.2f\n",fourthYear);
System.out.printf("5 %24.2f\n",fifthYear);
}
}