Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91372338
  • Price:- $50

Guranteed 36 Hours Delivery, In Price:- $50

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As