import java.util.HashMap;
import java.util.Map;
public class FormSubmissionFormatter {
/**
* Formats the output of a form submission with manual overrides.
*
* @param originalData The original data submitted from the form.
* @param manualOverrides A map containing fields to override in the original data.
* @return A formatted string representation of the form submission data.
*/
public static String formatSubmission(Map<String, String> originalData, Map<String, String> manualOverrides) {
Map<String, String> formattedData = new HashMap<>(originalData); // Create a copy to avoid modifying the original
// Apply manual overrides
for (Map.Entry<String, String> entry : manualOverrides.entrySet()) {
formattedData.put(entry.getKey(), entry.getValue());
}
StringBuilder sb = new StringBuilder();
sb.append("--- Form Submission ---\n");
for (Map.Entry<String, String> entry : formattedData.entrySet()) {
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
}
sb.append("-----------------------\n");
return sb.toString();
}
public static void main(String[] args) {
//Example usage
Map<String, String> originalData = new HashMap<>();
originalData.put("username", "john.doe");
originalData.put("email", "john.doe@example.com");
originalData.put("age", "30");
originalData.put("city", "New York");
Map<String, String> manualOverrides = new HashMap<>();
manualOverrides.put("age", "31"); //Override age
manualOverrides.put("city", "Los Angeles"); //Override city
String formattedOutput = formatSubmission(originalData, manualOverrides);
System.out.println(formattedOutput);
}
}
Add your comment