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.
20 replies to this topic
#1
Posted 02 May 2011 - 09:17 AM
|
|
|
#2
Posted 02 May 2011 - 10:54 AM
What do you have so far?
#3
Posted 03 May 2011 - 12:31 AM
Sir i dont hve any idea for this program... please help me
#4
Posted 03 May 2011 - 12:37 AM
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
Posted 03 May 2011 - 12:37 AM
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
Posted 03 May 2011 - 12:38 AM
i just started thinking... please help me to comple the program
#7
Posted 03 May 2011 - 01:19 AM
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
Posted 03 May 2011 - 01:30 AM
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
Posted 03 May 2011 - 01:40 AM
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
Posted 03 May 2011 - 01:40 AM
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
{
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
Posted 03 May 2011 - 01:41 AM
Sir,
Can I get more help from your side.
Can I get more help from your side.
WingedPanther said:
What do you have so far?
#12
Posted 03 May 2011 - 04:22 AM
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()
{
}
}
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









