This is the question – Write

This is the question –

Write an application that prompts a user for a month, day, and year. Then display the appropriate message:

  1. Y is not this year
  2. M was a month earlier this year
  3. M is a month later this year
  4. M is this month

This is the code I have for it so far –

import java.util.*;
import java.time.*;
public class PastPresentFuture {
    public static void main (String args[]) {
        LocalDate today = LocalDate.now();
      LocalDate enteredDate;
      int mo, da, yr;
      int todayMo, todayDa, todayYr;
      Scanner input = new Scanner(System.in);
      System.out.print(“Enter a month >> “);
      mo = input.nextInt();
      System.out.print(“Enter a day >> “);
      da = input.nextInt();
      System.out.print(“Enter a year (four digits) >> “);
      yr = input.nextInt();
    }
}

 

This is the question – Write

This is the question –

Write an application that displays a series of at least eight student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student.

Create an Exception class named GradeException that contains a static public array of valid grade letters (A, B, C, D, F, and I) that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display the message Invalid grade. In addition, store an I (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades.

Code I was given –

public class GradeException extends Exception {
    public GradeException(String string) {
    }
}
 
 
import java.util.*;
public class TestGrade {
    public static void main(String args[]) throws Exception {
        Scanner input = new Scanner(System.in);
        int[] ids = {1234, 1245, 1267, 1278, 2345,
                     1256, 3456, 3478, 4567, 5678
                    };
        char[] grades = new char[10];
        String gradeString = new String();
        final int HIGHLIMIT = 100;
        String inString, outString = “”;
        int flag = 0;
        for (int x = 0; x < ids.length; ++x) {
            System.out.println(“Enter letter grade for student id number: ” + ids[x]);
            inString = input.next();
            grades[x] = inString.charAt(0);
            // Write your code here
        }
        for (int x = 0; x < ids.length; ++x)
            outString = outString + “ID #” + ids[x] + ”  Grade ” +
                        grades[x] + “\n”;
        System.out.println(outString);
    }
}

This is the question –  Write

This is the question – 

Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays the message Can’t take square root of negative number.

Code I was given –

import java.util.*;
public class SqrtException {
    public static void main(String[] args) throws ArithmeticException {
        // Write your code here
    }
}

This is the question –  Write

This is the question – 

Write an application in which you declare an array of eight first names. Write a try block in which you prompt the user for an integer and display the name in the requested position. Create a catch block that catches the potential ArrayIndexOutOfBoundsException thrown when the user enters a number that is out of range. The catch block also should display the error message Subscript out of range.

Code I was given –

import java.util.*;
public class BadSubscriptCaught
{
   public static void main(String[] args)
   {
      String[] names = {“Ariel”, “Brad”, “Clifford”, “Denise”, “Emily”,
        “Fred”, “Gina”, “Henry”};
      Scanner keyboard = new Scanner(System.in);
      int number;
     
      // your code here
   }
}

This is the question – Write

This is the question –

Write a program that inserts parentheses, a space, and a dash into a string of 10 user-entered numbers to format it as a phone number. For example, 5153458912 becomes (515) 345-8912. If the user does not enter exactly 10 digits, display an error message. Continue to accept user input until the user enters 999.

This is the code I have – However it isn’t seeming to accept my output. It doesn’t like what I have for some reason – 
 
import java.util.*;
public class PhoneNumberFormat {
    public static void main(String[] args) {
        // Write your code here  //Create an instance of Scanner class

     Scanner keyboard=new Scanner(System.in);

     //declare string data type variables

     String phoneNumber= “”;

     String formattedPhoneNumber=””;

     /*Run the loop infinitely until user enters 999 to exit from program*/

     while(true)

     {

       System.out.println(“Enter phone number: “);

       phoneNumber=keyboard.nextLine();

       //exit from the program if enters 999

       if(phoneNumber.equalsIgnoreCase(“999”))

      

         System.exit(0);

         if(phoneNumber.length() < 10)

         System.out.println(“Invalid phone number .”);

         else {

           /* append the ( +xxx++) three characters to formattedPhoneNumber */

           formattedPhoneNumber+= “(” + phoneNumber.substring(0, 3) + “)”;

           //append next three characters

           formattedPhoneNumber+=phoneNumber.substring(3, 6);

           formattedPhoneNumber+=”-“;

           /* Then append rest of the phoneNumber to the formattedPhoneNumber */

           formattedPhoneNumber+= phoneNumber.substring(6, phoneNumber.length());

           //print the formatted phone number

           System.out.println(formattedPhoneNumber);

           }//end of else case

       }

     }

   }
 
This is what the program is showing as it counts it wrong – 
Test Case Incomplete

PhoneNumberFormat 2061234567

Input 
2061234567
999
 
Output
Enter phone number:
2061234567
(206)123-4567
Enter phone number:
999
 
Results

(206) 123-4567 (Marked in red because of everything showing in the results)
Expected Output

(206) 123-4567
 

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more