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

[JAVA] 1. Write a complete Java method called stringReverser that takes a String

ID: 665259 • Letter: #

Question

[JAVA]

1. Write a complete Java method called stringReverser that takes a String as a parameter and prints it in reverse order. For example, if the method is passed the string “test”, it prints “tset”. The method returns a boolean. If the method is passed an empty String, return false, otherwise print the String in reverse order and then return true. (2 points)

2. Write a Java statement (one line) to call the method you wrote in problem #1. (1 point)

3. Write a complete Java program called UserNamer that includes four methods. The first method gets the user’s first name from the command line and returns it. Include a prompt. The second gets the users last name from the command line and returns it. Include a prompt. The third method takes the first and last name as parameters and returns a suggested username as a String. This method constructs the username by concatenating the first letter of the user’s first name with their last name. For example, a user named Jill Smith would have a suggested username JSmith. The fourth method takes the username as a parameter and prints it to the command line. Call all of these methods from main to complete your program. (3 points)

4. Write a complete Java program called VitalSigns. The program gets three values from the user: heart rate, systolic blood pressure, and respirations. It uses the following table of rules to make an assessment of the patient’s condition (these are simplifications):

Normal Range

Low Condition

High Condition

Heart Rate

60-100

Bradycardia

Tachycardia

Systolic Blood Pressure

90-120

Hypotension

Hypertension

Respirations

12-20

Bradypnea

Tachypnea

After getting the three values from the user and deciding on each of their conditions, output the conditions to the command line as in this example:

Heart Rate: Normal           Blood Pressure: Hypertension                 Respirations: Normal

Your program should use AT LEAST four different methods to perform its functions. Call all of these methods from main to complete your program. (4 points)

Normal Range

Low Condition

High Condition

Heart Rate

60-100

Bradycardia

Tachycardia

Systolic Blood Pressure

90-120

Hypotension

Hypertension

Respirations

12-20

Bradypnea

Tachypnea

Explanation / Answer

// Answer to Question 1:

public class RevStr{

     public static void main(String []args){
         String str1;
        System.out.println("Strig Reverse Program");
        str1 = "test";
        RevMe(str1);
     }
   
     public static boolean RevMe(String str2)
     {
         if (str2.isEmpty()) {return false;}
         else
         {
         str2 = new StringBuffer(str2).reverse().toString();
         System.out.println("The string in reverse order is: " + str2);
         return true;
        }
       
     }
}

// Answer to Question 2: A one line java statement to call the above method:

RevMe(str1);

// Answer to Question 3:

import java.io.*;
import java.util.*;
      
public class UserName{
      public static void main(String []args){
         firstName(); // call the first method to read and write the first name
         lastName();   // call the second method to read and write the last name
         SuggestName();
         String UsrNm;
         UsrNm = "John GrahamBell";
         paramUserName(UsrNm); // main has called all these 4 methods
     }
     public static void firstName() // method 1
     {
        Scanner rd = new Scanner(System.in);
        System.out.println(" Enter User's First name: ");
        String fnm = rd.nextLine();
        System.out.println("The first name is: " + fnm);
     }
     public static void lastName()   // method 2
     {
        Scanner rd = new Scanner(System.in);
        System.out.println(" Enter User's Last name: ");
        String lnm = rd.nextLine();
        System.out.println("The Last name is: " + lnm);
       
     }
     public static void SuggestName() // method 3
     {
        String firstName, lastName, suggestedName, firstChar;
      
        Scanner rd = new Scanner(System.in);
      
        System.out.println(" Enter User's First name: ");
        firstName = rd.nextLine();
        firstChar = firstName.substring(0,1);
      
        System.out.println(" Enter User's Last name: ");
        lastName = rd.nextLine();
      
        System.out.println("The Suggested name is: " + firstChar + lastName);
       
     }
     public static void paramUserName(String un) // method 4
     {
           System.out.println("The user name received as a parameter is: " + un);
     }
}

Answer to Question 4:

import java.io.*;
import java.util.*;
import java.util.Scanner;
public class VitalSigns{
    public static void main(String []args){
        //int sysBP, resp;
        //String hrtRt;
    
      HeartRate();
      SystolicBP();
      Resp();
    
    }

public static void HeartRate(){
        Scanner rd = new Scanner(System.in);
      
        System.out.println(" Enter Heart Rate ");
        int hrtRt = rd.nextInt();

    if (hrtRt < 60 ) { System.out.println(" Heart Rate: BradyCardia ");}
    if (hrtRt > 100) { System.out.println(" Heart Rate: TachyCardia ");}
    if ((hrtRt >=60) && (hrtRt <=100)) { System.out.println(" Heart Rate: Normal ");}               
  
}

public static void SystolicBP(){
            Scanner rd = new Scanner(System.in);
        System.out.println(" Enter Systolic Blood Pressure ");
        int sysBP = rd.nextInt();
    if (sysBP < 90 ) { System.out.println(" Blood Pressure: Hypotension ");}
    if (sysBP > 120) { System.out.println(" Blood Pressure: Hypertension ");}
    if ((sysBP >=90) && (sysBP <=120)) { System.out.println(" Blood Pressure: Normal ");}               


}

public static void Resp(){
            Scanner rd = new Scanner(System.in);
        System.out.println(" Enter Respirations ");
        int resp = rd.nextInt();
    if (resp < 90 ) { System.out.println(" Respirations: Bradypnea ");}
    if (resp > 120) { System.out.println(" Respirations: Tachypnea ");}
    if ((resp >=90) && (resp <=120)) { System.out.println(" Respirations: Normal ");}               

}
}

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