Please wat is wrong with this program

I want to reverse the user input but when I run this program it only asks for the input and when i key it in and press enter nothing happens.It just freezes.
Sorry the code is a bit long .
import java.io.*;
class StackX
private int maxSize;
private char[] stackArray;
private int top;
public StackX(int max)  
       maxSize=max;
       stackArray=new char[maxSize];
       top=-1;
public void push(char j) 
     stackArray[++top]=j;
public char pop()    
     return stackArray[top--];
public char peek()  
     return stackArray[top];
public boolean isEmpty()   
     return (top==-1);
class Reverser
     private String input;  
     private String output; 
public Reverser(String in)
     {input = in;}
         public String doRev( )    
     int stackSize=input.length( ); 
     StackX theStack = new StackX(stackSize);
     for(int j=0;j<input.length( );j++)
     char ch=input.charAt(j); 
     theStack.push(ch);
     output ="";
     while( !theStack.isEmpty() )
     char ch=theStack.pop();
     output=output+ch; 
     return output;
class ReverseApp
     public static void main(String[]args)throws IOException
     String input, output;
     while(true)
     System.out.print("Enter a string:");
     System.out.flush();
     input=getString();
     if( input.equals(""))
      break;
     Reverser theReverser = new Reverser(input);
     output = theReverser.doRev();
     System.out.println("Reversed: " + output);
public static String getString()throws IOException
     InputStreamReader isr = new InputStreamReader(System.in);
     BufferedReader br= new BufferedReader(isr);
     String s = br.readLine();
     return s;
}

One potential problem is that you're using a new reader around system.in every time. I don't know what happens when you do that. Just make it a member variable, or create it once in main and pass it to getString.
Asid from that, put a bunch of print statements in or use a debugger to see what's happening at each step of the way. You might be getting into an infinite loop somewhere in your reverse operation.

Similar Messages

  • Does ANYONE know whats wrong with this program?!?!

    Hey(again),
    Does anyone know whats wrong with this program?:
    public class FloatingNumbersTest
    public static void main(String args[])
    float float1 =50.0f;
    float closeFloat=0.001f
    float farfloat=100.0f
    if (float1<=closeFloat)
    System.out.print("Float1 pretty close to zero");
    if (float1>=closeFloat)
    System.out.print("Float1 is near 0");
    if (float1>=farfloat)
    System.out.print("Float1 is not even close to zero!"0
    }There has seemed to be 5 errors!

    public class FloatingNumbersTest
    public static void main(String args[])
    float float1 =50.0f;
    float closeFloat=0.001f
    float farfloat=100.0f
    if (float1<=closeFloat)
    HERE        System.out.print("Float1 pretty close to zero");
    if (float1>=closeFloat)
    System.out.print("Float1 is near 0");
    if (float1>=farfloat)
    System.out.print("Float1 is not even close to zero!"0
    }you're missing the opening { for the first if.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • What's wrong with this program?

    /* Daphne invests $100 at 10% simple interest. Deirdre invests $100 at 5% interest compounded annually. Write a program that finds how many years it takes for the value of Deirdre's investment to exceed the value of Daphne's investment. Aso show the two values at that time.*/
    #include <stdio.h>
    #define START 100.00
    int main(void)
    int counter = 1;
    float daphne = START;
    float deirdre = START;
    printf("Daphne invests $100 at 10 percent simple interest. Deirdre invests $100 at 5 percent interest compounded annually.
    When will Deirdre's account value exceed Daphne's?
    Let\'s find out.
    while (daphne > deirdre)
    daphne += 10.00;
    deirdre *= 1.05;
    printf("%f %f
    ", daphne, deirdre);
    printf("At year %d, Daphne has %.2f dollars. Deirdre has %.2f dollars.
    ", counter, daphne, deirdre);
    counter++;
    printf("By the end of year %d, Deirdre's account has surpassed Daphne's in value.
    ", counter);
    return 0;
    This is my output:
    *Daphne invests $100 at 10 percent simple interest. Deirdre invests $100 at 5 percent interest compounded annually.*
    *When will Deirdre's account value exceed Daphne's?*
    *Let's find out.*
    *By the end of year 1, Deirdre's account has surpassed Daphne's in value.*
    What's wrong with it?
    Message was edited by: musicwind95
    Message was edited by: musicwind95

    John hadn't responded at the time I started typing this, but I'll keep it posted anyways in order to expand on John's answer a little bit. The answer to your last question is that the loop's condition has to return true for it to run the first time around. To examine this further, let's take a look at the way you had the while loop before:
    while (daphne > deirdre)
    Now, a while loop will run the code between its braces as long as the condition inside the parenthesis (daphne > deirdre, in this case) is true. So, if the condition is false the first time the code reaches the while statement, then the loop will never run at all (it won't even run through it once -- it will skip over it). And since, before the while loop, both variables (daphne and dierdre) are set equal to the same value (START (100.00), in this case), both variables are equal at the point when the code first reaches the while statement. Since they are equal, daphne is NOT greater than dierdre, and therefore the condition returns false. Since the condition is false the first time the code reaches it, the code inside the loop's braces is skipped over and never run. As John recommended in the previous post, changing it to this:
    while (daphne >= deirdre)
    fixes the problem because now the condition is true. The use of the "greater than or equal to" operator (>=) instead of the "great than" operator (>) means that the condition can now be returned true even if daphne is equal to deirdre, not just if it's greater than deirdre. And since daphne and deirdre are equal (they are both 100.00) when the code first reaches the while loop, the condition is now returned true and the code inside the loop's braces will be run. Once the program reaches the end of the code inside the loop's braces, it will check to see if the condition is still true and, if it is, it will run the loop's code again (and again and again and again, checking to see if the condition is still true each time), and if it's not true, it will skip over the loop's bottom brace and continue on with the rest of the program.
    Hope this helped clear this up for you. Please ask if you have any more questions.

  • What is wrong with this program segment? I could not understand the error..

    public class Hmw3
         public static char[] myMethod(char[]p1,int p2, char p3)
         {                             //13 th row
              if(p2<p1.length)
                   p1[p2]=p3;
                   System.out.println(p1);
         public static void main(String[] args)
              String sentence="It snows";
              char[] tmp=sentence.toCharArray();
              System.out.println(tmp);
              myMethod(tmp,3,'k');
              sentence=String.copyValueOf(tmp);
              System.out.println(sentence);     
    i wrote this program segment and compiler gave this error:
    C:\Program Files\Xinox Software\JCreator LE\MyProjects\hmw3\Hmw3.java:13: missing return statement
    What is wrong???

    Your method signature states that myMethod should return an array for chars.
    But in ur implementation of myMethod, there is nothing returned.
    Just add a return statement like "return p1"

  • What is wrong with this program it keeps telling me the file doesn't exist?

    this program is supposed to write the file so why does it need the file to already exist?
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Scanner;
    public class NewClass implements ActionListener{
        static List list = new List();
        static TextField input = new TextField(20);
        static Button submit = new Button("Submit");
        static Frame f = new Frame("RealmList editor");
        static File file = new File("/Applications/World of Warcraft/realmlist.wtf");
        static Label status = new Label("");
        static Button selected = new Button("Change to Selected");
        static File config = new File("/Applications/RealmLister/config.txt");
        static File dir = new File("/Applications/RealmLister/");
        public static void main(String[] args) {
            f.setLayout(new BorderLayout());
            f.add(list, BorderLayout.CENTER);
            Panel p = new Panel();
            p.add(input);
            p.add(submit);
            p.add(selected);
            f.add(p, BorderLayout.NORTH);
            f.add(status, BorderLayout.SOUTH);
            new NewClass();
            f.setSize(500,500);
            f.setVisible(true);
            try {
                loadConfig();
            } catch(Exception e) {}
            f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    try {
                      writeConfig();
                      System.exit(0);
                    } catch(Exception e) {
                       status.setText("Error: config couldn't be written!("+e+")");
        public NewClass() {
            submit.addActionListener(this);
            input.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent e) {
                    if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                    try {
                    editRealmlist(input.getText(), true);
                    input.setText("");
                 catch(Exception ex) {
                   status.setText("Error: "+e);
            selected.addActionListener(this);
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == submit) {
                try {
                    editRealmlist(input.getText(), true);
                    input.setText("");
                } catch(Exception ex) {
                   status.setText("Error: "+e);
                   wait(3000);
                   status.setText("");
            if(e.getSource() == selected) {
                try {
                    editRealmlist(list.getSelectedItem(),false);
                } catch(Exception ex) {
                    status.setText("Error: "+e);
                    wait(3000);
                    status.setText("");
        public static void loadConfig() throws Exception{
            if(config.exists()) {
                Scanner scan = new Scanner(config);
                ArrayList<String> al = new ArrayList<String>();
                while(scan.hasNext()) {
                    al.add(scan.nextLine());
                for(int i = 0; i < al.size(); i++) {
                    list.add(al.get(i));
        public static void writeConfig() throws Exception{
            FileWriter fw = new FileWriter(config);
            dir.mkdir();
            config.mkdirs();
            String temp = "";
            for(int i = 0; i < list.getItemCount(); i++) {
                temp += list.getItem(i)+"\n";
            fw.write(temp);
            fw.flush();
            System.gc();
        public static void editRealmlist(String realm, boolean addtoList) throws Exception{
            FileWriter fw = new FileWriter(file);
            fw.write("set realmlist "+realm+"\nset patchlist us.version.worldofwarcraft.com");
            fw.flush();
            status.setText("Editing RealmList.wtf Please Wait...");
            Thread.sleep(3000);
            status.setText("");
            System.gc();
            if(addtoList)
                list.add(realm);
        public void wait(int time) {
            try {
                Thread.sleep(time);
            catch(Exception e) {}
    }

    Erm, you should call mkdirs() on a File object that represents a directory.

  • Java newbie (what's could be wrong with this program?)

    First things first, I just started programming with JAVA recently so please forgive me if it seems stupid. Since I am so relatively new to the language, in order to get a feel for it I started running some simple scripts. I can compile and execute most of them without any problem. However when I tried to compile this one I get a couple of errors I am not familiar with. So my question is what could be wrong and what needs to be changed in order to get it to work? or if the syntax is correct could there be some other problem?
    On a side note, I am coming more from a C and C++ background so if anyone can recommend a way to start learning the JAVA language from a prespective in C that would be highly appreciated.
    System Environment: I am using j2sdk1.4.2 on a Windows 2000 machine running SP3.
    If anything else needs further clarification please let me know.
    |------------------------- The Code -----------------------------------|
    package RockPaperScissors;
    import java.util.HashMap;
    public class RockPaperScissors {
    String[] weapons = {"Rock", "Paper", "Scissors"};
    EasyIn easy = new EasyIn();
    HashMap winners = new HashMap();
    String playerWeapon;
    String cpuWeapon;
    int cpuScore = 0;
    int playerScore = 0;
    public static void main(String[] args) {
    RockPaperScissors rps = new RockPaperScissors();
    boolean quit = false;
    while (quit == false) {
    rps.playerWeapon = rps.getPlayerWeapon();
    rps.cpuWeapon = rps.getCpuWeapon();
    System.out.println("\nYou chose: " + rps.playerWeapon);
    System.out.println("The computer chose: " + rps.cpuWeapon + "\n");
    rps.getWinner(rps.cpuWeapon, rps.playerWeapon);
    if (rps.playAgain() == false) {
    quit = true;
    System.out.println("Bye!");
    public RockPaperScissors() {
    String rock = "Rock";
    String paper = "Paper";
    String scissors = "Scissors";
    winners.put(rock, scissors);
    winners.put(scissors, paper);
    winners.put(paper, rock);
    System.out.println("\n\t\tWelcome to Rock-Paper-Scissors!\n");
    public String getPlayerWeapon() {
    int choice = 6;
    String weapon = null;
    System.out.println("\nPlease Choose your Weapon: \n");
    System.out.println("1. Rock \n2. Paper \n3. Scissors \n\n0. Quit");
    try {
    choice = easy.readInt();
    } catch (Exception e) {
    errorMsg();
    return getPlayerWeapon();
    if (choice == 0) {
    System.out.println("Quitting...");
    System.exit(0);
    } else {
    try {
    weapon = weapons[(choice - 1)];
    } catch (IndexOutOfBoundsException e) {
    errorMsg();
    return getPlayerWeapon();
    return weapon;
    public void errorMsg() {
    System.out.println("\nInvalid Entry.");
    System.out.println("Please Select Again...\n\n");
    public String getCpuWeapon() {
    int rounded = -1;
    while (rounded < 0 || rounded > 2) {
    double randomNum = Math.random();
    rounded = Math.round(3 * (float)(randomNum));
    return weapons[rounded];
    public void getWinner(String cpuWeapon, String playerWeapon) {
    if (cpuWeapon == playerWeapon) {
    System.out.println("Tie!\n");
    } else if (winners.get(cpuWeapon) == playerWeapon) {
    System.out.println("Computer Wins!\n");
    cpuScore++;
    } else if (winners.get(playerWeapon) == cpuWeapon) {
    System.out.println("You Win!\n");
    playerScore++;
    public boolean playAgain() {
    printScore();
    System.out.print("\nPlay Again (y/n)? ");
    char answer = easy.readChar();
    while (true) {
    if (Character.toUpperCase(answer) == 'Y') {
    return true;
    } else if (Character.toUpperCase(answer) == 'N') {
    return false;
    } else {
    errorMsg();
    return playAgain();
    public void printScore() {
    System.out.println("Current Score:");
    System.out.println("Player: " + playerScore);
    System.out.println("Computer: " + cpuScore);
    |------------------------- Compiler Output ----------------------------|
    C:\ide-xxxname\sampledir\RockPaperScissors>javac RockPaperScissors.java
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    2 errors

    limeybrit9,
    This importing certainly seems to be the problem, I'm still not used to how compilation works within the JAVA language, I'll play around with it a bit and see if I can get it to work correctly.
    bschauwe,
    The C++ approach has certainly clarified some of the points. I guess I will be sticking to that.
    bsampieri,
    You were correct on the class looking rather generic, but as I mentioned before I was just sort of tinkering to see if I could get it to work.
    Thanks to all for the help, very much appreciated.

  • Whats wrong with this program???

    Sorry if this is the wrong place to put it...this is my first time....
    else if (e.getSource() == b1)
              while(e.getSource() == b1)
              quantity1++;
         TxtArea1.setText("Egg");
         TxtArea2.setText("1");
         TxtArea3.setText("$55.00");
         Price =55.00;
         Total = price*quantity1;
         Txtfild.setText(Txtfild.getText() + "\n EGG\t1 55.00");
    There no error during both compilation and run. Yet every time I press the button the program freezes.........

    Tried a little bit of this and a little bit of that plus an append.....got the problem fixed quantity is now updating! Thanks for the tips........
    Once a problem has been fixed a new one arises.......
    Now every time I press the problem is that it creates another line with the old quantity value......
    Ex. I press the button twice.....
    1 EGG 55.00
    2 EGG 110.00
    Please help me........
    Heres the new code:
    if (e.getSource() == b1)
    quantity1++;
         TxtArea.setText("EGG");
         TxtArea.setText("1");
         TxtArea.setText("Php55.00");
         Price =55.00;
         Total = price*quantity1;
         TxtFild.append("\n"+quantity1+" "+"EGG"+" "+Total);
         }

  • What's wrong with this program that about socket

    package example;
    import java.net.*;
    import java.io.*;
    public class Server implements Runnable{
        Thread t;
        ServerSocket sSocket;
        int sPort=6633;
        public Server(){
            try{
                sSocket=new ServerSocket(sPort);
                System.out.println("server start....");
            }catch(IOException e){
                e.printStackTrace();
            t=new Thread(this);
            t.start();
        public void run(){
            try{
                while(true){
                    Socket cSocket=sSocket.accept();
                    ClientThread cThread=new ClientThread(cSocket);
                    cThread.start();
            }catch(IOException e){
                e.printStackTrace();
       public static void main(String[] args){
            new Server();
    package example;
    import java.net.*;
    import java.io.*;
    public class ClientThread extends Thread{
        Socket cSocket;
        PrintStream writer;
        BufferedReader reader;
        public ClientThread(Socket s){
            cSocket=s;
            try{
                writer=new PrintStream(cSocket.getOutputStream());
                reader=new BufferedReader(new InputStreamReader(cSocket.getInputStream()));
            }catch(IOException e){
                e.printStackTrace();
        public void run(){
            try{
                while(true){
                    String message=reader.readLine();
                    System.out.println("Server get:"+message);
            }catch(IOException e){
                e.printStackTrace();
    package example;
    import java.net.*;
    import java.io.*;
    public class Client{
        public static void main(String[] args){
            String ipaddr="localhost";
            PrintStream writer;
            try{
                Socket  cSocket=new Socket(ipaddr,6633);
                System.out.println(cSocket);
                writer=new PrintStream(cSocket.getOutputStream());
                System.out.println("client send:hello");
                writer.print("hello");
            catch(Exception e){
                e.printStackTrace();
    }first,I run Server,and then I run Client,
    output at Server:
    server start....
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.net.SocketInputStream.read(SocketInputStream.java:90)
    at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:285)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at java.io.BufferedReader.fill(BufferedReader.java:136)
    at java.io.BufferedReader.readLine(BufferedReader.java:299)
    at java.io.BufferedReader.readLine(BufferedReader.java:362)
    at example.ClientThread.run(ClientThread.java:20)
    what' wrong??????

    In your Client class, after doing writer.print("hello"); you should flush
    the output stream. As it is now, you attempt to write something (without actually
    sending something to your server) and main simply terminates. The server,
    still waiting for some input (you didn't flush on the client side), is confronted with
    a closed client socket (main on the client side terminated and implicitly closed
    the client socket), hence the 'connection reset' exception on the server side.
    kind regards,
    Jos

  • Help me please, what's wrong with my program...

    My program has no problem writing data into file. But, I get garbages when my program retrieved data from file. How to solve this, anyone? I tried last 4 days still can't figure out. :(
    /* myDate.java */
    import java.util.*;
    public class myDate extends Object{
    private int year;
    private int month;
    private int day;
    public myDate(String newDate) {
    StringTokenizer st = new StringTokenizer(newDate, "/");
    try {
    this.day = Integer.parseInt(st.nextToken());
    this.month = Integer.parseInt(st.nextToken());
    this.year = Integer.parseInt(st.nextToken());
    }catch (NumberFormatException nfe) {
    System.out.println("Incorrect Date Format!!!");
    System.out.println(nfe.getMessage());
    public void setDay (int Day) { this.day = Day; }
    public void setMonth (int Month) { this.month = Month; }
    public void setYear (int Year) { this.year = Year; }
    public String toString() {
    return day + "/" + month + "/" + year;
    public int getDay() { return day; }
    public int getMonth() { return month; }
    public int getYear() { return year;  }
    /* Inventory.java
    * Book Name: 30 bytes Characters
    * Book ISBN: 10 bytes Characters
    * Book Author: 30 bytes Characters
    * Book Genre : 30 bytes Characters
    * Book Quantity : 4 bytes integer
    * Date of the book purchased : 10 bytes Characters.
    import java.io.*;
    class Inventory{
    private String bookName, bookISBN, bookAuthor, bookGenre;
    private int quantity;
    private myDate datePurchased;
    public Inventory() {
    this.bookName = "";
    this.bookISBN = "";
    this.bookAuthor = "";
    this.bookGenre = "";
    this.quantity = 0;
    this.datePurchased = new myDate("00/00/0000");
    public void setBookName(String bookname) {
    this.bookName = bookname;
    public void setISBN(String BookISBN) {
    this.bookISBN = BookISBN;
    public void setAuthor(String author) {
    this.bookAuthor = author;
    public void setGenre(String genre) {
    this.bookGenre = genre;
    public void setQuantity(int qty) {
    this.quantity = qty;
    public void setPurchaseDate(String dateOfPurchase) {
    this.datePurchased = new myDate(dateOfPurchase);
    public String getBookName() { return bookName;}
    public String getISBN() { return bookISBN;}
    public String getAuthor() { return bookAuthor;}
    public String getGenre() { return bookGenre;}
    public int getQuantity() { return quantity;}
    public String getPurchaseDate() { return datePurchased.toString();}
    public String toString() {
    return bookName + "\n" + bookISBN + "\n" + bookAuthor + "\n" +
    bookGenre + "\n" + quantity + "\n" + datePurchased.toString() +
    "\n";
    public String fillData(RandomAccessFile raf, int len) throws
    IOException {
    char data[] = new char[len];
    char temp;
    for(int i = 0; i < data.length; i++) {
    temp = raf.readChar();
    data[i] = temp;
    return new String(data).replace('\0', ' ');
    public void writeStr(RandomAccessFile file, String data, int len)
    throws IOException {
    StringBuffer buf = null;
    if(data != null)
    buf = new StringBuffer(data);
    else
    buf = new StringBuffer(len);
    buf.setLength(len);
    file.writeChars(buf.toString());
    public void writeRecord(RandomAccessFile rafile) throws
    IOException {
    writeStr(rafile, getBookName(), 30);
    writeStr(rafile, getISBN(), 10);
    writeStr(rafile, getAuthor(), 30);
    writeStr(rafile, getGenre(), 30);
    rafile.writeInt(getQuantity());
    writeStr(rafile, getPurchaseDate(), 10);
    public void readRecord(RandomAccessFile rafile) throws
    IOException {
    setBookName(fillData(rafile, 30));
    setISBN(fillData(rafile, 10));
    setAuthor(fillData(rafile, 30));
    setGenre(fillData(rafile, 30));
    setQuantity(rafile.readInt());
    setPurchaseDate(fillData(rafile, 10));
    public final static int size() {
    return 114;
    /* btnPanel.java */
    import javax.swing.*;
    import java.awt.*;
    class btnPanel extends JPanel {
    JButton btnSave, btnCancel;
    public btnPanel() {
    btnSave = new JButton("Save Changes");
    btnCancel = new JButton("Cancel");
    add(btnSave);
    add(btnCancel);
    /* inpPanel2.java */
    import javax.swing.*;
    import java.awt.*;
    class inpPanel2 extends JPanel{
    JTextField tfBookName, tfBookISBN, tfGenre, tfQuantity,
    tfAuthor, tfDatePurchased;
    JLabel lblBookName, lblBookISBN, lblAuthor, lblGenre,
    lblQuantity, lblDatePurchased;
    public inpPanel2() {
    tfBookName = new JTextField("",30);
    tfBookISBN = new JTextField("",10);
    tfGenre = new JTextField("",30);
    tfAuthor = new JTextField("",30);
    tfQuantity = new JTextField("",10);
    tfDatePurchased = new JTextField("",10);
    lblBookName = new JLabel("Book Name ");
    lblBookISBN = new JLabel("ISBN ");
    lblAuthor = new JLabel("Author ");
    lblGenre = new JLabel("Genre ");
    lblQuantity = new JLabel("Quantity ");
    lblDatePurchased = new JLabel("Date Purchased ");
    setLayout(new GridLayout(6,2));
    add(lblBookName);
    add(tfBookName);
    add(lblBookISBN);
    add(tfBookISBN);
    add(lblAuthor);
    add(tfAuthor);
    add(lblGenre);
    add(tfGenre);
    add(lblQuantity);
    add(tfQuantity);
    add(lblDatePurchased);
    add(tfDatePurchased);
    /* InventoryAdd.java */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    class InventoryAdd extends JFrame {
    btnPanel buttonPanel;
    inpPanel2 inputPanel;
    Inventory bookInventory;
    RandomAccessFile rafile;
    public InventoryAdd() {
    super("Book Inventory - Add");
    buttonPanel = new btnPanel();
    buttonPanel.btnSave.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
    openFile();
    bookInventory = new Inventory();
    bookInventory.setBookName(inputPanel.tfBookName.getText());
    bookInventory.setISBN(inputPanel.tfBookISBN.getText());
    bookInventory.setAuthor(inputPanel.tfAuthor.getText());
    bookInventory.setGenre(inputPanel.tfGenre.getText());
    bookInventory.setQuantity(
    Integer.parseInt(
    inputPanel.tfQuantity.getText()));
    bookInventory.setPurchaseDate(inputPanel.tfDatePurchased.getText());
    try {
    bookInventory.writeRecord(rafile);
    }catch(IOException ioe) {
    System.out.println("Cannot Write Record into file...");
    System.out.println(ioe.getMessage());
    clearInput();
    closeFile();
    System.out.println(bookInventory.toString());
    buttonPanel.btnCancel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
    clearInput();
    inputPanel = new inpPanel2();
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(inputPanel, BorderLayout.CENTER);
    c.add(buttonPanel, BorderLayout.SOUTH);
    setSize(350, 190);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    public void clearInput() {
    inputPanel.tfBookName.setText("");
    inputPanel.tfBookISBN.setText("");
    inputPanel.tfAuthor.setText("");
    inputPanel.tfGenre.setText("");
    inputPanel.tfQuantity.setText("");
    inputPanel.tfDatePurchased.setText("");
    public void openFile() {
    try {
    rafile = new RandomAccessFile("BOOK_INV.DAT","rw");
    rafile.seek(rafile.length());
    }catch(IOException ioe) {
    System.out.println("Error, Cannot open File");
    public void closeFile() {
    try{
    rafile.close();
    }catch(IOException ioe) {
    System.out.println("Error, Cannot Close File");
    public static void main(String args[]) {
    new InventoryAdd();
    /* ReadInv.java */
    import java.io.*;
    class ReadInv {
    RandomAccessFile rafile;
    Inventory bookInv;
    public ReadInv() {
    bookInv = new Inventory();
    try {
    rafile = new RandomAccessFile("BOOK_INV.DAT","r");
    rafile.seek(0);
    for(int i=0; i < (rafile.length()/bookInv.size()); i++) {
    bookInv.readRecord(rafile);
    System.out.println(bookInv.toString());
    }catch(IOException ioe) {}
    public static void main(String args[]) {
    new ReadInv();

    it's hard to read. please use code tag.
    why don't u use object serialization by implements Serializable?
    import java.io.Serializable;
    public class Inventory implements Serializable {
        // u don't need to change ur code here
    }when saving & loading inventory, u can use ObjectOutputStream & ObjectInputStream.
    here is an example:
    Inventory i = new Inventory();
    // set your inventory here
    // save to file
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
       "InventoryFile.dat")); // file name
    out.writeObject(i);
    // u can write many object to one single file.
    out.close();
    // load the file
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(
       "InventoryFile.dat"));
    Inventory i = (Inventory) in.readObject();

  • Please help whats wrong with my program(XTAPI+JTAPI)

    hi, everybody ,I want to ask one problem about xtapi
    i have download xtapi.jar and mstapi from http://sourceforge.net/projects/xtapi/
    Now i am unable to understand this statement
    terminal = myprovider.getTerminal("0");
    i cannot understand wt parameter shuld be passed here if i pass here names of the ports LTP1, H323,etc it gives me exception InvalidArgumentException
    i cannot understand what parameter should be passed here if i pass here 2,3,5,6 it works but it does not detect events observer in jtapi
    Please tell me wt should i pass here so that i can observe my modem as terminal
    Please help me i will be very thankful to you
    MY CODE
    import javax.telephony.*;
    public class InCommingCall {
    public InCommingCall() {
    * Create a provider by first obtaining the default implementation of
    * JTAPI and then the default provider of that implementation.
    Provider myprovider = null;
    try {
    //JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
    JtapiPeer peer = JtapiPeerFactory.getJtapiPeer("net.xtapi.XJtapiPeer");
    myprovider = peer.getProvider(null);
    catch (Exception excp) {
    System.out.println("Can't get Provider: " + excp.toString());
    excp.printStackTrace();
    * Locate the Terminal associated with our near end and place a call
    * observer on it. This will instruct the implementation to add a call
    * observer once a telephone call comes to the Terminal. We are assuming
    * Terminals are named after a primary telephone number on that terminal.
    Terminal terminal;
    try {
    Terminal[] T=myprovider.getTerminals();
    for(int i=0;i<T.length;i++){
    System.out.println(T.getName());
    terminal = myprovider.getTerminal("0");
    terminal.addCallObserver(new CallAndDTMFObserver());
    System.out.println("Now standing by for phone calls");
    catch (Exception excp) {
    excp.printStackTrace();
    public static void main(String argv[]) {
    InCommingCall callReceiver = new InCommingCall();
    }

    Duplicate of:
    http://forum.java.sun.com/thread.jspa?threadID=623891

  • What is wrong with this program?

    When I run a get these messages:
    ^
    MULTIPLYIMP.java:25: 'class' or 'interface' expected
    ^
    MULTIPLYIMP.java:7: cannot resolve symbol
    symbol : class UnicastRemoteObject
    location: class MULTIPLYIMP
    UnicastRemoteObject implements multiply {
    ^
    MULTIPLYIMP.java:6: MULTIPLYIMP should be declared abstract; it does not define
    greet() in MULTIPLYIMP
    public class MULTIPLYIMP extends
    ^
    MULTIPLYIMP.java:11: cannot resolve symbol
    symbol : method supa ()
    location: class MULTIPLYIMP
    supa (); //Export
    ^
    MULTIPLYIMP.java:15: missing method body, or declare abstract
    public int mult (int a,int b) throws RemoteException
    ^
    9 errors
    //MULTIPLYIMPL.JAVA
    import java.rmi.*;
    import .rmi.server.*;
    public class MULTIPLYIMP extends
    unicastRemoteObject implements multiply {
    public MULTIPLYIMPL () throwsRemoteException {
    supa (); //Export
    public int mult (int a,int b) throws RemoteException
    return (a * b)
    public String greet () throws RemoteException
    return("CCM 3061");

    When I run a get these messages:
    ^
    MULTIPLYIMP.java:25: 'class' or 'interface' expected
    ^
    MULTIPLYIMP.java:7: cannot resolve symbol
    symbol : class UnicastRemoteObject
    location: class MULTIPLYIMP
    UnicastRemoteObject implements multiply {
    ^
    You haven't imported the right package.
    You need to import
    java.rmi.server.UnicastRemoteObject
    or
    java.rmi.server.*
    MULTIPLYIMP.java:6: MULTIPLYIMP should be declared
    abstract; it does not define
    greet() in MULTIPLYIMP
    public class MULTIPLYIMP extends
    ^
    It says that you don't define greet() because it doesn't have curly braces after the method name.
    I'm reasonably sure
    public String greet () throws RemoteException
    return("CCM 3061");is not acceptable, usepublic String greet () throws RemoteException
    return("CCM 3061");
    MULTIPLYIMP.java:11: cannot resolve symbol
    symbol : method supa ()
    location: class MULTIPLYIMP
    supa (); //Export
    ^
    MY GOD MAN, SUPER(), SUPER!!!!!!
    MULTIPLYIMP.java:15: missing method body, or declare
    abstract
    public int mult (int a,int b) throws RemoteException
    ^
    9 errors
    Same with mult(), need to have curly braces around the method body
    //MULTIPLYIMPL.JAVA
    import java.rmi.*;
    WHAT IS THIS LINE?
    import java.rmi.server.*
    import .rmi.server.*;
    public class MULTIPLYIMP extends
    unicastRemoteObject implements multiply {
    public MULTIPLYIMPL () throwsRemoteException {
    supa (); //Export
    public int mult (int a,int b) throws RemoteException
    return (a * b)
    public String greet () throws RemoteException
    return("CCM 3061");
    }Messy messy code mate,
    Good luck,
    Radish21

  • Wat is wrong with this simple query ???

    I am using 10gxe.
    Below is the query which is not working
    Whenever i am executing it a pop up windows is coming up
    and asking me to enter bind variables ..wat shall i do ???
    Here is a prntscrn of the issue .
    http://potupaul.webs.com/at.html
    VARIABLE g_message VARCHAR2(30)
    BEGIN
    :g_message := 'My PL/SQL Block Works';
    END;
    PRINT g_message
    Edited by: user4501184 on May 18, 2010 12:42 AM

    sqlplus "system/sm@test"
    SQL*Plus: Release 10.2.0.2.0 - Production on Tue May 18 12:45:05 2010
    Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> VARIABLE g_message VARCHAR2(30)
    SQL> BEGIN
    2 :g_message := 'My PL/SQL Block Works';
    3 END;
    4 /
    PL/SQL procedure successfully completed.
    SQL> PRINT g_message;
    G_MESSAGE
    My PL/SQL Block Works
    SQL>

  • What wrong with this program

    It worked fine until i tried to make capitalized vowels recognized and now it doesn't work
    import cs1.Keyboard;
    public class Vowels
        public static void main (String[] args)
                int vowelcount = 0;
                char ltr;
                while (vowelcount <5)
                System.out.print ("Enter a letter to see if it's a vowel: "); //Prompt
                ltr = Keyboard.readChar();
                if (ltr =='a'||ltr =='e'||ltr =='o'||ltr =='i'||ltr =='u');
                System.out.println (""+ ltr +" is a vowel"); //Vowel entered
                vowelcount = (vowelcount + 1);
                else
                    System.out.println (""+ ltr +" is not a vowel"); //vowel not entered
                   System.out.println ("Congratulations you have entered all 5 vowels!");
    }I get a 'else' without 'if' error

    In java characters are internally represented with integers..
    for ex:
    char a=49 and
    char a='1' are same..
    Your are just checking for lowercase vowells..check the condition for liek this
    if(enteredChar ==65||enteredChar==96 )
    System.out.println("vowel");
    }

  • What's wrong with this program, nothing displays.

    Compile ok, but nothing displays.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class Card{
    JFrame f;
    JLabel nameTF;
    JComboBox jobChoice;
    JButton B1, B2, B3, B4;
    public static void main(String[] av) {
    new Card( );
    public Card( ) {
    f=new JFrame();
    f.setSize(500,500);
    Container cp = f.getContentPane( );
    cp.setLayout(new GridLayout(0, 1));
    f.addWindowListener(new WindowAdapter( ) {
    public void windowClosing(WindowEvent e) {
    f.setVisible(false);
    f.dispose( );
    System.exit(0);
    JMenuBar mb = new JMenuBar( );
    f.setJMenuBar(mb);
    JMenu aMenu;
    aMenu = new JMenu("filemenu");
    mb.add(aMenu);
    JMenuItem mi = new JMenuItem("exit");
    aMenu.add(mi);
    mi.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    aMenu = new JMenu("editmenu");
    mb.add(aMenu);
    aMenu = new JMenu("viewmenu");
    mb.add(aMenu);
    aMenu = new JMenu("optionsmenu");
    mb.add(aMenu);
    aMenu =new JMenu("helpmenu");
    mb.add(aMenu);
    JPanel p1 = new JPanel( );
    p1.setLayout(new GridLayout(0, 1, 50, 10));
    nameTF = new JLabel("My Name", JLabel.CENTER);
    nameTF.setFont(new Font("helvetica", Font.BOLD, 18));
    nameTF.setText("MYNAME");
    p1.add(nameTF);
    jobChoice = new JComboBox( );
    jobChoice.setFont(new Font("helvetica", Font.BOLD, 14));
    String next;
    int i=1;
    do {
    next = "job_title" + i;
    if (next != null)
    jobChoice.addItem(next);
    } while (next != null);
    p1.add(jobChoice);
    cp.add(p1);
    JPanel p2 = new JPanel( );
    p2.setLayout(new GridLayout(2, 2, 10, 10));
    B1 = new JButton( );
    B1.setText("button1.label");
    p2.add(B1);
    B2 = new JButton( );
    B2.setText("button2.label");
    p2.add(B2);
    B3 = new JButton( );
    B3.setText("button3.label");
    p2.add(B3);
    B4 = new JButton( );
    B4.setText("button4.label");
    p2.add(B4);
    cp.add(p2);
    f.pack( );
    f.show();
    }

    hi there
    try this code i changed a little bil and one more thing yr LOOP is not working Properly check that out
    rest is fine
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class Card extends JFrame
        JLabel nameTF;
        JComboBox jobChoice;
        JButton B1, B2, B3, B4;
        public static void main(String[] av)
            Card C = new Card( );
            C.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public Card( )
            setSize(500,500);
            Container cp = getContentPane( );
            cp.setLayout(new GridLayout(0, 1));
            addWindowListener(new WindowAdapter( )
                public void windowClosing(WindowEvent e)
                    dispose( );
                    System.exit(0);
        JMenuBar mb = new JMenuBar( );
        setJMenuBar(mb);
        JMenu aMenu;
        aMenu = new JMenu("filemenu");
        mb.add(aMenu);
        JMenuItem mi = new JMenuItem("exit");
        aMenu.add(mi);
        mi.addActionListener(new ActionListener( )
            public void actionPerformed(ActionEvent e)
                dispose( );
                System.exit(0);
        aMenu = new JMenu("editmenu");
        mb.add(aMenu);
        aMenu = new JMenu("viewmenu");
        mb.add(aMenu);
        aMenu = new JMenu("optionsmenu");
        mb.add(aMenu);
        aMenu =new JMenu("helpmenu");
        mb.add(aMenu);
        JPanel p1 = new JPanel( );
        p1.setLayout(new GridLayout(0, 1, 50, 10));
        nameTF = new JLabel("My Name", JLabel.CENTER);
        nameTF.setFont(new Font("helvetica", Font.BOLD, 18));
        nameTF.setText("MYNAME");
        p1.add(nameTF);
        jobChoice = new JComboBox( );
        jobChoice.setFont(new Font("helvetica", Font.BOLD, 14));
        String next;
    //    int i=1;
    //    do
    //        next = "job_title" + i;
    //        if (next != null)
    //           jobChoice.addItem(next);
    //    } while (next != null);
        p1.add(jobChoice);
        cp.add(p1);
        JPanel p2 = new JPanel( );
        p2.setLayout(new GridLayout(2, 2, 10, 10));
        B1 = new JButton( );
        B1.setText("button1.label");
        p2.add(B1);
        B2 = new JButton( );
        B2.setText("button2.label");
        p2.add(B2);
        B3 = new JButton( );
        B3.setText("button3.label");
        p2.add(B3);
        B4 = new JButton( );
        B4.setText("button4.label");
        p2.add(B4);
        cp.add(p2);
        pack( );
        setVisible(true);
    }Regards
    Satinderjit

  • Wat is wrong in this decode function, it doesn get executed,please help me

    wat is wrong in this decode function, it doesn get executed,please help me
    decode(DVI.COMPANY||'.')||
                                            DECODE(DVI.COST_CENTRE||'.')||
                                            DECODE(DVI.ACCOUNT||'.')||
                                            DECODE(DVI.LOCATION||'.')||
                                            DECODE(DVI.PRODUCT||'.')||
                                            DECODE(DVI.FUTURE)company_id,

    Hi,
    I could not understand what you are trying to do with decode here.
    The standard way of using the decode is like :
    SQL>SELECT DECODE (1 , 1 ,'TRUE','FALSE') FROM DUAL;
    DECO
    TRUE
    1 row selected.
    1* SELECT DECODE (1 , 0 ,'TRUE','FALSE') FROM DUAL
    SQL>/
    DECOD
    FALSE
    1 row selected.
    Please explain what you want to do with DECODE ?
    Regards

Maybe you are looking for

  • Display Multiple reports in a single query view

    Hi Team, I have 3 similar reports for MTD, QTD & YTD. While displaying the report in the portal..  I want to display the reports in a single view wherein the MTD report will be a default report for the input selections. whereas the QTD & YTD will be

  • Sync my Mac Mini to my iPhone 4

    Can I sync my Mac Mini to my iPhone 4, remotely using home sharing? Basically I want to be able to sync music, movies, and audio books to my iPhone without having to dig round the back of my computer for my apple cabble. I want to know if its possibl

  • How to create ios environment with adobe id?

    Hi , i am trying to create ios environment in windows platform. can any one please tell me, how to create IOS environment with adobe id. I a created adobe id and inserted code into it. But its running (Since one hour), and no response. Any one have i

  • I need to access apple works 6 docs in lion

    Hi there, I upgraded to lion but backed up my disk using time machine beforehand. Now time machine is not recognised and want to be set up again. I have files in the time machine that I need to see but can not access. I still have the apple works 6 f

  • Error in creating an Oracle WebLogic Server domain

    Hi Everyone,                     Am getting this following error when I tried to create a Weblogic Server Domain,Kindly help.I displayed the screen shot below,