Tag Archives: ElseIf

Java CurrencyTranslator

Program shows the exchange rate (Doesn’t show real rates) for a requested sum between euros and USD. Edit: Testing GitHub Gists Old: import java.util.Scanner; public class CurrencyTranslator { Scanner reader=new Scanner(System.in); boolean repeat=true; double euroTOdollar=1.18;//€->$ rate double dollarTOeuro=0.85;//$->€ rate private void run(){ System.out.println(“*******************\nCurrency translator 1.0”); while(repeat){ int requestedOperation=getOperation();//euro->dollar or dollar->euro or exit executeRequestedOperation(requestedOperation); } }… Read More »

Java calculator

This program asks for two numbers and the mathematical operator to use on them. Calculator.java: import java.util.Scanner; public class Calculator { public void run() { Scanner numberReader=new Scanner(System.in); Scanner textReader=new Scanner(System.in); double number1, number2; String operator, result, rounding1, rounding2; System.out.print(“Enter first number: “); number1=numberReader.nextDouble(); System.out.print(“Enter second number: “); number2=numberReader.nextDouble(); System.out.print(“Operation: “); operator=textReader.nextLine(); numberReader.close(); textReader.close(); if(operator.equals(“+”))… Read More »

Java min&max

The program asks for three numbers and prints either the biggest or the smallest of them depending which one you choose. BiggestOrSmallestNumber.java: import java.util.Scanner; public class BiggestOrSmallestNumber { public void run() { Scanner numberReader=new Scanner(System.in); Scanner textReader = new Scanner(System.in); int number1, number2, number3; String biggestSmallest; System.out.println(“Enter three numbers:”); number1=numberReader.nextInt(); number2=numberReader.nextInt(); number3=numberReader.nextInt(); System.out.print(“Do you want… Read More »

Java calculate discount

The program asks for a price, checks if it is higher than 1000. If the price is less, it checks if it’s higher than 600 and prints the discounted price or a notification that the price wasn’t high enough. CalculateDiscount.java: import java.util.Scanner; public class CalculateDiscount { public void run() { Scanner reader=new Scanner(System.in); String over6hundred=”8%”,… Read More »