Write a program that allows a user to enter a number of values, the program should then convert the values entered in pounds (GBP) into a number of different currencies. The menu should look something like this:
- Enter values and type -1 to stop
- Euros
- Dollars
- Yen
- Rupees
- Exit
When 2, 3, 4 or 5 are selected the program should display each value entered in both the original pounds and the converted currency, along with a total of all numbers and converted total.
public class Money {
public static void main(String[] args) {
System.out.println("Enter values and type -1 to stop");
System.out.println("'1' = Euros");
System.out.println("'2' = Dollars");
System.out.println("'3' = Yen");
System.out.println("'4' = Rupees");
System.out.println("'5' = Exit");
int count=0;
String exit = "-1", euro="E";
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.print("Convert to: ");
while (!scan.hasNext("[E, D, Y, R, X]+")) {
System.out.print("Invalid value, enter Surname again: ");
scan.next();
}
String exTo = scan.next();
ArrayList<String> num = new ArrayList<String>();
while (true) {
count++;
System.out.print("|| Enter values "+count+" in (P)Pounds : ");
while (!scan.hasNextDouble()) {
System.out.print("Invalid value, try again: ");
scan.next();
}
num.add(scan.next());
if(num.contains(exit)){
String ar[]=num.toArray(new String[num.size()]);
ar=num.toArray(ar);
System.out.println("Result: "+ num);
scan.close();
break;
}
}
}
}
try this :
to remove the last input (-1)
add this line before print
num.remove("-1");