Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /***
- *
- * @author Rilind Asllani
- * Spring 2020
- * Information Systems 4415-090
- * Homework 1
- * 1/15/2020
- */
- public class homeworkOne
- {
- public static void main(String[] args)
- {
- //Remove commment lines to run specific method.
- //celsiusToFahrenheit();
- //calculateTips();
- //sumOfTheDigits();
- //compoundValue();
- //futureInvestmentValue();
- }
- /**
- * Homework Problem 2.1
- * Convert Celsius to Fahrenheit
- * Celsius written using double value then converting with formula to fahrenheit.
- */
- public static void celsiusToFahrenheit()
- {
- Scanner input = new Scanner(System.in); //Reads the console input.
- double celsius; // Variable set for celius.
- double Fahrenheit; // Variable set of Fahrenheit.
- System.out.print("Enter a degree in Celsius: "); //asking for Celsius
- celsius = input.nextDouble(); //reads the input and sets it equal to variable celsius.
- Fahrenheit = (9.0/5.0) * celsius + 32; // calculates the fahrenheit and sets it equal to variable fahrenheit.
- System.out.println(celsius + " Celsius is "+ Fahrenheit + " Fahrenheit."); //prints line with the fahrenheit given some celsius.
- }
- /**
- * Homework Problem 2.5
- * Calculate the tip.
- */
- public static void calculateTips()
- {
- // Scanner variable and double variables.
- Scanner input = new Scanner(System.in);
- Double subtotal, gratuity;
- //Console prompt for two doubles to be used in calculations.
- System.out.print("Enter the subtotal and a gratuity rate: ");
- //Setting the two double values to the variables.
- subtotal = input.nextDouble();
- gratuity = input.nextDouble();
- //calculating the gratuity.
- gratuity = gratuity/100 * subtotal;
- //calculating the total
- subtotal = gratuity + subtotal;
- //printing out the total
- System.out.println("The gratuity is $" + gratuity + " and the total is $" + subtotal);
- }
- /**
- * Homework Problem 2.6
- * Sum of the digits between 0 and 1000 not inclusive.
- */
- public static void sumOfTheDigits()
- {
- //asking for a number between 0-1000
- System.out.print("Enter a number between 0 and 1000: ");
- //Scanner and setting variable number equal to next int.
- Scanner input = new Scanner(System.in);
- int number = input.nextInt();
- // splitting the number into each digit.
- int hundreds = number % 1000 /100;
- int tens = number % 100 / 10;
- int ones = number - (hundreds*100) -(tens*10);
- //the sum of all the digits
- int sum = hundreds + tens + ones;
- //prints out sum of the digits
- System.out.println("The sum of the digits is " + sum);
- }
- /**
- * Homework Problem 2.13
- */
- public static void compoundValue()
- {
- //Scanner and asking for savings amount
- Scanner input = new Scanner(System.in);
- System.out.print("Enter the monthly saving amount: ");
- // setting variables
- double savings = input.nextDouble();
- double interest = 0.00417;
- double totalSavings = 0;
- // Just repeated the savings account calculation 5 times
- totalSavings += savings+(savings+totalSavings)*interest;
- totalSavings += savings+(savings+totalSavings)*interest;
- totalSavings += savings+(savings+totalSavings)*interest;
- totalSavings += savings+(savings+totalSavings)*interest;
- totalSavings += savings+(savings+totalSavings)*interest;
- totalSavings += savings+(savings+totalSavings)*interest;
- //removing the numbers that come after the second digit beyond the decimal. The addition of 0.5 is to round up.
- totalSavings = (int)(totalSavings * 100 + 0.5);
- // Printing savings after 6 months
- System.out.println("After the sixth month, the account value is $" + totalSavings/100);
- }
- /**
- * Homework Problem 2.21
- */
- public static void futureInvestmentValue()
- {
- //asking for investment amount
- System.out.print("Enter investment amount: ");
- Scanner input = new Scanner(System.in);
- double investmentAmount = input.nextDouble();
- //asking for annual rate and changing it to monthly rate while setting it to monthlyPercentage variable.
- System.out.print("Enter annual rate in percentage: ");
- double monthlyPercentage = ((input.nextDouble()/100)/12);
- //asking for years and setting the variable for years.
- System.out.print("Enter number of years: ");
- int years = input.nextInt();
- //investment formula and removing everything after the 2 decimal place
- double futureValue = investmentAmount*Math.pow(1+monthlyPercentage, years*12);
- futureValue = (int)(futureValue*100 + 0.5);
- System.out.println("Future value is $" + futureValue/100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement