Post by Ian Plätschisch on Dec 7, 2018 22:10:35 GMT -6
I am currently studying for a final in a Java course I am taking, so I decided to write some Talossa-related programs. This one can convert dollars to louise and vice versa.
import java.util.Scanner;
public class MoneyConverter {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter \"1\" to convert from dollars to louise or \"2\" to convert from louise to dollars");
int input = keyboard.nextInt();
while (input != 1 && input != 2) {
System.out.println("Invalid input. Enter a valid input");
input = keyboard.nextInt();
}
if (input == 1) {
System.out.println();
System.out.print("Enter the amount of dollars: ");
double dollars = keyboard.nextDouble();
double louise = dollars / 1.5;
int wholeLouise = (int)louise;
double bence = (louise - wholeLouise) * 60;
int roundedBence = (int)bence;
if (bence - roundedBence >= .5) {
roundedBence++;
}
if (roundedBence == 60) {
wholeLouise++;
roundedBence = 0;
}
if (roundedBence == 0) {
System.out.println("Amount of louise: ℓ" + wholeLouise);
}
else {
System.out.println("Amount of louise: " + wholeLouise + "¤" + roundedBence);
}
}
else {
System.out.println();
System.out.print("Enter the number of whole louise: ");
int louise = keyboard.nextInt();
System.out.print("Enter the number of bence: ");
int bence = keyboard.nextInt();
double dollars = louise * 1.5 + bence * .025;
int wholeDollars = (int)dollars;
double cents = (dollars - wholeDollars) * 100;
int roundedCents = (int)cents;
if (cents - roundedCents >= .5) {
roundedCents++;
}
if (roundedCents == 100) {
wholeDollars++;
roundedCents = 0;
}
if (roundedCents == 0) {
System.out.println("Amount of dollars: $" + wholeDollars);
}
else {
System.out.println("Amount of dollars: $" + wholeDollars + "." + roundedCents);
}
}
}
}
import java.util.Scanner;
public class MoneyConverter {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter \"1\" to convert from dollars to louise or \"2\" to convert from louise to dollars");
int input = keyboard.nextInt();
while (input != 1 && input != 2) {
System.out.println("Invalid input. Enter a valid input");
input = keyboard.nextInt();
}
if (input == 1) {
System.out.println();
System.out.print("Enter the amount of dollars: ");
double dollars = keyboard.nextDouble();
double louise = dollars / 1.5;
int wholeLouise = (int)louise;
double bence = (louise - wholeLouise) * 60;
int roundedBence = (int)bence;
if (bence - roundedBence >= .5) {
roundedBence++;
}
if (roundedBence == 60) {
wholeLouise++;
roundedBence = 0;
}
if (roundedBence == 0) {
System.out.println("Amount of louise: ℓ" + wholeLouise);
}
else {
System.out.println("Amount of louise: " + wholeLouise + "¤" + roundedBence);
}
}
else {
System.out.println();
System.out.print("Enter the number of whole louise: ");
int louise = keyboard.nextInt();
System.out.print("Enter the number of bence: ");
int bence = keyboard.nextInt();
double dollars = louise * 1.5 + bence * .025;
int wholeDollars = (int)dollars;
double cents = (dollars - wholeDollars) * 100;
int roundedCents = (int)cents;
if (cents - roundedCents >= .5) {
roundedCents++;
}
if (roundedCents == 100) {
wholeDollars++;
roundedCents = 0;
}
if (roundedCents == 0) {
System.out.println("Amount of dollars: $" + wholeDollars);
}
else {
System.out.println("Amount of dollars: $" + wholeDollars + "." + roundedCents);
}
}
}
}