Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3951280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:42:44+00:00 2026-05-20T01:42:44+00:00

I’m currently working on a lab for class and we were told to make

  • 0

I’m currently working on a lab for class and we were told to make a method in the main form called “DisplayInformation. that accepts a parameter of type Time and then displays the Time objects information” Which doesn’t sound difficult to me but we’re told to use 2 buttons to access this method. One just goes to the base class and gets the current time and returns it. The other is suppose to go to a derived class. And this is where my problem begins.

private void btnDisplayTime_Click(object sender, EventArgs e)
{
    DisplayInformation(time1);


} 

And this is the DisplayInformation function I’m not sure about:

private string DisplayInformation (Time zone)
        {
            time1 = zone;
            time1.displayTime();
           // extTime1.displayTime();
            return "okay";

        }//end of DisplayInformation

When i call DisplayInformation with the first button it’ll go just fine.
And if i make a call from the second button to this method it’ll be fine as well. But i need to be able to pick and choose which class i go to. It’s difficult to explain really.
I just need to be able to call from each button to that method and get a different output depending on the button. I’m not sure if this would just be an if statement or what.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CIS247A_Week_4_Lab_BREWER
{
class Time
{
    private const int MIN_HOUR = 0;
    private const int MAX_HOUR = 24;
    internal int hour;
    internal int minute;

    public Time()
    {
        hour = 12;
        minute = 00;
    }//end of Time

    public Time(int Hour, int Minute)
    {
        hour = Hour;
        minute = Minute;
    }//end of Time

    public int incrementHour(int step)
    {
        if (step > 0 && hour < 24)
        {
            //step = step % hour;
            hour = (hour + step) % 24;

            return hour;
        }//end of if

        else
        {
            MessageBox.Show("Please enter a positive number.");

            return 0;
        }//end of else
    }//end of incrementHour

    public int incrementMinute(int step)
    {
        if (step > 0 && minute < 60)
        {
            minute = (minute + step) / 60;

            return 0;
        }//end of if

        else if (step < 0)
        {
            MessageBox.Show("Please enter a positive number.");
            minute = 0;
            return 0;
        }//end of else if
        else
        {
            MessageBox.Show("Unknown error.");
            return 0;
        }
    }//end of incrementMinute
    public virtual string displayTime()
    {
        DateTime time = DateTime.Now; // Use current time
        string format = "MMM ddd d HH:mm yyyy"; // Use this format
        MessageBox.Show(time.ToString(format)); // Write to console

        return time.ToString(format);
    }//end of displayTime

    public int Hour
    {
        get { return hour; }


        set
        {
            if (value < MIN_HOUR)
            {
                hour = 0;
                MessageBox.Show("Hour value " + value.ToString() + " cannot be negative. Reset to " + MIN_HOUR.ToString(),
                "Invalid Hour", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //take the modulus to ensure always less than 24 hours
                //works even if the value is already within range, or value equal to 24
                hour = value % MAX_HOUR;
            }
        }
    }
    public int Minute
    {
        get { return minute; }
        set
        {
            if (value < 0)
            {
                minute = 0;
                //MessageBox.Show("cannot be negitive" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                minute = value % 60;
            }


        }
    }
}//end of Time Class
}//end of Namespace

And the extendedtime class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CIS247A_Week_4_Lab_BREWER
{

class ExtendedTime : Time
{

    private string timeZone{get; set;}

    public ExtendedTime() : base()
    {
        timeZone = "CDT";

    }//end of ExtendedTime

    public ExtendedTime(int Hour, int Minute, String TimeZone) :base(Hour, Minute)
    {

        timeZone = TimeZone;
    }//end of ExtendedTime

    public override string displayTime()
    {
        //return base.displayTime();
        MessageBox.Show(base.displayTime() + timeZone);
        return base.displayTime() + timeZone;
    }//end of DisplayTime

}//end of ExtendedTime class

}//end of namespace

And just for time sake the section of the form i’m working on:

public partial class frmTime : Form
    {
        Time time1;
        ExtendedTime extTime1;


    public frmTime()
    {
        //DateTime Ctime = DateTime.Now; // Use current time
       // Ctime = new DateTime();
       // label1.Text = Ctime.ToString();
        InitializeComponent();
        time1 = new Time();
        extTime1 = new ExtendedTime();
    }


    private void DisplayInformation (Time zone)
    {
        time1 = zone;
       // time1.displayTime();
        extTime1.displayTime();
        //return "okay";

    }//end of DisplayInformation
    //exit Button (btnExit)
    private void btnExit_Click(object sender, EventArgs e)
    {
        Application.Exit();//closes the program

    }

    private void btnDisplayTime_Click(object sender, EventArgs e)
    {
        DisplayInformation(time1);


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:42:45+00:00Added an answer on May 20, 2026 at 1:42 am

    In your DisplayInformation class if you are passing in a Time object from one click handler and an extTime object from the other handler then you should be able to just call the displayTime method.

    private void DisplayInformation (Time zone)
    {
        zone.displayTime();
    }
    

    on the Time one it will obviously call the base method. On the extTime one despite the fact you are treating it as a Time object it will call the overridden method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.