There are LOTS of errors in the code as presented. These are the ones I spotted.
public class Date{
Problem: you are missing package declaration means this will be in the default package. That's a bad idea.
Problem: you are using a class name that is the same as commonly used classes in the standard class library. That's a bad idea.
public Date(String inString){
String s = inString;
String b;
b.printThis(s);
Error: The code attempts to invoke a method in the String API called printThis(...)
. No such method exists. You should probably get rid of b
and just call printThis(s)
Error: The code attempts to use an uninitialized local (b
) and this will give a compilation error (if you "fixed" the previous error by changing the type of b
to something that did have a printThis
method).
Problem: It is bad practice for a constructor to invoke a method on the object being constructed if there is any possibility that it might be overridden in a subclass. The problem is that the overriding method (from the subclass) might be called on the object before the superclass initialization has completed. It is safe to call static
or private
methods.
}
public void printThis(getString) {
Error: There is a syntax error in the declaration. Change getString
to String getString
.
Problem: The choice of parameter name is (IMO) nonsensical. What is a "get string"???
System.out.printf(System.out.printf(
new SimpleDateFormat("MM/dd").format(
new SimpleDateFormat("MM/dd").parse(getString) ) );
Error: Compilation error: the parentheses don't balance.
Error: Compilation error: the first argument to printf
must be a String
or a Locale
. In your code, the first argument in the outer call is a PrintStream
instance.
Error: System.out.printf(System.out.printf(
is nonsensical. You almost certainly should use just System.out.println
or System.out.print
. If you do use a printf
method you have to supply a format string in the syntax specified in the PrintStream
javadocs. (This is NOT the same as the syntax used for date formats!!!)
}
Error: missing '}' to complete class.
Problem: Your code style needs a lot of work. If you can swear on a bible that nobody else is ever going to have to read your code (!), then I suppose its OK. Otherwise, this kind of stuff is unacceptable. If this was homework, I'd dock you 50% of your marks straight off for making no attempt to get the style correct.
SimpleDateFormat
s. You are reading a string inMM/dd
into a date and then formatting itMM/dd
010101
button while the text is selected.