Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with strings and class string #typ value; #det value; #loc value; #lat valu

ID: 3744212 • Letter: H

Question

Help with strings and class string

#typ value; #det value; #loc value; #lat value; #lng value;

1) Make a scanner class to input a message and store into a String variable (message)

2) Parse the message into 5 different types of info specifyed by #(type, location, detail, latitude, and longitude and store these values into their own variables

3) Divide message into the seperate substrings and store in 2 variables(first & last) that hold where the substring first starts and finishes (last)

4) Then when the numbers are assigned to the first and last, discard the # tag(ie. #typ or #loc) and extract where the value starts and finishes

5) Then take the substring at those staring and ending positions to assign it to the variables mentioned in (2)

6) Then trim leading and trailing whitespaces from the strings

7) Then we repeat the steps for each substring

8) Then change the type value into upper case and make the "," in detail and location into "-"

Then print statements showing each variable with the information

Type: VALUE

Detail: value

Location: value

Latitude: value

Longitude: value

Explanation / Answer

I am not able to understand your problem statement clearly. Please explain the problem with a sample input and output. Once you do so, i will provide you a more correct version of the solution.

For time being, I am providing you a sample implementation of the code. Please provide the sample input and output using pastebin (share the link with me later).Once you do so, I will update the solution.

CODE

===================

import java.util.Random;

import java.util.Scanner;

public class App {

   public static void main(String args[]) {

       Random rand = new Random();

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter a message : ");

       String message = sc.nextLine();

      

       String inputs[] = message.split("#");

       String type = inputs[0];

       String location = inputs[1];

       String detail = inputs[2];

       String latitude = inputs[3];

       String longitude = inputs[4];

      

       int first = 0;

       int last = rand.nextInt(message.length());

      

       String firstSubstr = message.substring(first, last);

       String lastSubstr = message.substring(last);

      

       // discarding location tag

       firstSubstr = firstSubstr.replace(location, "");

       lastSubstr = lastSubstr.replace(location, "");

      

       // if the location was present in the first substring, need to update the last position

       last = firstSubstr.length()-1;

      

       firstSubstr = firstSubstr.trim();

       lastSubstr = lastSubstr.trim();

      

       type = type.toUpperCase();

       location = "-";

       detail = ",";

      

       System.out.println("Type : " + type);

       System.out.println("Detail : " + detail);

       System.out.println("Location : " + location);

       System.out.println("Latitude : " + latitude);

       System.out.println("Longitude : " + longitude);

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote