1,076,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by sapure

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

In this example, what's the difference between creating a class variable from the "class Employee" & creating an object from the class GenQueue ?!

What's the difference in uses and implementation?

import java.util.LinkedList;
    class GenQueue {
       private LinkedList list = new LinkedList();
       public void enqueue(E item) {
           list.addLast(item);
     }
       public E dequeue() {
           return list.poll();
     }
       public boolean hasItems() {
           return !list.isEmpty();
     }
       public int size() {
           return list.size();
     }
       public void addItems(GenQueue q) {
           while (q.hasItems())
               list.addLast(q.dequeue());
     }
    }

    public class GenQueueTest {
     public static void main(String[] args) {
       GenQueue empList;
       empList = new GenQueue();
       GenQueue hList;
       hList = new GenQueue();
       hList.enqueue(new HourlyEmployee("T", "D"));
       hList.enqueue(new HourlyEmployee("G", "B"));
       hList.enqueue(new HourlyEmployee("F", "S"));
       empList.addItems(hList);
       System.out.println("The employees' names are:");
       while (empList.hasItems()) {
          Employee emp = empList.dequeue();
          System.out.println(emp.firstName + " " 
         + emp.lastName);
       }
      }
    }

     class Employee {
        public String lastName;
        public String firstName;
        public Employee() {
    }
       public Employee(String last, String first) {
          this.lastName = last;
          this.firstName = first;
      }
       public String toString() {
          return firstName + " " + lastName;
      }
    }

    class HourlyEmployee extends Employee {
       public double hourlyRate;
       public HourlyEmployee(String last, String first) {
           super(last, first);
      }
 }

Thanks.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I really appreciate all your HELPFUL BENEFICIAL tips & advices. This is very supporting and motivating. THANK YOU ALL.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I want to know ...

1) The difference between ordered & unordered dictionaries.
2) & Which type is more efficient for the previous algorithm.

Thanks.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Please, I'd like to know the difference and the special uses for each one.
If I want to use it for text file compression whose algorithm is as follows, which one is more efficient?

Encoding Algorithm
1. Initialize the dictionary to contain all blocks of length one (D={a,b}).
2. Search for the longest block W which has already appeared in the dictionary.
3. Encode W by its index (location) in the dictionary.
4. Add W followed by the first symbol of the next block to the dictionary.
5. If not done, go to (2).

Thanks, any help is appreciated.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I've been studying C++ for two years, then started Java two months ago. My performance in C++ wasn't good at all although I study hard. I thought that the problem is in not understanding the language concepts but when I started a new language with the intention of building up the concepts from scratsh, I discovered the REAL problem.

The problem isn't with knowing the syntax or understanding the language. My problem is when I'm faced with a program to solve, first, I don't know from where to start & how to think in solving it.

That's a HUGE problem...
Any suggestions for books to read, what to learn to help me think correctly when designing programs.

Thanks in advance :)

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It's worth resurection ... very beneficial :)

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Thanks both of you VERY MUCH. You really made me change the way I think of programming.

I've been struggling and suffering for 3 years in my college studies, thinking I'm dumb although I do love programming but didn't understand how to think about a solution when given a problem!

I studied C++ and now I'm studying Java...
I'd certainly follow your advice
1) Testing the code in sections (A precise comparision and a brilliant analysis)
2) Having a sketch beside me to write down what helps me solve the problem

Thanks.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Boolean eminem = new Boolean("yes");

What does it mean & what does it create?

Thanks.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

When choosing the input file, I tried three ways & all of them generated errors !
I created the file.txt in the project's folder. I'm using Netbeans IDE.

1) Passing

java ShowFile Input.text

as a command-line argument [properties ---> run ---> wrote this command-line in the 'Argument' box]

2) Using the file's path....

File file = new File("C:\\Users\\TOSHIBA\\My Documents\\NetBeansProjects\\fin.txt");

3) Creating an instance of the file...

java.io.File file = new java.io.File("fin.txt");

This first one gave... "File Not Found" error. //FileNotFoundException
The second two gave... "Usage: ShowFile File" error. //ArrayIndexOutOfBoundsException

What's wrong with it?!

Thanks.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Thank you, changing the class's name DID fix the problem.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
public class BufferedReader {

    public static void main(String[] args) 
    throws IOException
    {
        char c;
        BufferedReader sen  = new BufferedReader (new InputStreamReader(System.in)); **// ERROR**

        System.out.println("Enter characters, 'q' to quit");

        // read characters from the console
        while(c != 'q')
        {
            c = (char) sen.read(); **// ERROR**
            System.out.print(c);
        }
    }
}

I don't understand why the upper two lines of code produce error!

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

That's very helpful, thanks a lot.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

NormR1: Thanks for your time. :)
stultuske: yes findMax is a method. :)
But I need to pass a parameter which will decide on the output of the program. If I passed 1 ---> largest number of the 10 .... so on. That's the requirement of the assignment.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I don't use a command prompt window but an Netbeans IDK. Does it make a difference here?

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Why does this invoking

"java FindMax 2;"

says (can't find symbol
symbol: class java
location: class FindMax)?!

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

That's very helpful, thanks stultuske & NormR1.

That's what I was looking for, invoking by entering a command line. How can I randomize "thearg" for example, to be between 1 and 3 (can it be different every time I run the program?) and if it didn't invoke, how to set a default output?

Thanks a lot.

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I admit it's a part of an assignment but I don't understand what the assignment require in this part.
This program is supposed to read 10 numbers from the keyboard and then the application findMax will take one single command line argument.

If you invoke findMax 1, it will print to the screen the largest number amongst the ten numbers.

If you invoke findMax 2, it will print to the screen the second largest number amongst the ten numbers.

If you invoke findMax 3, it will print to the screen the third largest number amongst the ten numbers.

What does invokeing mean?! does the user input 1, 2 or 3 after inputing the 10 numbers ?!
Any help is appreciated...

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm a beginner too, but this is the source that my professer recommended....
A very useful Java reference http://docs.oracle.com/javase/6/docs/api/

What's SWING ?! http://docs.oracle.com/javase/tutorial/ui/overview/intro.html

sapure
Newbie Poster
21 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
 
© 2013 DaniWeb® LLC
Page rendered in 0.1111 seconds using 2.58MB