Professional Documents
Culture Documents
Laboratory Activity #8
Text-based Code:
package midtermactivities;
import java.util.Scanner;
//Scanner object
Scanner input = new Scanner(System.in);
//To declare what the data type the termination variable can accept
String toTerminateProg = "x";
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();
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|___________________________________________________________|");
//End of program
}
}
Sample Output:
Text-based Code:
package midtermactivities;
import java.util.Scanner;
//scanner object
Scanner input = new Scanner (System.in);
//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();
/**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___________________________________________________________");
//End of program
}
package midtermactivities;
import java.util.Scanner;
//scanner object
Scanner input = new Scanner (System.in);
//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();
//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___________________________________________________________");
//End of program
}
package midtermactivities;
import java.util.Scanner;
//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();
//To declare data type and to include later the starting number in conversion
double count = startingPoint;
double inches = 0;
}
while(count <= endPoint); //Loop for continuous evaluation until the end point user
chooses
System.out.println("\t\s___________________________________________________________");
//End of program
}
Sample Output:
Text-based Code:
package midtermactivities;
import java.util.Scanner;
//End of program
}
package midtermactivities;
import java.util.Scanner;
//End of program
}
Sample Output:
" I affirm that I have not given or received any unauthorized help in this assignment, and that this work is
my own “