You receive raw telemetry data in the following format: "D-100*T-10:30:45*STATUS:Ready"
· D- represents the number of days left for the launch.
· T- stands for the time left in hours, minutes, and seconds' format.
· After the second asterisk (*) is the current status of the spacecraft.
Your task is to:
· Extract this data and convert it into a more readable format.
· Calculate the total time left for the launch in minutes.
· Generate a status message based on the raw telemetry data.
Steps:
· Data Extraction:
· Identify the positions of the asterisks and hyphens in the string.
· Extract the number of days, time, and status message from the raw data string.
· Time Conversion:
· Convert the extracted time (which is in hours:minutes:seconds format) into total minutes using mathematical functions.
· Consider the days in your calculations. (1 day = 1440 minutes)
· Status Message Generation:
· If the character after "STATUS:" is an uppercase letter, display the status as it is. If it's a lowercase letter, convert it to uppercase before displaying. This ensures the status message always looks formal.
Deliverable:
Write a program in Java that takes the raw telemetry data string as input, performs the aforementioned steps, and outputs the status message and total minutes left for the launch.
Tips:
· Use String.indexOf() to find the position of specific characters or substrings in the string.
· String.split() can help in splitting the time format into hours, minutes, and seconds.
· Convert the extracted string numbers into integers using Integer.parseInt().
· Remember to use Math.round() or other relevant Math functions when needed.
1 answer
```java
public class TelemetryDataProcessor {
public static void main(String[] args) {
String rawData = "D-100*T-10:30:45*STATUS:Ready";
processTelemetryData(rawData);
}
public static void processTelemetryData(String rawData) {
// Data Extraction
int firstAsterisk = rawData.indexOf('*');
int secondAsterisk = rawData.indexOf('*', firstAsterisk + 1);
int hyphen = rawData.indexOf('-');
int days = Integer.parseInt(rawData.substring(hyphen + 1, firstAsterisk));
String time = rawData.substring(firstAsterisk + 3, secondAsterisk);
String status = rawData.substring(secondAsterisk + 8);
// Time Conversion
String[] timeParts = time.split(":");
int hours = Integer.parseInt(timeParts[0]);
int minutes = Integer.parseInt(timeParts[1]);
int seconds = Integer.parseInt(timeParts[2]);
int totalMinutes = (days * 1440) + (hours * 60) + minutes;
// Status Message Generation
if (Character.isLowerCase(status.charAt(0))) {
status = status.toUpperCase();
}
// Output
System.out.println("Days: " + days);
System.out.println("Time: " + time);
System.out.println("Total Minutes: " + totalMinutes);
System.out.println("Status: " + status);
}
}
```
This program first defines a `processTelemetryData` method that takes the raw telemetry data string as input.
In the method, we use the `indexOf` method to locate the positions of the asterisks and hyphen in the string. We then extract the number of days, time, and status message using the `substring` method.
Next, we split the time format into hours, minutes, and seconds using the `split` method. We convert these extracted string numbers into integers using `Integer.parseInt`.
To calculate the total time left for the launch, we multiply the number of days by 1440 (minutes in a day), then add the number of hours converted to minutes, and finally add the minutes extracted.
For the status message, we check if the character after "STATUS:" is lowercase using `Character.isLowerCase`. If it is, we convert it to uppercase using the `toUpperCase` method.
Finally, we output the extracted data, total minutes, and status message.
Note: In the given example, the `processTelemetryData` method is called in the `main` method with the raw data as input. You can modify this code according to your needs, like taking user input or passing the raw data from elsewhere.