Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that prompts the user for one of the numbers 1, 2, 3, ..., 12 and outputs the corresponding month name January, February,

Write a program that prompts the user for one of the numbers 1, 2, 3, ..., 12 and outputs the corresponding month name January, February, March, ... , December.

Implementation: Create a class with a constructor that takes the number and a method that returns the month string. Make a very long string "January February March ... ", in which you add spaces such that each month name has the same length. Then use substring to extract the month you want. You will need to figure out a little arithmetic to get the correct limits for the substring.

Hints:
in your class
make a constructor to initialize the month number and the long string
make the long string (make each month 10 characters long, padded by spaces)
make an instance method getMonth() which computes the correct indices to give to substring(), then return the substring containing the correct month name.
in main
prompt user for month number
read in month number
create object passing month number to constructor
print result by calling instance method getMonth().

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

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions

Question

A theory-based prediction is called a(n) .

Answered: 1 week ago