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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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