What is an integer overflow error

Assignment Help Basic Computer Science
Reference no: EM13802331

Questions:

Submit your answers to these questions as a text file named "Questions.txt". You should not need to write more than a few sentences for each answer.

  1. Many sports and games have constants embedded in their rules. For example, baseball has 9 innings, 3 outs per inning, 3 strikes in an out, and 4 balls per walk. We can program Java named constants for a program involving baseball as follows:
      public static final int INNINGS = 9;
      public static final int OUTS_PER_INNINGS = 3;
      public static final int STRIKES_PER_OUT = 3;
      public static final int BALLS_PER_WALK = 4;
    Select a game or sport that you are familiar with, and give at least three lines of Java code initializing the constants for a program involving that game or sport. You should use conventional Java naming conventions for constants. Also include as a comment, an explanation of the constants you have chosen (e.g., "baseball has 9 innings, 3 outs per inning...").
  2. Consider the following two boolean expressions, and explain why they each are probably not what the programmer intended.
      a. ((x > 10)|| (x < 100))

      b. ((2 < 5) && (x < 100))
  3. Complete a program memory trace of your solution to Lab 3 (Conversation.java). You should also turn in your code for Lab 3 again (to be compared to your trace). For your trace, assume the user enters the sentence: "When it rains, I hate getting wet."
  4. Now consider your solution to Lab 4 (Approximation.java). Think about the six boolean operators. What can you conclude about using floating point numbers in boolean expressions, based on what you saw when you ran the program?
  5. Review your answer to the Type Casting Activity (especially question 5 in Model 1). Explain in your own words:
      a. What is an integer overflow error?

      b. What happens when an integer overflow error occurs? Describe the behavior of the program.

      c. Why is multiplication particularly risky for integer overflow errors?

Program 1: Write a program (TypeCast.java) that demonstrates type casting of double values by performing the following tasks:

Use Scanner to read a floating-point value into a variable called number.
Type cast number to an int value and store the result in a variable called integer.
Display number and integer, clearly labeled.
Typecast number to a byte value and store the result into the result other.
Display number and other clearly labeled.

Try your program on positive and negative values of number that range from 2e-11 to 2e11. What can you conclude?

Program 2:

Write a program (DateCheck.java) that reads a String from the keyboard using the nextLine method, and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid.

The input date will have the format mm/dd/yyyy (m/d/yyyy is also valid, as are m/dd/yyyy and mm/d/yyyyy). A valid year value must be four digits. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. April, June, September and November each have 30 days. February has 28 days except for leap years when it has 29. A leap year is any year that is divisible by 4, but not divisible by 100 unless it is already divisible by 400. All remaining months have 31 days each.

Java hints:

You cannot use the nextInt method to read in the String.
You will need two versions of each date field (month, day, and year): one String variable and one int variable.
You will need to isolate the mm, dd, and yy as Strings first.
To convert Strings to ints, use the Integer.parseInt method, which takes a String as an argument and returns the corresponding int.
You should use many if-statements and many boolean expressions to check if the date is valid.
For the homework assignment, you only need to catch errors where the numeric values of mm, dd, or yyyy are invalid. All other errors would be caught as extra credit.

Don't forget to write this program in steps, and compile and test after each step. You may want to write down your steps before beginning.

Reference no: EM13802331

Questions Cloud

Dna sequencing and replication : DNA sequencing and replication
Evolution of presidential powers is a positive : Have Presidential powers evolved over time, or were they a result of a major event. Explain in detail. Do you believe that the evolution of Presidential powers is a positive for our democracy, or does it infringe upon the duties of the legislature
Concept of goodness of product fit : 1. Define and explain the NPS formula and how it applies to customer satisfaction. 2. Explain the concept of goodness of product fit.
Distinguish the difference between plants and animals : distinguish the difference between plants and animals
What is an integer overflow error : What is an integer overflow error? What happens when an integer overflow error occurs? Describe the behavior of the program. Why is multiplication particularly risky for integer overflow errors
Provide example from information that you learne about china : Provide one example from the information that you learned about China to support your response.
Managing the development of large software systems : Write paper on managing the development of large software systems
Prepare research for a project scuba and advancements : Prepare research for a project Scuba AND advancements OR technology. Which of the following best describes the likely results of this search when following Boolean logic?
Explain over-representation of bilingual children : Explain over-representation and under-representation of bilingual children in Special Education classes. What do these terms mean, where are we heading with bilingual children in Special Education?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What are the pro and con of digital rights managment

What are the pro's and con's of Digital Rights Managment?

  Write a computer program that calculates the average

The following is a list of 20 exam scores. Write a computer program that calculates the average of the top 8 scores.

  What is the improvement factor resulting

what is the improvement factor resulting from the use of the cache assuming that the LRU algorithm is used for block replacement?

  Application communications plan

Application Communications Plan

  What are the benefits of using tangible interfaces

What are the benefits of using tangible interfaces compared with other interfaces like GUI, pen-based or gesture?

  Analyze the fundamental impact of it architecture

Ascertain the importance of information management for the company or industry that you have chosen. Analyze the fundamental impact of IT architecture or enterprise architecture on information management for your chosen company or industry.

  Find the values of condition flags

Find the values of condition flags N, Z, V, and C in the CCR register after the executive of each of the following instructions, given that [A] = $50 and the condition flags are N =0, Z =1, V =0, and C =1. a) suba #40 b) tsta c) adda #$50 d) lsra ..

  Describe why suggestion of connecting by twisted pair cable

Describe why you would suggest connecting all current and new client computers using twisted pair cable instead of staying with the current coax wiring structure.

  Class that tests all the methods in the class

Write a test program for each class that tests all the methods in the class.

  Explaining cash-drawer management concept

Explain in scholarly detail cash-drawer management concept and its relationship to departmental Budget vs. Actual control process.

  How to convert power to decimal

How to convert 82 to the 16th power to decimal

  Identify and describe any potential ethical issues

Identify and describe any potential ethical issues that could arise in connection with the new architecture.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd