₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,074 members, 8,420,177 topics. Date: Thursday, 04 June 2026 at 12:53 PM

Toggle theme

Urgent Help On Java Project - Tech Jobs - Nairaland

Nairaland ForumScience/TechnologyProgrammingTech JobsUrgent Help On Java Project (896 Views)

1 Reply

Urgent Help On Java Project by bigboyslim(op): 11:28pm On Oct 24, 2008
hi,
I have a class project that is due in 4 days and I still dont know if i'm going about it the right way. Would really appreciate if java gurus can help out. The assignment is to write a program that reads lines from stdin and dynamically allocate storage for the entire set of lines read. I am not allowed to use any of the java storage facilities to manage the data storage memory ie i cant use ArrayList. it must all be done by hand.

Hints provided
- use a byte array for the character storage
- pick one of the simplest java input facilities to read characters from stdin and treat as bytes

I tried to go about this using the following steps but got stuck.
- Read the input lines and stored them in a string array
- tried to convert each of the characters in the string into byte and store in a byte array.

i think i'm going about this the wrong way so guys, your input would be appreciated.
Re: Urgent Help On Java Project by javarules(m): 8:33am On Oct 28, 2008
I hope this help. It converts Strings to bytes

public class Stringy {
    public static void main(String args[]) {
        String s = "My name is Javarules";
        System.out.println(s);
        byte[] data = s.getBytes();
        System.out.println(data);
    }
}


But to dynamically allocate Storage(I heard pointers ringing in my ears), you are better with C. using java you could use pointers too.

this is a code that utilises this

//JAND
//http://naijadukes.net
//You are free to use and re-distribute this code.

import java.io.*;

public class Pointers {
    Pointer myPointer = new Pointer();
    Pointer p = new Pointer();
    //to make life easier, I read the lines from a file. You can read it from console if you like
    //The logic is simple. You have a class that has a member which is itself.
    //Java classes are references by default.
    //
    //Therefore is a class has a member that is itself, we can have a Pointer in java
   
    public Pointers() {
        try {
            InputStream in = new FileInputStream(new File("Pointers.java"wink);
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line = reader.readLine();

            myPointer.line = line;
            myPointer.nextLine = p;
            while(line != null) {               
                line = reader.readLine();
                p.line = line;
                p.nextLine = new Pointer();
                //this point should be noted carefully. See that p is pointing to it's nextLine,
                //myPointer.nextLine is p, p.nextLine is a new Pointer so myPointer.nextLine.nextLine is a new Pointer
                //This is a loop so the process is repeated and then we have myPointer.nextLine.nextLine.nextLine.
                //Study the readline below and you will get a feel of how to read the lines.
                //You can also set a class variable for Pointer say int pos; such that pos is incremented everytime the loop is entered.
                //Then you can read a particular pointer by just knowing what pos is.
                p = p.nextLine;
            }
        } catch(FileNotFoundException fne) {
            fne.printStackTrace();
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
    }

    public void readLines() {
        Pointer nextPointer = new Pointer();
        String line = myPointer.line;
        System.out.println(line);
        nextPointer = myPointer.nextLine;
        while(line != null) {
            line = nextPointer.line;
            System.out.println(line);
            nextPointer = nextPointer.nextLine;
        }
    }

    public static void main(String args[]) {
        Pointers pointers = new Pointers();
        pointers.readLines();
    }
}

class Pointer {
    public String line;
    public Pointer nextLine;

    public Pointer() {
        line = "";
//this is to avoid null pointer exceptions. We will change this value of nextLine, it can not be this.
//do not use nextLine = new Pointer() either, you get some cryptic java runtime exceptions
        nextLine = this;
    }
}


Visit http://naijadukes.net with your questions, you get faster responses there as long as its java question, I hope this solution is not too late. Today is 4 days already

Ciao
Re: Urgent Help On Java Project by bigboyslim(op): 6:23pm On Oct 28, 2008
Thanks for your reply. and yea today is submission date but luckily I managed to find an i/o facility that works well for my intended purpose.

I used System.in.read() to retrieve characters one at a time. It retrieves the characters as integers so all I had to do was cast the retrieved characters as bytes and i processed them one at a time.

Thanks for your effort though it came a bit late smiley.
1 Reply

Where Can I Download A Complete Video Tutorial On Java Programming.Co-programming Partner In A Java Project NeededHelp Needed With Java Project Urgently ( I Will Pay)234

Get A Web Site Designed And Developed For FreeUrgently NeededNesta Accounting Solution