Results 1 to 5 of 5
Thread: NumberFormat is abstract?
- 03-27-2009, 03:52 AM #1
NumberFormat is abstract?
Hi yes, I am trying to format some numbers in java program but i get error message
Documents\Java\PHotel.java:42: java.text.NumberFormat is abstract; cannot be instantiated
NumberFormat nf = new NumberFormat();
^
1 error
Tool completed with exit code 1
does anyone know whats going on here?I've got an idea--an idea so smart that my head would explode if I even began to know what I'm talking about.
- 03-27-2009, 03:58 AM #2
Yes. Look at the Methods Summary sexction of the NumberFormat class api. It contains some static methods for obtaining instances of NumberFormat, eg,
Java Code:NumberFormat nf = NumberFormat.getInstance();
- 03-27-2009, 04:28 AM #3
I have NumberFormat nf = new NumberFormat();
when I put NumberFormat nf = new NumberFormat.get Instance();
i get error message
Documents\Java\PHotel.java:17: cannot find symbol
symbol : class getInstance
location: class java.text.NumberFormat
NumberFormat nf = new NumberFormat.getInstance();
^
1 error
CODE:
import java.util.*;
import java.io.*;
import java.text.*;
public class PHotel
{
public static void main(String[]args) throws InputMismatchException
{
int totalFloors;
int numOfRooms;
int roomsOccupied;
int roomsVacant;
double occupancyRate;
NumberFormat nf = new NumberFormat();
//Occupancy rate = number of rooms occupied/total number of rooms//
System.out.println("How many floors are in the hotel?");
Scanner keyboard = new Scanner(System.in);
totalFloors = keyboard.nextInt();
for(int i = 0; i!=totalFloors;i++)
{
if(totalFloors<=1)
System.out.println("The building must have more then 1 floor.");
if(totalFloors>1)
System.out.println("How many rooms are on floor "+i+"?");
numOfRooms = keyboard.nextInt();
if(numOfRooms>=10)
{
System.out.println("How many rooms on floor "+i+" are occupied?");
roomsOccupied = keyboard.nextInt();
}
else
System.out.println("Each floor must have at least 10 rooms.");
}
System.out.println("Rooms in the hotel: "+numOfRooms);
System.out.println("Rooms occupied: "+roomsOccupied);
System.out.println("Rooms vacant: "+roomsVacant);
System.out.println("occupancy rate:"+occupancyRate);
}//end main
}//end classI've got an idea--an idea so smart that my head would explode if I even began to know what I'm talking about.
- 03-27-2009, 06:32 AM #4
I copied, pasted and compiled the code you posted above and got this:
Change this lineJava Code:C:\jexp>javac PHotelRx.java PHotelRx.java:16: java.text.NumberFormat is abstract; cannot be instantiated NumberFormat nf = new NumberFormat(); ^ 1 error
to thisJava Code:NumberFormat nf = new NumberFormat();
Then give initial values, eg, 0, to the five variables declared at the beginning of the main method.Java Code:NumberFormat nf = NumberFormat.getInstance();
- 03-27-2009, 07:54 AM #5
Similar Threads
-
Difference between Abstract class having only abstract method and a Interface class
By Santoshbk in forum New To JavaReplies: 6Last Post: 02-11-2009, 10:51 AM -
GameImpl is not abstract and does not override abstract method
By Macca07 in forum New To JavaReplies: 2Last Post: 11-21-2008, 12:20 AM -
Error! "filename" is not abstract and does not override abstract method...
By hasani6leap in forum New To JavaReplies: 6Last Post: 10-27-2008, 12:25 AM -
Parsing a number using a NumberFormat
By Java Tip in forum java.textReplies: 0Last Post: 04-16-2008, 11:03 PM -
GUI for Abstract...
By judepereira in forum AWT / SwingReplies: 0Last Post: 01-04-2008, 08:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks