Answer:
Step-by-step explanation:
import javax.swing.JOptionPane;
public class MassageReservation {
public static void main(String[] args)
{
String memberId = JOptionPane.showInputDialog(null, "Please enter the member Id:");
while(memberId.length() != 6)
{
JOptionPane.showMessageDialog(null, "Member Id should be 6 characters long!");
memberId = JOptionPane.showInputDialog(null, "Please enter the member Id:");
}
// capitalise all the characters
memberId = memberId.toUpperCase();
// format the member id
String newMemberId = memberId.substring(0, 2) + "-" + memberId.substring(2, 5) + "-" + memberId.substring(5);
// prompt user for the number of minutes
String minStr = JOptionPane.showInputDialog(null, "Please enter the number of minutes:");
while(!isDigit(minStr))
{
minStr = JOptionPane.showInputDialog(null, "Please enter the number of minutes:");
}
int minutes = Integer.parseInt(minStr);
// convert the minutes into hours and minutes
int hours = (minutes / 60);
int remMinutes = (minutes % 60);
if(hours == 1)
JOptionPane.showMessageDialog(null, "Thank you, Member " + newMemberId
+ " for youur massage reservation for " + hours + " hour and " + remMinutes + " minutes.");
else
JOptionPane.showMessageDialog(null, "Thank you, Member " + newMemberId
+ " for youur massage reservation for " + hours + " hours and " + remMinutes + " minutes.");
}
// this method takes a string as input and checks whether it is an integer
// if so, returns true or else, returns false
private static boolean isDigit(String s)
{
try
{
Integer.parseInt(s);
return true;
}catch(NumberFormatException nfe){
JOptionPane.showMessageDialog(null, s + " is not a valid digit!");
return false;
}
}
}