You are on page 1of 21

Name: Clemente, Danielle Rose Date: May 13, 202

CITE 003 / CS12S1 / M W F / 8:30am - 10:30am Professor: Mr. Alfio Regla

Laboratory Activity #8

Source Code (Screenshot):


Text-based Code:

package midtermactivities;

import java.util.Scanner;

public class ThreeMethodsOfCompoundInterest {

public static void main(String[] args) {

//Scanner object
Scanner input = new Scanner(System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|---------------COMPOUND INTEREST IN 10 YEARS---------------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+------------------------------+");
System.out.println("\t\t\s\sLET US COMPUTE IT FOR YOU.");
System.out.println("\t\t+------------------------------+\n");

//To declare and initiate number of program use by the user


int transactionNumber = 0;

//To declare what the data type the termination variable can accept
String toTerminateProg = "x";

//Outer loop as part of the instructions


do {
transactionNumber++;
System.out.printf("\n\t\s\sComputation %d\n", transactionNumber); //For easier tracking of number of calculation

System.out.printf("\n\t\s\sEnter back account balance: \u20B1"); //To get the account balance of user
double accountBalance = input.nextDouble();

System.out.printf("\n\t\s\sEnter rate (annual) %%: "); //To get the interest rate from user
double interestRate = input.nextDouble();

double compoundDaily = accountBalance;


double rateForDaily = (interestRate/100)/365; //To compute for rate when daily

double compoundMonthly = accountBalance;


double rateForMonthly = (interestRate/100)/12; //To compute for rate when monthly

double compoundYearly = accountBalance;


double rateForYearly = interestRate/100; //To compute for rate when monthly

//For subtitle and partition purposes


System.out.println("\t\s__________________________________________________________\n");
System.out.println("\t\t+------------------------------+");
System.out.printf("\t\t\s\s\s\s\sACCOUNT IN TEN YEARS...\n");
System.out.println("\t\t+------------------------------+\n");

for(double day = 0; day < (365 * 10); day++) { //To initialize, set a limit, and
increment
compoundDaily = compoundDaily + compoundDaily * rateForDaily; //To compute for the future
value when compounded daily
}
System.out.printf("\n\t\s\sValue when compounded daily = \u20B1%.2f\n", compoundDaily); //To print future value when
compounded daily

for(double month = 0; month < (12 * 10); month++) { //To initialize, set a limit, and
increment for number
compoundMonthly = compoundMonthly + compoundMonthly * rateForMonthly; //To compute for the future
value when compounded monthly
}
System.out.printf("\n\t\s\sValue when compounded monthly = \u20B1%.2f\n", compoundMonthly); //To print future value when
compounded monthly

for(double year = 0; year < 10; year++) { //To initialize, set a limit, and
increment for number
compoundYearly = compoundYearly + compoundYearly * rateForYearly; //To compute for the future
value when compounded yearly
}
System.out.printf("\n\t\s\sValue when compounded yearly = \u20B1%.2f\n", compoundYearly); //To print future value when
compounded yearly
System.out.println("\t\s__________________________________________________________\n");

System.out.printf("\t\s\sPress any key to continue or type (x) to quit program: "); //To ask the user to decide if he or
she wants another transaction
input.nextLine();
toTerminateProg = input.nextLine();

System.out.println("\t\s__________________________________________________________\n");
}
while (!toTerminateProg.equals("x")); //To continue the loop as long as input is not
x
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|-------------THANK YOU FOR USING OUR SERVICE!--------------|");
System.out.println("\t|___________________________________________________________|");

//To terminate object scanner


input.close();

//End of program

}
}





















































































Sample Output:

Source Code (Screenshot):

USING FOR LOOP


USING WHILE LOOP

USING DO WHILE LOOP

Text-based Code:

USING FOR LOOP

package midtermactivities;

import java.util.Scanner;

public class CentimetersToInchesForLoop {

public static void main(String[] args) {

//scanner object
Scanner input = new Scanner (System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|-------------CM TO IN CONVERSION USING FOR LOOP------------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\sLET US COMPUTE IT FOR YOU.");
System.out.println("\t\t+-----------------------------+\n");

//To get a number from the users for where they want to start the loop from
System.out.printf("\n\t\s\sInput the value where to start: ");
double startingPoint = input.nextDouble();

//To get a number from the users for what they want to use as a step or jump
System.out.printf("\n\t\s\sInput the value for step: ");
double interval = input.nextDouble();

//To get a number from the users for where they want to end the loop at
System.out.printf("\n\t\s\sInput the value where to end: ");
double endPoint = input.nextDouble();

//For title, design, and partitions


System.out.println("\t\s___________________________________________________________\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\s\s\s\sCONVERSION OUTPUT:");
System.out.println("\t\t+-----------------------------+\n");
System.out.println("\n\t\s\sCM\t\tINCHES");

/**To declare data type and to include later the starting number in conversion
* Loop for continuous evaluation until the end point user chooses
* To follow the step the user chooses
*/
for (double count = startingPoint; count <= endPoint; count += interval) {
double inches = count / 2.54; //For conversion
purposes
System.out.printf("\t\s\s%.0f\t\t%.2f\n", count, inches); ////To display the
conversion results
}

System.out.println("\t\s___________________________________________________________");

//To terminate object scanner


input.close();

//End of program
}

USING WHILE LOOP

package midtermactivities;

import java.util.Scanner;

public class CentimetersToInchesWhileLoop {

public static void main(String[] args) {

//scanner object
Scanner input = new Scanner (System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|------------CM TO IN CONVERSION USING WHILE LOOP-----------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\sLET US COMPUTE IT FOR YOU.");
System.out.println("\t\t+-----------------------------+\n");

//To get a number from the users for where they want to start the loop from
System.out.printf("\n\t\s\sInput the value where to start: ");
double startingPoint = input.nextDouble();

//To get a number from the users for what they want to use as a step or jump
System.out.printf("\n\t\s\sInput the value for step: ");
double interval = input.nextDouble();

//To get a number from the users for where they want to end the loop at
System.out.printf("\n\t\s\sInput the value where to end: ");
double endPoint = input.nextDouble();

//For title, design, and partitions


System.out.println("\t\s___________________________________________________________\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\s\s\s\sCONVERSION OUTPUT:");
System.out.println("\t\t+-----------------------------+\n");
System.out.println("\n\t\s\sCM\t\tINCHES");

//To declare data type and to include later the starting number in conversion
double count = startingPoint;
double inches = 0;

//Loop for continuous evaluation until the end point user chooses
while(count <= endPoint) {
inches = count / 2.54; //For conversion purposes
System.out.printf("\t\s\s%.0f\t\t%.2f\n", count, inches); //To display the
conversion results
count += interval; //To follow the step the
user chooses
}

System.out.println("\t\s___________________________________________________________");

//To terminate object scanner


input.close();

//End of program
}

USING DO WHILE LOOP

package midtermactivities;

import java.util.Scanner;

public class CentimetersToInchesDoWhile {

public static void main(String[] args) {


//scanner object
Scanner input = new Scanner (System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|----------CM TO IN CONVERSION USING DO WHILE LOOP----------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\sLET US COMPUTE IT FOR YOU.");
System.out.println("\t\t+-----------------------------+\n");

//To get a number from the users for where they want to start the loop from
System.out.printf("\n\t\s\sInput the value for the START: ");
double startingPoint = input.nextDouble();

//To get a number from the users for what they want to use as a step or jump
System.out.printf("\n\t\s\sInput the value for the STEP: ");
double interval = input.nextDouble();

//To get a number from the users for where they want to end the loop at
System.out.printf("\n\t\s\sInput the value for the END: ");
double endPoint = input.nextDouble();

//For title, design, and partitions


System.out.println("\t\s___________________________________________________________\n");
System.out.println("\t\t+-----------------------------+");
System.out.println("\t\t\s\s\s\s\s\sCONVERSION OUTPUT:");
System.out.println("\t\t+-----------------------------+\n");
System.out.println("\n\t\s\sCM\t\tINCHES");

//To declare data type and to include later the starting number in conversion
double count = startingPoint;
double inches = 0;

/**What should be done simultaneously,


* conversion, printing of results, and step or jump
*/
do {inches = count / 2.54;
System.out.printf("\t\s\s%.0f\t\t%.2f\n", count, inches);
count += interval;

}
while(count <= endPoint); //Loop for continuous evaluation until the end point user
chooses

System.out.println("\t\s___________________________________________________________");

//To terminate object scanner


input.close();

//End of program
}

Sample Output:

USING FOR LOOP

USING WHILE LOOP

USING DO WHILE LOOP

Source Code (Screenshot):

USING FOR LOOP


USING DO WHILE LOOP

Text-based Code:

USING FOR LOOP

package midtermactivities;

import java.util.Scanner;

public class ProgramStopsAtInputZeroForLoop {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|---------PROGRAM STOPS AT INPUT ZERO WITH FOR LOOP---------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+------------------------------+");
System.out.println("\t\t\s\s\s\sTRY MORE NUMBERS!!!");
System.out.println("\t\t+------------------------------+\n");

System.out.printf("\t\s\sEnter a number, 0 to stop: ");


int a = scan.nextInt();
System.out.println("\t\s\s" + a);

//Loop to be executed as long as the input is not equal to zero


for(;a != 0;) {

System.out.printf("\t\s\sEnter a number, 0 to stop: "); //To get a number from


the user
a = scan.nextInt();
System.out.println("\t\s\s"+a); //To print the number from
the user

//To be printed once the customer inputs 0


System.out.println("\t\s___________________________________________________________");
System.out.println("\t|--------------EXECUTION SUCCESSFULLY COMPLETED-------------|");
System.out.println("\t|___________________________________________________________|");

//End of program
}

USING DO WHILE LOOP

package midtermactivities;

import java.util.Scanner;

public class ProgramStopsAtInputZeroForLoop {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

/** For title purposes and design


* The little box looking filled with symbols are just,
* for aesthetic purposes only.
*/
System.out.println("\t\s___________________________________________________________");
System.out.println("\t|-------PROGRAM STOPS AT INPUT ZERO WITH DO WHILE LOOP------|");
System.out.println("\t|___________________________________________________________|\n");
System.out.println("\t\t+------------------------------+");
System.out.println("\t\t\s\s\s\sTRY MORE NUMBERS!!!");
System.out.println("\t\t+------------------------------+\n");

System.out.printf("\t\s\sEnter a number, 0 to stop: ");


int a = scan.nextInt();
System.out.println("\t\s\s" + a);

//Loop to be executed as long as the input is not equal to zero


for(;a != 0;) {

System.out.printf("\t\s\sEnter a number, 0 to stop: "); //To get a number from


the user
a = scan.nextInt();
System.out.println("\t\s\s"+a); //To print the number from
the user

//To be printed once the customer inputs 0


System.out.println("\t\s___________________________________________________________");
System.out.println("\t|--------------EXECUTION SUCCESSFULLY COMPLETED-------------|");
System.out.println("\t|___________________________________________________________|");

//End of program
}

Sample Output:

USING FOR LOOP

USING DO WHILE LOOP

" I affirm that I have not given or received any unauthorized help in this assignment, and that this work is
my own “

You might also like