1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
4 years ago
7

Define a class to represent a date. A date is defined by three properties: month (two digits), day (two digits), and year (4 dig

its). Include the following methods: 1) a setter function for the month to only allow numbers 1-12 2) a setter function for the day that only allows 1-31 3) a function that will print the date as month/day/year (ie 10/1/1999).
Computers and Technology
1 answer:
Delvig [45]4 years ago
8 0

Answer:

The Date class below is created using Java.

  1. public class Date {
  2.    private int day;
  3.    private int month;
  4.    private int year;
  5.    public Date(int d, int m, int y)
  6.    {
  7.        setDay(d);
  8.        setMonth(m);
  9.        this.year = y;
  10.    }
  11.    public void setMonth(int m)
  12.    {
  13.        if(m >= 1 && m <= 12)
  14.        {
  15.            this.month = m;
  16.        }
  17.        else
  18.        {
  19.            throw new IllegalArgumentException("Input Month must be between 1 - 12");
  20.        }
  21.    }
  22.    public void setDay(int d)
  23.    {
  24.        if(d >=1 && d <=31)
  25.        {
  26.            this.day = d;
  27.        }
  28.        else
  29.        {
  30.            throw new IllegalArgumentException("Input Day must be between 1 - 31");
  31.        }
  32.    }
  33.    public void printDate()
  34.    {
  35.        System.out.println(this.month + "/" + this.day + "/" + this.year);
  36.    }
  37. }

Explanation:

Line 1:

  • Create a class and name it as <em>Date</em>

Line 3-5:

  • Define three properties/attributes in the Date class which are day, month and year.
  • The data type of the properties are defined as integer

Line 7-13:

  • Create a class constructor to initialize the values for the properties (day, month and year).
  • To initialize the day and month, setDay() and setMonth() setter methods are called. This is to ensure the day and month are within the range of 1-31 and 1-12, respectively.

Line 15-25:

  • Create setMonth() setter method with one parameter m to accept one input value.

  • The setMonth() method will check the input value m to see if it is bigger or equal to 1 and less than or equal to 31 (the valid range). If not, an error will be thrown.

Line 27 - 37:

  • Create setDay() setter method with one parameter d to accept one input value.
  • The setDay() method will check the input value m to see if it is bigger or equal to 1 and less than or equal to 12 (the valid range). If not, an error will be thrown.

Line 39 - 42:

  • Create printDate() method to display the date as month/day/year (ie 10/1/1999)
  • Use Java println() method to print the class property values, month, day, and year.
  • Please note that to access the property values,  this keyword must be preceded with the property name.

Important notes:

  • This program doesn't consider the valid input range of days for Feb (1 - 28 or 29) and for those of the months with only 30 days because this is not expected by the question.  
  • Beside, the input year is also presumed to be a four digit number.

You might be interested in
The background image does not affect any cell’s format or content. _______
Korvikt [17]
Hmmm...that is true 
Here a quizlet about if you need it!
https://quizlet.com/15207805/csci-241-flash-cards/
3 0
3 years ago
Which excel feature prevents you from having to type the same thing over and over?
tamaranim1 [39]

Answer:

Explanation: Another way by which you can do it, press the Ctrl+1 key on your keyboard, Format cells dialog box will get appear. Go to Alignment tab, Click on Justify in Vertical drop down list, click on ok. This is the way by which you can prevent the text from spilling over in Microsoft Excel 2010 and 2013.

6 0
3 years ago
In a(n) ____, the programmer uses a programming language (in context free grammar) to tell the computer what to accomplish and h
Mamont248 [21]

A 5GL fifth-generation languages a programming language design to solve given problem without programmer. The user only needs to solve the problem and condition without implementing an algorithm.

Explanation:

First Generation Language

The first generation language is called low- level style because they were used at a superficial level of abstraction. First-generation language referred to as the native language.

Second Generation Language

The second-generation language is also low-level language or assembly language. The second level of language uses the concept of mnemonics for the writing program. Symbolic name are used.

Third Generation Language

The third-generation language overcomes the first and second-generation languages. Third generation language is considered as high- level language because the target is to focus on the logic of the program.

Fourth Generation Language

The language of generation required a lot of time and effort that affect programmers.The fourth-generation was developed to reduce the time, cost, and effort.

Fifth Generation Language

The programming language of this generation focuses on constraints programming. The fifth-generation programming languages are Artificial Intelligence and Artificial Neural Network.

6 0
3 years ago
A dmz is a subnet of _____________ accessible servers placed outside the internal network.
Alborosie

A dmz is a subnet of publicly accessible servers placed outside the internal network. Any service provided to users on the public internet should be placed in the DMZ network. DMZ means demilitarized zone (perimeter network) .

7 0
3 years ago
PLEASE HELP
MakcuM [25]

The answer is D: Click on Final in the Display for Review drop-down menu.

Microsoft Word can keep track of changes made words or sentences of a document. It marks the text added or removed. To turn the track changes option on, you will simply click on the Review tab and click Track Changes. To view the edited document without the Track Changes markup, Click on Final in the Tracking group for Review drop-down menu located opposite the Track Changes button.


4 0
3 years ago
Read 2 more answers
Other questions:
  • The default view in word is ____ view, which shows the document on a mock sheet of paper in the document window.
    6·1 answer
  • If you turn your volume to loud on u'r headphones can it break the sound quality of the speaker?
    9·2 answers
  • How can i do a back up on one computer and save it to the hard drive in another computer without it being seen by others on the
    9·1 answer
  • Help, please!! A file named "games.txt" exists and has 80 lines of data. You open the file with the following line of code. aFil
    6·1 answer
  • The _________ indicates the number of elements, or values, an array can hold
    14·1 answer
  • Each tab is divided into groups of related commands or buttons. T or F
    10·1 answer
  • Write the definition of a method, oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each ar
    10·1 answer
  • horseback riders, bicyclists, and skateboarders ____ the rules of right-of-way when they use the road ?
    7·2 answers
  • A nursing informatics specialist is preparing an in-service program for staff on healthcare informatics and information technolo
    13·1 answer
  • Why do we need the system requirements for Adobe photoshop?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!