Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can some one please help me with this Coding? We are using Eclipse so it would have to be done in Eclipse. Also if you

Can some one please help me with this Coding? We are using Eclipse so it would have to be done in Eclipse. Also if you could try to explain what is going on that would be much helpful and really appriciated !!

COSC 1174 Chapter 10 Lab Programming Assignment

Design and implement a MyDate class. The class contains:

The data fields year, month, and day that represent a date. The variable month is 0-based, meaning that a value of 0 is for January.

A no-arg constructor that creates a MyDate object for the current date.

A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970 in milliseconds.

A constructor that constructs a MyDate object with the specified year, month, and day.

Three getter methods for the data fields year, month, and day, respectively.

A method named setDate(long elapsedTime) that sets a new date for the object using the elapsed time.

The UML diagram for this object will be discussed in class. The test client program is included below. Please develop your Java class and use the test program to ensure correct results. Upload both the test client program and your Java class to Blackboard.

import java.util.*;

public class TestMyDate {

public static void main(String[] args) {

MyDate date = new MyDate();

System.out.println("year: " + date.getYear());

System.out.println("month: " + date.getMonth());

System.out.println("day: " + date.getDay());

date = new MyDate(561555550000L);

System.out.println("year: " + date.getYear());

System.out.println("month: " + date.getMonth());

System.out.println("day: " + date.getDay());

}

}

Use the GregorianCalendar class from chapter 9 (Exercise 9.5) to simplify your coding. You may have to look this class up in the Java documentation (online). The elapsed time value specified above should produce a date of October 18, 1987. Here is what your no-arg constructor for the class might look like using the GregorianCalendar class.

MyDate() {

GregorianCalendar date = new GregorianCalendar();

// Find year, month, and day from date.

year = date.get(Calendar.YEAR);

month = date.get(Calendar.MONTH);

day = date.get(Calendar.DAY_OF_MONTH);

}

Tip: Note that the GregorianCalendar class inherits the Calendar class, so all methods of Calendar are available to GregorianCalendar.

Design and implement a class named MyInteger. The class contains:

An int data field named value that stores the int value represented by this object.

A constructor that creates a MyInteger object for the specified int value.

A getter method that returns the int value.

The methods isEven(), isOdd(), isPrime() that return the true value if the value in this object is even, odd, or prime, respectively.

The static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.

The static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.

The methods equals(int) and equals(MyInteger) that return true if the value in this object is equal to the specified value.

Draw the UML diagram for the MyInteger class and submit that in a Word document to Blackboard as well as the .java class file for your program. A sample of the client test program is included below. Please use your own values for integers. submit your client test program version to Blackboard along with your other files.

public class TestMyInteger {

public static void main(String[] args) {

MyInteger n1 = new MyInteger(5);

System.out.println("n1 is even? " + n1.isEven());

System.out.println("n1 is prime? " + n1.isPrime());

System.out.println("15 is prime? " + MyInteger.isPrime(15));

MyInteger n2 = new MyInteger(24);

System.out.println("n2 is odd? " + n2.isOdd());

System.out.println("45 is odd? " + MyInteger.isOdd(45));

System.out.println("n1 is equal to n2? " + n1.equals(n2));

System.out.println("n1 is equal to 5? " + n1.equals(5));

}

}

**Here is some information my Instructor gave us to further help us

Here is a coding snippet to maybe help (if you need it) with the MyDate class in our lab assignment. Remember, you can use the GregorianCalendar class so that you have access to some of the methods to use in this assignment.

If you recall, there were three constructors specified. The no-arg constructor was provided in the assignment. Here is the constructor that takes an elapsed time as an argument and converts that to a month, day, and year. You only have one constructor left to provide where the month, day, and year are passed as arguments.

MyDate(long elapsedTime) { GregorianCalendar date = new GregorianCalendar(); date.setTimeInMillis(elapsedTime); // Find year, month, and day from date. You write your own code to replace the out-dated get methods year = date.get(Calendar.YEAR); month = date.get(Calendar.MONTH); day = date.get(Calendar.DAY_OF_MONTH); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

Students also viewed these Databases questions

Question

In certain functions more than others?

Answered: 1 week ago