|
|
Date value set to current datetime, after recall the date value is null
Output as below
D:\Example\javaux\OO>java appmotor
The engine is now on. Tue Oct 10 23:44:41 CST 2006 (Yamaha RZ350)
Engine Start date = Tue Oct 10 23:44:41 CST 2006
Detail:
Model is Yamaha RZ350
Color is Yello
Year is 2003
Engine Started on null
D:\Example\javaux\OO>
"Engine Started" should not null , should be Tue Oct 10 23:44:41 CST
2006.
What wrong as below two java program ?
import java.util.*;
import java.text.*;
class Motorcycle {
private String Model;
private String Color;
private int Year;
private Date EngineStartDate;
private boolean engineStatus = false;
void setModel (String loName) {
this.Model = loName;
}
void setColor(String loColor) {
this.Color = loColor ;
}
void setYear (int loYear) {
this.Year = loYear;
}
public String getEngineStartDate() {
return "xx";
}
void showDetail() {
System.out.println("\nDetail:");
System.out.println("\tModel is " + this.Model);
System.out.println("\tColor is " + this.Color);
System.out.println("\tYear is " + this.Year);
System.out.println("\tEngine Started on " + EngineStartDate +
"\n");
}
public void startEngine() {
if (engineStatus == true)
System.out.println("The engine is alreay on. " + EngineStartDate +
" (" + this.Model + ")");
else {
engineStatus = true;
Date EngineStartDate = new Date();
System.out.println("The engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
System.out.println("Engine Start date = " + EngineStartDate);
}
}
}
/* eof */
import java.lang.*;
/* Testing Inheritance */
class M2 extends Motorcycle {
private int speed;
public void setSpeed(int loSpeed) {
this.speed = loSpeed ;
}
public int getSpeed() {
return this.speed;
}
}
/* Main Part */
public class appmotor {
public static void main (String args[]) {
M2 m = new M2();
m.setModel ("Yamaha RZ350");
m.setColor ("Yello");
m.setYear (2003);
m.startEngine();
m.showDetail();
// m.startEngine();
// m.showDetail();
}
}
|
|
0
|
|
|
|
Reply
|
moon_ils-se (53)
|
10/10/2006 3:50:58 PM |
|
"moonhk" <moon_ils-se@yahoo.com.hk> wrote in message
news:1160495457.928202.31910@k70g2000cwa.googlegroups.com...
>
> "Engine Started" should not null , should be Tue Oct 10 23:44:41 CST
> 2006.
>
> What wrong as below two java program ?
>
[code snipped]
It might be easier for you to find the bug if you tried to make your
program as small as possible while still reproducing the problem:
http://mindprod.com/jgloss/sscce.html
For example, you can probably get rid of inheritance by getting rid of
the M2 class, and the problem will still be there.
- Oliver
|
|
0
|
|
|
|
Reply
|
owong (5281)
|
10/10/2006 4:30:33 PM
|
|
Date EngineStartDate = new Date();
delete the first word in that line. Cheers.
opalpa
opalpa@gmail.com
http://opalpa.info/
|
|
0
|
|
|
|
Reply
|
opalpa (277)
|
10/10/2006 4:41:08 PM
|
|
opalpa opalpa@gmail.com http://opalpa.info wrote:
> Date EngineStartDate = new Date();
>
> delete the first word in that line. Cheers.
>
> opalpa
> opalpa@gmail.com
> http://opalpa.info/
try to OK Now. Thank a lot. What problem ?
Change as below
public void startEngine() {
if (engineStatus == true)
System.out.println("\nThe engine is alreay on. " + EngineStartDate
+ " (" + this.Model + ")");
else {
engineStatus = true;
EngineStartDate = new Date(); /* New */
System.out.println("\nThe engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
System.out.println("Engine Start date = " + EngineStartDate);
}
}
}
D:\Example\javaux\OO>java appmotor
The engine is now on. Wed Oct 11 01:26:06 CST 2006 (Yamaha RZ350)
Engine Start date = Wed Oct 11 01:26:06 CST 2006
Details:
Model is Yamaha RZ350
Color is Yello
Year is 2003
Engine Started on Wed Oct 11 01:26:06 CST 2006
Speed is 100 mph
Year is 2003
Engine Started on null
Speed is 100 mph
D:\Example\javaux\OO>
|
|
0
|
|
|
|
Reply
|
moon_ils-se (53)
|
10/10/2006 5:30:05 PM
|
|
> try to OK Now. Thank a lot. What problem ?
>
> Change as below
>
> public void startEngine() {
> if (engineStatus == true)
> System.out.println("\nThe engine is alreay on. " + EngineStartDate
> + " (" + this.Model + ")");
> else {
> engineStatus = true;
> EngineStartDate = new Date(); /* New */
> System.out.println("\nThe engine is now on. " + EngineStartDate +
> " (" + this.Model+ ")");
> System.out.println("Engine Start date = " + EngineStartDate);
> }
> }
> }
>
These are all the changes? Did you change anything else?
> D:\Example\javaux\OO>java appmotor
>
> The engine is now on. Wed Oct 11 01:26:06 CST 2006 (Yamaha RZ350)
> Engine Start date = Wed Oct 11 01:26:06 CST 2006
>
> Details:
> Model is Yamaha RZ350
> Color is Yello
> Year is 2003
> Engine Started on Wed Oct 11 01:26:06 CST 2006
> Speed is 100 mph
> Year is 2003
> Engine Started on null
> Speed is 100 mph
> D:\Example\javaux\OO>
Using your source from original post: Its main method call showDetail()
once. The above output has more lines. The first problem looks
resolved. Repost source code.
opalpa
opalpa@gmail.com
http://opalpa.info/
|
|
0
|
|
|
|
Reply
|
opalpa (277)
|
10/10/2006 5:57:54 PM
|
|
Source Code as below
I add some coding
such as in
public void showDetails() {
// calls the superclass by prefixing it with a super
super.showDetails();
// Add New Item
System.out.print("\tSpeed is " + speed + " mph");
}
Also, do you how to call Motorcycle.showDetails() ?
Motorcycle.java
============
import java.util.*;
import java.text.*;
class Motorcycle {
private String Model;
private String Color;
private int Year;
private Date EngineStartDate;
private boolean engineStatus = false;
void setModel (String loName) {
this.Model = loName;
}
void setColor(String loColor) {
this.Color = loColor ;
}
void setYear (int loYear) {
this.Year = loYear;
}
public void showDetails() {
System.out.println("\nDetails:");
System.out.println("\tModel is " + this.Model);
System.out.println("\tColor is " + this.Color);
System.out.println("\tYear is " + this.Year);
System.out.println("\tEngine Started on " + EngineStartDate );
}
public void startEngine() {
if (engineStatus == true)
System.out.println("\nThe engine is alreay on. " + EngineStartDate
+ " (" + this.Model + ")");
else {
engineStatus = true;
EngineStartDate = new Date();
System.out.println("\nThe engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
}
}
}
/* eof */
appmotor.java
==========
import java.lang.*;
/* Testing Inheritance */
class M2 extends Motorcycle {
private int speed;
public void setSpeed(int loSpeed) {
this.speed = loSpeed ;
}
public int getSpeed() {
return this.speed;
}
public void showDetails() {
// calls the superclass by prefixing it with a super
super.showDetails();
// Add New Item
System.out.print("\tSpeed is " + speed + " mph");
}
}
/* Main Part */
public class appmotor extends Thread {
public static void main (String args[]) {
M2 m = new M2();
m.setModel ("Yamaha RZ350");
m.setColor ("Yello");
m.setYear (2003);
m.setSpeed(100);
m.startEngine();
m.showDetails();
try {
sleep (4000);
} catch ( InterruptedException e) {}
m.startEngine();
m.showDetails();
}
}
|
|
0
|
|
|
|
Reply
|
moon_ils-se (53)
|
10/11/2006 4:45:00 AM
|
|
|
5 Replies
23 Views
(page loaded in 0.081 seconds)
Similiar Articles: How to check whether malloc has allocated memory properly in case ...If it returns non-NULL, it must return a value that is distinct from all the other values ... to return a non-NULL value ... After >all, what I most recall as near universal ... How best to detect duplicate values in a column? - comp.databases ...Here's the current form (including question+answers ... (May I suggest sticking the date and time into each ... variables >that I call (and then provides a NULL value for ... basic questions about the leapsecond - comp.protocols.time.ntp ...I don't recall just when the last ... is merely that they are set before 23:59 and cleared after ... command, by checking the current TAI offset, looking at the date of ... Converting number to std::string ("itoa()" ) - comp.lang.c++ ...... there is normally only one way of representing a value as ... like "twenty", "thirty", etc.); if there was a null ... all, 1000 is written "mille" except in a year in a date ... Sockets in gfortran? - comp.lang.fortran... the original Unix versions date back 2 ... ported to Solaris 2, and I think I recall ... * Normal return value for child is 0. * Positive return values are errors in parent. Quickest way to bulk copy many files from one disk cluster to ...I seem to recall an example of this in the ... timestamps of symbolic links were set to the current date ... set other block size than 10k, useful values e.g. bs=1m fs= set ... NMEA ref.clock better than my ISP's timeserver? - comp.protocols ...After first trying the Haicom HI-204III claiming to have ... I.e. about 1/3 of the total Oslo stock exchange value. ... to this address will be added to the BlackLists <Null ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... Sampling: What Nyquist Didn't Say, and What to Do About It - comp ...Edit | Preferences | Rendering set to smooth ... harmonics, specifically reporting the RMS value of ratty current ... Recall that your document is not one long string of ... Enter Null Values for DateTime Column of SQL ServerInserting a null value to the DateTime Field in SQL Server is ... Current Affairs Custom Controls C# Databases ... cmd.Parameters["@Date"].Value = DateTime.Parse(txtDate.Text); Set value date/time field to null.I tried various ways to set the value of the end date to “”, null and ... it will fail... there is no current ... the international parsing of date with DateTime ... 7/15/2012 10:07:16 PM
|
|
|
|
|
|
|
|
|