Pseudocode Task #1: Calculating an Average Goal: write an algorithm that calcula
ID: 3664049 • Letter: P
Question
Pseudocode Task #1: Calculating an Average Goal: write an algorithm that calculates the average of a sequence of numbers.
Inputs: Assume that you start with a variable called "list_of_numbers" that contains all numbers in a sequence to be averaged.
Output: A floating point number representing the average of list_of_numbers.
Pseudocode Task #2: Input Checker Goal: write an algorithm that determines whether or not the supplied number is either an integer (whole number) or a floating point number (decimal number).
Input: Assume that you start with a variable called "user_input" that contains the input to be verified.
Output: Whether user_input is an integer or floating point number.
Programming Task: Loan Calculator In this task, you will write a simple loan repayment calculator. In order to complete this task, you will need to prompt the user for the following information:
Principle (i.e. total loan amount, in dollars)
Annual interest rate (in percent)
Loan duration (in years)
Explanation / Answer
1.
float average(int list[], int n) {
float avg = 0;
int sum = 0;
for(int i =0; i <n; i++ ) {
sum = sum + list[i];
}
avg = (float)sum/n;
return avg;
}
2.
verify_input(user_input) {
int temp = (int)usr_input; // getting integer part
if(temp - user_input == 0)// both are same
return "Integer";
else
return "Float"; // Not same
}
3.
//LoanCalculator.java
import java.util.Scanner;
public class LoanCalculator {
static float loanCalculator(float principle, int year, int rate) {
float total_loan = 0;
float interest = 0.0f;
interest =(principle*year*rate)/100.0f;
total_loan = principle + interest;
return total_loan;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter principle: ");
float principle = sc.nextFloat();
System.out.println("Enter year: ");
int year = sc.nextInt();
System.out.println("Enter rate: ");
int rate = sc.nextInt();
float total_loan = loanCalculator(principle, year, rate);
System.out.println(total_loan);
}
float average(int list[], int n) {
float avg = 0;
int sum = 0;
for(int i =0; i <n; i++ ) {
sum = sum + list[i];
}
avg = (float)sum/n;
return avg;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.