Results 1 to 6 of 6
- 08-12-2010, 10:59 PM #1
Error when using String.format method
Hi,
Hopefully I've posted this question in the right forum. I'm new (Obviously) so please bare with me.
I'm trying to create a subclass that contains a public String toString. But when trying to use the method "return String.format(...) I'm getting an error stating,
" cannot find symbol,
symbol: method format(java.lang.String,java.lang.String,doubl,jav a.lang.String,double)
Location: class java.util.Scanner"
I've imported a util.Scanner and created a constructor for it. I've also tried to use a util.toString and it still doesn't work. I've added the code for the subclass below. Any detials or help would be appreciated.
Java Code:package program3; import java.util.Scanner; import java.util.*; import java.io.PrintStream; public class Total_RestockFee extends LP { Scanner scanner = new Scanner(System.in); private double RestockFee; private double Total; Total_RestockFee(String LPTitle, double LPItemNumber, double LPUnitPrice, double LPStockQty, double RestockFee, double Total){ //explicit call to super super (LPTitle, LPItemNumber, LPUnitPrice, LPStockQty); setTotal(Total); setRestockFee(RestockFee); } public double getRestockFee() { return RestockFee; } public void setRestockFee(double RestockFee) { this.RestockFee = (RestockFee * .05); } public double getTotal() { return Total; } public void setTotal(double Total) { this.Total = Total; } @Override public String toString(){ return String.format("%s: %.2f: \n%s: %.2f \n","Restock Fee: $", RestockFee, "Total: $", Total) ; //String.format("%.2f\n%s: %.2f\n%s", "Restock Fee:$ ", RestockFee, "Total:$ ", Total); } }
BenLast edited by Fubarable; 08-12-2010 at 11:10 PM. Reason: Moderator Edit: Code tags added
-
String#format has only been around since Java 1.5. You're possibly compiling with 1.4 or at a setting of 1.4 compliance level.
- 08-13-2010, 07:27 AM #3
String.format error
Hi,
Thanks for the response. I looked at my Java and I'm showing JRE 1.6.0.21. Any additional ideas?
-
This may not be enough info, and I'm not giving up on my idea so readily. How are you compiling it? Command line? If so, show your command line. IDE such as NetBeans or Eclipse? If so, then you had better check the IDE documentation to see how you set the Java compiler compliance level and if 1.4 or lower, increase it to 1.6.
- 08-13-2010, 07:52 AM #5
First if you have error message copy and paste don't write it.
next,
" cannot find symbol,
symbol: method format(java.lang.String,java.lang.String,doubl,jav a.lang.String,double)
Location: class java.util.Scanner"
- 08-13-2010, 12:19 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
Similar Threads
-
Text/String format..??
By Neullson in forum New To JavaReplies: 14Last Post: 07-23-2010, 09:51 AM -
Help with checking for a certain format in a String
By SteroidalPsycho in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:56 AM -
format content of String[]
By eponcedeleon in forum Advanced JavaReplies: 9Last Post: 02-23-2010, 06:12 AM -
String.format not in javadoc
By ortollj in forum New To JavaReplies: 3Last Post: 11-08-2009, 06:14 PM -
Help with Format.justify method
By lenny in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 07:29 AM
Bookmarks