0% found this document useful (0 votes)
4 views5 pages

Kodlar

The document contains multiple Java programs that perform various tasks: converting seconds to minutes and seconds, converting Fahrenheit to Celsius, calculating sales tax, computing loan payments, and determining the monetary equivalent of a given amount in dollars and coins. Each program prompts the user for input and displays the results accordingly. The code examples illustrate basic programming concepts such as user input, arithmetic operations, and output formatting.

Uploaded by

Emre Selvili
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Kodlar

The document contains multiple Java programs that perform various tasks: converting seconds to minutes and seconds, converting Fahrenheit to Celsius, calculating sales tax, computing loan payments, and determining the monetary equivalent of a given amount in dollars and coins. Each program prompts the user for input and displays the results accordingly. The code examples illustrate basic programming concepts such as user input, arithmetic operations, and output formatting.

Uploaded by

Emre Selvili
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Write a program that obtains minutes and remaining seconds from

seconds.
import java.util.Scanner;

public class DisplayTime {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user for input
System.out.print("Enter an integer for seconds: ");
int seconds = input.nextInt();

int minutes = seconds / 60; // Find minutes in seconds


int remainingSeconds = seconds % 60; // Seconds remaining
System.out.println(seconds + " seconds is " + minutes +
" minutes and " + remainingSeconds + " seconds");
}
}

Write a program that converts a Fahrenheit degree to Celsius using the


formula:
import java.util.Scanner;

public class FahrenheitToCelsius {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter a degree in Fahrenheit: ");


double fahrenheit = input.nextDouble();
// Convert Fahrenheit to Celsius
double celsius = (5.0 / 9) * (fahrenheit - 32);
System.out.println("Fahrenheit " + fahrenheit + " is " +
celsius + " in Celsius");
}
}

Write a program that displays the sales tax with two digits after the
decimal point.
import java.util.Scanner;

public class SalesTax {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter purchase amount: ");


double purchaseAmount = input.nextDouble();

double tax = purchaseAmount * 0.06;


System.out.println("Sales tax is " + (int)(tax * 100) / 100.0);
}
}
This program lets the user enter the interest rate, number of years, and
loan amount, and computes monthly payment and total payment.
import java.util.Scanner;

public class ComputeLoan {


public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);

// Enter yearly interest rate


System.out.print("Enter yearly interest rate, for example 8.25: ");
double annualInterestRate = input.nextDouble();

// Obtain monthly interest rate


double monthlyInterestRate = annualInterestRate / 1200;

// Enter number of years


System.out.print(
"Enter number of years as an integer, for example 5: ");
int numberOfYears = input.nextInt();

// Enter loan amount


System.out.print("Enter loan amount, for example 120000.95: ");
double loanAmount = input.nextDouble();

// Calculate payment
double monthlyPayment = loanAmount * monthlyInterestRate / (1
- 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
double totalPayment = monthlyPayment * numberOfYears * 12;

// Display results
System.out.println("The monthly payment is $" +
(int)(monthlyPayment * 100) / 100.0);
System.out.println("The total payment is $" +
(int)(totalPayment * 100) / 100.0);
}
}

This program lets the user enter the amount in decimal representing
dollars and cents and output a report listing the monetary equivalent in
single dollars, quarters, dimes, nickels, and pennies. Your program
should report maximum number of dollars, then the maximum number
of quarters, and so on, in this order

mport java.util.Scanner;

public class ComputeChange {


public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);

// Receive the amount


System.out.print(
"Enter an amount in double, for example 11.56: ");
double amount = input.nextDouble();

int remainingAmount = (int)(amount * 100);

// Find the number of one dollars


int numberOfOneDollars = remainingAmount / 100;
remainingAmount = remainingAmount % 100;
// Find the number of quarters in the remaining amount
int numberOfQuarters = remainingAmount / 25;
remainingAmount = remainingAmount % 25;

// Find the number of dimes in the remaining amount


int numberOfDimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;

// Find the number of nickels in the remaining amount


int numberOfNickels = remainingAmount / 5;
remainingAmount = remainingAmount % 5;

// Find the number of pennies in the remaining amount


int numberOfPennies = remainingAmount;

// Display results
System.out.println("Your amount " + amount + " consists of");
System.out.println(" " + numberOfOneDollars + " dollars");
System.out.println(" " + numberOfQuarters + " quarters");
System.out.println(" " + numberOfDimes + " dimes");
System.out.println(" " + numberOfNickels + " nickels");
System.out.println(" " + numberOfPennies + " pennies");
}
}

You might also like