Tag Archives: Method

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 NumberTable

Program asks you to enter 10 numbers and lists them from biggest to smallest. After the list is shown, the program asks if you would like to check for a specific number from the list. import java.util.Scanner; public class NumberTable { Scanner numberReader=new Scanner(System.in); Scanner textReader=new Scanner(System.in); double[] numbers=new double[10]; private void run(){ getNumbers(); arrangeNumbers();… Read More »

Java check phone number

Program asks for a phone number and checks if it is valid. CheckPhoneNo.java: import java.util.Scanner; public class CheckPhoneNo { boolean go=true; private void run() { Scanner reader=new Scanner(System.in); String phoneNo; while(go) { System.out.println(“Enter a phone number (6-15 numbers, may include an area code and spaces)”); phoneNo = reader.nextLine(); String phoneNoWithoutSpaces=removeSpaces(phoneNo); checkPhoneNo(phoneNoWithoutSpaces); } reader.close(); } private… Read More »

Java dice game

The program asks how much money you want to bet (amount of rounds) and throws three dice. If you get six once you win 1 euro, if twice 20 euros and if all three dice give a six you win 40 euros. DiceGame.java: import java.util.Scanner; import java.util.Random; public class DiceGame { Scanner reader=new Scanner(System.in); Random… Read More »

Java age in days

Program ask for your birthday and current date and calculates your age in days. AgeInDays.java import java.util.Scanner; public class AgeInDays { Scanner reader=new Scanner(System.in); int yearOfBirth, monthOfBirth, dayOfBirth, currentYear, currentMonth, currentDay, input;//Scope private void run() { yearOfBirth=getYear(“year of birth”); monthOfBirth=getMonth(“month of birth”); dayOfBirth=getDay(“day of birth”); currentYear=getYear(“current year”); currentMonth=getMonth(“current month”); currentDay=getDay(“current day”); reader.close(); int ageInDays=countAge(currentYear, yearOfBirth,… Read More »