Last active
July 5, 2018 07:27
-
-
Save Kejvu/55f59d97ade33a357e04f1fe1bc8e8c4 to your computer and use it in GitHub Desktop.
Car Loan - Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Vujadin Ranisavljević | |
* | |
*/ | |
import java.util.Scanner; | |
public class CarLoan { | |
public static void main(String[] args) { | |
// Car loan program. | |
Scanner input = new Scanner(System.in); | |
int carLoan; | |
int loanLenght; | |
int interestRate = 5; | |
int downPayment; | |
System.out.println("Koliku pozajmicu želite?"); | |
carLoan = input.nextInt(); | |
if(carLoan > 50000) | |
{ | |
System.out.println("Pozajmica ne moze da bude veca od 50.000 eura"); | |
} | |
else if(carLoan <1000) | |
{ | |
System.out.println("Pozajmica ne moze da bude manja od 1000 eura"); | |
return; | |
} | |
System.out.println("Na koliko godina želite pozajmicu? "); | |
loanLenght = input.nextInt(); | |
if (loanLenght <= 0 ) { | |
System.out.println("Greska! Morate uzeti validnu pozajmicu"); | |
return; // zaustavlja program ukoliko je pozajmica 0 godina. | |
} else if (loanLenght > 6 ) { | |
System.out.println("Pozajmica ne moze da bude duža od 6 godina" ); | |
return; // zaustavlja program ukoliko je duze od 6 godina | |
} | |
System.out.println("Koliko želite da date depozit? "); | |
downPayment = input.nextInt(); | |
if (downPayment >= carLoan) { | |
System.out.println("Pozajmica je placena u potpunosti"); | |
return; // zaustavlja program ukoliko je pozajmica placena u potpunosti | |
} | |
int remainingBalance = carLoan - downPayment; | |
int month = loanLenght * 12; | |
int monthlyBalance = remainingBalance / month; | |
int interest = monthlyBalance * interestRate /100; | |
int monthlyPayment = monthlyBalance; | |
System.out.print("Vaša mesečna rata je: " ); | |
System.out.print(monthlyPayment + interest); System.out.println(" eura"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment