Jump to content

Constructor

- - - - -

  • Please log in to reply
20 replies to this topic

#1
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Please help me for the following...

Define a class time with the following members
class name : time
Member Variables---
hh to store hour value
mm to story minute
ss to store second
Member Method :
Default Constructor -- to initialize the member variables by default value zero.

Parameterized constructor -- to accept a time into a 24 hours format as string and initialize the member variables.

Boolean validate() to check whether the time is valid or not.
void display to display the time in 12 hrs format.
Include the main function to create the object of the class to use the class to check if the time is valid or not.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Sir i dont hve any idea for this program... please help me

#4
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
Do you know how to declare a class?

public class Car

{

private int field1;

private int field2;

private String field3

}

I dont think someone in programming dont know this therefore if you dont it means something, i.e learn how its done.

#5
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
i just able to do this...


public class time

{

int hh;

int mm;

int ss;

    time()

    {

        hh = 0;

        mm = 0;

        ss = 0;

    }

    Boolean validate()

    {

     }

     void display()

     {

        }

}



#6
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
i just started thinking... please help me to comple the program

#7
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
yes sir i. and perhaps there should be a ; after 3rd variable field3 i.e., private String field3;

Mozana said:

Do you know how to declare a class?

public class Car

{

private int field1;

private int field2;

private String field3

}

I dont think someone in programming dont know this therefore if you dont it means something, i.e learn how its done.


#8
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
So i don't see what the problem is because all you have to do is create a class with a few members, read input and validate and I dont there any of those should be a problem, unless maybe you want to tell me what exactly is it you want help with. It seems I was replying while you were also posting something on this thread.

#9
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
I have done the code as follows... please help me

public class time

{

int hh;

int mm;

int ss;

    time()

    {

        hh = 0;

        mm = 0;

        ss = 0;

    }

    Boolean validate()

    {

     }

     void display()

     {

        }

}

Mozana said:

So i don't see what the problem is because all you have to do is create a class with a few members, read input and validate and I dont there any of those should be a problem, unless maybe you want to tell me what exactly is it you want help with. It seems I was replying while you were also posting something on this thread.


#10
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
if (you are going to have three individual read statements for the hh , mm and ss you will not need a delimeter and you can use)
{
Scanner ScannerObject = new Scanner(System.in);
ScannerObject.nextInt();
}
else
{
you might want to use a stringbuilder object
}

your validate() will declare a variable isTrue = true;
if(hh > 24 )// make isTrue false
if(mm > 60)//make isTrue false
if(ss > 60)//change isTrue false
//none of the above maybe less than 0 and fianally return isTrue

Edited by Mozana, 03 May 2011 - 01:42 AM.
ommitted something


#11
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Sir,
Can I get more help from your side.

WingedPanther said:

What do you have so far?


#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

arunjib said:

i just able to do this...

public class time
{
int hh;
int mm;
int ss;
    time()
    {
        hh = 0;
        mm = 0;
        ss = 0;
    }
    Boolean validate()
    {
     }
     void display()
     {
        }
}
OK, you have the skeleton of your class.
Now, you need to add a second version of time() that accepts three parameters.
You need to add logic to validate (check things like hh<24 and hh>=0)
You also need to create the standard static int main so you can do testing.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users