View the step-by-step solution to:

in java: Design and implement an application that reads an integer value representing a year from the user.

in java:



1. Design and implement an application that reads an integer value representing a year from the user. The purpose of the program is to determine if the year is a leap year (and therefore, has 29 days in February) in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100, but not 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is not a leap year because it is divisible by 100, but the year 2000 is a leap year because even though it is divisible by 100, it is also divisible by 400. Produce an error message for any input values less than 1582 (the year the Gregorian calendar was adopted).

2. Implement a method called allEven that takes an integer parameter end. The method returns the sum of all even integers between 2 and end, inclusive. Return -1 if the end value is less than 2.

3. Implement a method named outlier that will generate a random number from 1 – 30. It will return true if the number is less than 10 or greater than 20.

4. Implement a method named digits that takes one integer parameter named num. The method will return the number of digits in the integer.
You CANNOT use any methods of the String or Integer Wrapper Classes

Example: (if the integer is 342712) the method will return: 6 // (number of digits)
NOTE: Remember to put all methods in a class for testing (As you did in Homework 4).

5. [20 points] Define a class MonetaryCoin with 2 instance data, a string face, which can be “head” or “tail” and an int value that represents the monetary value of the coin. The following method should be included in the class:
- a default constructor
- a constructor that takes 2 parameters to initialize instance data
- a getter for each instance data
- a setter method for each instance data
- a toString method that returns the coin’s face and monetary value
- a method flip() that randomly sets the face to either “head” or “tail”
- a method add() that takes another MonetaryCoin parameter and returns the sum of their monetary values.
- an equals() method that compares two monetary coins and returns true if they have same face and value and false otherwise.

6. Using the MonetaryCoin class defined above, design and implement a driver class called FlipRace whose main method creates two MonetaryCoin objects, with face and value entered from the keyboard. It then continually flips them both to see which coin first comes up heads three flips in a row. Continue flipping the coins until one of the coins wins the race, and consider the possibility that they might tie. Print the results of each turn, and at the end print the winner and total number of flips that were required.

7. Using the MonetaryCoin class defined above, design and implement a driver class called FlipApp whose main method crates two MonetaryCoin objects, with face and same monetary value entered from the keyboard. The method flips the coins 100 times and prints to the screen the total number of times both coins were equal. It should then print the information about each coin as well as their sum.

8. Using the PairOfDice class from previous homework, design and implement an application that rolls a pair of dice 1000 times, counting the number of box cars (two sixes) that occur.
Sign up to view the entire interaction

Top Answer

Here is the final program for the assignment. Please let me know if this... View the full answer

FlipApp.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author tellytopia
*/
public class FlipApp {
public static void main(String args) {
int...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online