28.8k views
0 votes
FitnessFirst FitnessFirst Gyms utilize a member ID and the number of minutes to make massage reservations. Write a program that receives a string of 6 characters as a member ID and a number of minutes. Format the member ID as demonstrated below. Input: R4E877 Display: R4-E87-7 If the user enters characters in lowercase, it should still display the characters in uppercase. Your program should capitalize any letters it comes across. Input: x83rws Display: X8-3RW-S Use JOptionPane windows to get the string for the member id and the number of minutes for the massage. Return a confirmation JOptionPane window with newly formatted Member ID and translation of massage time into hours and minutes. Use good variable names and place comments throughout the source code explaining what you are doing. You do not need a comment for every line but provide some details of what you are attempting to do. Your program will have two prompts for data (member id and number of minutes) and return one window with the newly formatted memberId and the number of minutes translated into hours and minutes. For example: Fitness First Message Example Name your program FitnessFirstYourLastName and upload the completed .java file. Make sure you put your name in a comment at the top. This assignment is worth 10 points.

User MelMass
by
5.1k points

1 Answer

0 votes

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;

}

}

}

User Jake Toronto
by
5.3k points