Question

Pearson Sign in Mail - Josue Velazq... CSC 15 Chapter 4 lab This lab has two different problems. In this lab you are going to

File Assign to State * sentence analyzer X CSC 15 - Lab A C:/Users/17078/Downloads/chapter 204%20sentence weather pdf Pearson

e temperature is greater than or equal to 90, it is probably .summer. If the temperature is greater than or equal to 70, and

i need help getting this program running

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation::

  • Code in JAVA is given below
  • Please read comments for better understanding of the code
  • Output is given at the end of the code

Code in JAVA::

import java.util.Scanner;

public class Methods {

   public static void main(String[] args) {
       /**
       * Declaring Scanner class object named kb
       * */
       Scanner kb = new Scanner(System.in);
       /**
       * Calling the run() method
       * */
       run(kb);
       kb.close();
   }
  
   public static void run(Scanner kb) {
       /**
       * An integer variable named n is declared and we will store how many
       * times this program needs to be run as per user input
       * */
       int n;
       System.out.print("How many times do you want to run this program? ");
       n = kb.nextInt();
      
       /**
       * Running for loop for n times
       * */
       for(int i=1;i<=n;i++) {
           /**
           * An String variable named option is declared
           * and we call the getOption() method
           * */
           String option = getOption(kb);
           if(option.equals("sentence analyzer")) {
               String sentence;
               kb.nextLine();
               System.out.print("\nEnter the sentence: ");
               sentence = kb.nextLine();
               String answer = sentenceAnalyser(sentence);
               System.out.println("The given sentence is an "+answer+".");
           }else if(option.equals("probable season")) {
               double temp;
               System.out.print("\nEnter the temperature in degree Fahenheit: ");
               temp = kb.nextDouble();
               String answer = probableSeason(temp);
               System.out.println("The probable season is "+answer);
           }
           System.out.println();
       }
   }
   public static String getOption(Scanner kb) {
       int choice;
       System.out.println("\nChoose any one from below");
       System.out.println("Enter 1 for Problem 1");
       System.out.println("Enter 2 for Problem 2");
       System.out.print("Enter: ");
       choice = kb.nextInt();
       if(choice==1) {
           return "sentence analyzer";
       }else if(choice==2) {
           return "probable season";
       }
       return "unknown choice";
   }
   public static String sentenceAnalyser(String sentence) {
       /**
       * integer variable length will store length of the string sentence
       * */
       int length = sentence.length();
      
       /**
       * An char variable named lastChar will store last character of sentence string
       * */
       char lastChar = sentence.charAt(length-1);
      
       if(lastChar=='.') {
           return "declarative";
       }else if(lastChar=='?') {
           return "interrogative";
       }else if(lastChar=='!') {
           return "exclamatory";
       }
       return "unknown sentence type";
   }
   public static String probableSeason(double temp) {
       if(temp>110 || temp<-5) {
           return null;
       }
       if(temp>=90) {
           return "summer";
       }else if(temp>=70 && temp<90) {
           return "spring";
       }else if(temp>=50 && temp<70) {
           return "fall";
       }else {
           return "winter";
       }
   }
}


OUTPUT:

How many times do you want to run this program? 7

Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 1

Enter the sentence: Hello World!
The given sentence is an exclamatory.


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 2

Enter the temperature in degree Fahenheit: 45.78
The probable season is winter


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 2

Enter the temperature in degree Fahenheit: -10
The probable season is null


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 1

Enter the sentence: Are you ok?
The given sentence is an interrogative.


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 1

Enter the sentence: We are dominant on earth.
The given sentence is an declarative.


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 1

Enter the sentence: well done
The given sentence is an unknown sentence type.


Choose any one from below
Enter 1 for Problem 1
Enter 2 for Problem 2
Enter: 2

Enter the temperature in degree Fahenheit: 90
The probable season is summer

Please provide the feedback!!

Thank You!!

Add a comment
Know the answer?
Add Answer to:
i need help getting this program running Pearson Sign in Mail - Josue Velazq... CSC 15...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 14: all 5 parts must be complete to receive credit for the question    /**...

    Problem 14: all 5 parts must be complete to receive credit for the question    /** * q1: Write a public static method named q1 that takes no parameters and returns void. The * method should print all the integers from -8 to 47 to the screen. The output should be * inclusive of these end points */             /** * q2: Write a public static method named q2 that takes two ints as parameters and returns...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester *...

    /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing Java Strings * * @author *** Replace with your name *** */ public class CPS150_Lab13 { static final Scanner KBD = new Scanner(System.in); static final PrintStream OUT = System.out; // TO DO: Implement each of the following 4 methods, // using the String compareTo method: /* * lessThan(String, String) -> boolean * * method is...

  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT