aspire1 36 Light Poster

I assume you are using self signed certificates. Is your friend using a proper signed certificate?

aspire1 36 Light Poster

A contiguous sequence of memory?

aspire1 36 Light Poster

Looks like you are learning the hard way parallel programming. MPI has all the tools to do this relatively painlessly.

Doing it the hard way I guess: create original array containing all the data and two other arrays half the size, create your two sub processes, each subprocess sorts one of the smaller arrays. Parent process waits for the two subprocesses to finish and then merges the two smaller arrays back into the bigger one.

WaltP commented: So you're saying all programming should use MPI. Not likely. -4
aspire1 36 Light Poster

well known method:

(( 1stNumber + 2ndNumber ) * numberOfNumbers) / 2

eg. 1st Number = 4 2nd = number 8

( ( 4 + 8 ) * ( 8 - 4 + 1 ) ) / 2
( 12 * 5 ) / 2
= 30

aspire1 36 Light Poster

The default .hashCode() method uses the contents of the string to create the hashcode so unsuprisingly all the values are the same. A better test is:

String str1="ABC";
	 String str2="ABC";
	 String str3 = new String("ABC");
	
	 
	 if( str1 == str2 )
	   System.out.println( "str1 and str2 reference same object");
	  else
        System.out.println( "str1 and str2 do not reference the same object");	  
	 
	 if( str1 == str3 )
	   System.out.println( "str1 and str3 reference same object");
	 else
        System.out.println( "str1 and str3 do not reference the same object");
	 
       if( str2 == str3 )
	   System.out.println( "str2 and str3 reference same object");
	 else
        System.out.println( "str2 and str3 do not reference the same object");

which shows two objects are created.

aspire1 36 Light Poster

Just out of interest, here is a recursive method ( which I don't claim to have rigorously tested by any means)

public static int sumPowers( int n, int m )
{    
    if( m > 0 )
    {
     int sum = n;
     sum *= sumPowers( n, --m );
     
     return sum+1;
    }
  
  return 1; 
          
}
aspire1 36 Light Poster

...as has been pointed out double is different from Double, double is a primitive type, Double is an immutable object, arraylists and other such collections can only accept objects. If using an array is appropriate for the situation then go ahead and use it, if a dynamic data structure such as an ArrayList is more appropriate then use that.

aspire1 36 Light Poster

a) 2 power 24 - 1
b) well BCD 4 bits each digit 0-9, work it out, 21 - 0010 0001
c) a bit of a trick question, ACII is used to represent characters not numbers specifically but you can look up the ASCII table and fiddle about but I'd say what? for that question or ask for clarification

aspire1 36 Light Poster

Taking what you've said without any further constraints then interpret it as a poistive base two number, convert it to decimal and that is that.

aspire1 36 Light Poster

Big problem I've seen at universities/colleges compared to back then is students expecting the "teaching" of a subject to be only within the bounds of what is actually delivered within class rather than what is delivered in class being a basis for reasearching and learning on your own. My opinion and only that, what used to be a post school education, staff are there to guide you, although it doesn't mean some of them stink at that. If you have a real interest in the subject and dare I say it these days, aptitude ( we ain't all built to be pop stars or bridge builders ) then pursue it on your own to your best ability.

aspire1 36 Light Poster

You have a text file. It is split into lines. You are reading it a line at a time. Read a line and if it starts with S and 2 then ignore it. String.startswith() or something like that. Lookup String class.

aspire1 36 Light Poster

Yup local variable is getting created. You're not actually modifying anything - java everything is passed by value, a copy is made. So a copy of whatever reference value bytes[] holds is getting made, in this case null and assigned to the local variable bytes in your function.

You have to return return the newly created array ref. and assign it.

byte bytes[] = ChangePrimitiveArray( byte bytes[] );

Note: it's pointless in this case passing anything to the ChangePrimitiveArray method. Your method is working like a "Factory" method.

VernonDozier commented: Thanks. +13
aspire1 36 Light Poster
if(numList.get(i) == numList.get(j))

You are actually comparing if two Integer objects are referencing the same object. Try numList.get(i).intValue() == numList.get(j).intValue()

Couldn't say for sure why the way you are doing it works in some cases.

aspire1 36 Light Poster

You have to provide a lower aswell as an upper bound or your expression will return true at the first match e.g

//Sanitize salesPersonName first

salesPersonName.matches( "[a-zA-Z]{20,20}");

As a tip, it's redundant to be doing the test twice in your code, use a normal while loop rather than do/while.

aspire1 36 Light Poster

Have a look at the Sun JavaCompiler class, haven't used it myself.

aspire1 36 Light Poster

Just use one pass of the bubble sort algorithm as hinted at in the code in previous post. The larget value in the array will be in the last position of the array after one pass, the second largest in second last position after two passes etc..

aspire1 36 Light Poster

And another variation where index is initially the length of the String:

public String reverse(String s, int index ){
   
    if( index >0 )
    {
     return s.charAt( --index) + reverse( s, index);
    }

    return "";
  }
aspire1 36 Light Poster

Just my penny's worth - do it if you are genuinely interested in it. Computer Science isn't "all my friends have problems with windows and I fix it for them". Programming is only one area of Computer Science ( all be it important ) and even then, knowing the syntax of a language doesn't imply Computer Science it is a very wide field and keeping one eye on the maths ( computer science maths will do ) will stand you good.

aspire1 36 Light Poster

Simple answer - sort your small list using an appropriate algorithm then merge them using an appropriate algorithm and of course you can sort a linked list in less than O(n^2).

aspire1 36 Light Poster

Isn't 10 instances of Animal class is being created with this line?

Nope, ten uninitialized reference variables of type Animal are being created.

aspire1 36 Light Poster

Just out of curiosity, what is the overall aim of the program?
Are you trying to generate the power set of an array of values and do you have to use Random? At what point will the program have accomplished it's mission?

aspire1 36 Light Poster

do
ls -l /usr/bin/java
and
ls -l /usr/bin/javac

and look at the output.

aspire1 36 Light Poster

O(n)

aspire1 36 Light Poster

As far as I'm aware applets can't by default write to the local file system: security. Google should show you how to do it.

aspire1 36 Light Poster

If it was a reference to the third/combined array that you had passed to the Object, then yes, changes will be visible. Personally I would prefer to have a "put" method which updates the Object with the concated arrays as it breaks encapsulation the way you are trying to do it and it may not be entirely clear what is going on to someone else looking at the code and you'd have to do extra work if the size of the arrays being combined isn't constant, so I'd:

concat to the two arrays to create a new combined array.
pass the combined array reference variable to the object to update it's "view"/reference of the combined array

public class MyClass{
   private int[] myArray;

   public void putArray( int[] combinedArray )
   {
      myArray = combinedArray;  
      
   }
  }

That's the simple sort of way I'd do it.

aspire1 36 Light Poster

Arrays/Objects ARE accessed using reference variables. Parameters are passed by value in Java, so if you pass an array to a method it is a copy of the reference to the Object or array that is passed not a whole copy of each element in the array. It goes to stand then that if I have an unintialised array as such, meaning the elements in the array haven't been initialised:

Integer[] myArray = new Integer[ 5 ]; // All of the elements are initially null

and pass myArray to some object that stores that reference variable, any changes made to the array outside the object will be visible inside the object and vice versa.

e.g
myArray[ 2 ] = 2;

The object storing the copy of the reference to the array will also see this change. It's pretty much similar to C.

aspire1 36 Light Poster

This is one version. You might want to look up Generics as of course, only works with int[]

private static void mergeSort( int[] data )
    {
       
       if( data.length > 1 )
       {
         int midPoint = data.length / 2;
         int[] left = new int[ midPoint ];   
         int[] right = new int[ data.length - midPoint ];
         
         for( int i = 0; i < midPoint; i++)
         {
           left[ i ] = data[ i ];
         }
         
         for( int i = midPoint, j= 0; i < data.length; i++, j++)
         {
           right[ j ] = data[ i ];
         }
         
         mergeSort( left );
         mergeSort( right );
         merge( left, right, data );
       }
     
    }
    
    private static void merge( int[] left, int[] right, int[] data )
    {
      int i = 0;
      int j = 0;
      int index = 0;
      
      while( i < left.length && j < right.length )
      {
        if( left[ i ] <= right[ j ] )
        {
            data[ index++ ] = left[ i++ ];
        }
        else
        {
          data[ index++ ] = right[ j++ ];
        }
       
      }
      
      while( i < left.length )
      {
         data[ index++ ] = left[ i ++ ]; 
      }
      
      while( j < right.length )
      {
        data[ index++ ] = right[ j++ ];
      }
    
    }
aspire1 36 Light Poster

You're not returning maxtemp from the getinput function.

aspire1 36 Light Poster

You had the hostname spelling wrong for one thing and your use of Scanner doesn't look right. You program still isn't quite right though. Remember, it's possible to telnet into servers that use "text" format which can help a lot in trouble shooting.

Socket s = new Socket("time-a.nist.gov", HTTP_PORT);
 System.out.println("Connected to time-a.nist.gov. Getting return string..");
 BufferedReader br = 
      new BufferedReader( new InputStreamReader( s.getInputStream() ) );
        
 for( String temp = br.readLine(); temp != null; temp = br.readLine() )
 {
   inStr += temp.trim();
 }
       
 s.close();
 System.out.println("Return string retrieved: " + inStr);
aspire1 36 Light Poster

I assume it means shifting all the elements one place to the right with the last element in the array wrapping around to be the first element in the array with every rotation.

aspire1 36 Light Poster

IF SO, Should any method I create in ConnectStudentDAO start in StudentDAO?

Not necessarily.

public interface StudentDAO {
   // This sort of thing would make more sense to me.  
   public Student connect( String user, String host, String password )
             throws LoginException, IncorrectPasswordException;

   //public Student connect(ConnectStudentDAO connectStudentDAO)
   //         throws LoginException,
   //         //UnknownstudentUserException,
   //         IncorrectPasswordException;
/*
    public void insertStudent(Student studentUser)
            throws SubscribeException;
 
    public void update(Student studentUser)
            throws ProfileException;
 
    public void delete(Student studentUser)
            throws UnsubscribeException;
 * 
 */
}
aspire1 36 Light Poster

You might not see the benefit of programming to interfaces in a small program but it is good practice.

Say you want a different implementation of how you connect to the database. You'd create a new class that implements StudentDAO and replace references of ConnectStudentDAO with the new implementation:

StudentDAO connection = new ConnectStudentDAO();
StudentDAO connection = new ADifferentConnectStudentDAO();

Notice that I'm using StudentDAO (the interface ) as the type.

As it stands, I'd make the GUI a seperate class from the database connection and encapsulate an object of the database connection in the GUI:

public MyGUI{

private StudentDAO connection = new ConnectStudentDAO();

...
connection.getResultSet() and so on...
...
...
...
}

aspire1 36 Light Poster

You're incrementing i in the wrong place.

aspire1 36 Light Poster

It is used to provide a consistent well, interface, for accessing an object WITHOUT regard to how the actual methods in the interface are implemented. This allows you to swap one class that implements an interface with another that implements it a different way without breaking the underlying logic of the program.

Simple example is the List interface:
A list can be implemented using an array or using a series of nodes linked together. If you want to switch from the array based list to the node based list you can easily do this if they both use the same interface.

aspire1 36 Light Poster

You need an empty constructor if you're going to provide your own one and you still want to create a bank account without passing parameters to it:

public bankAccount() { }

and I'd change the class name to BankAccount as this is the standard way to name classes with capital letters.

aspire1 36 Light Poster

Example using alpha as the comparison function:

int (*compare)(char*,char*) = &alpha;

aspire1 36 Light Poster

You'll have to structure your program then so that it's flow of control naturally terminates it.

boolean validInput = true;
          
while( validInput )
{
    // do all the stuff my program is meant to do

   if user enters invalidInput then
      display a message
      validInput = false

}

that sort of thing

aspire1 36 Light Poster

You're checking for null before you've read the next line, a quick change to:


while( (currentLine = bread.readLine() ) != null){ //read line by line while

should fix it

aspire1 36 Light Poster

1. System runs the command and the parent process waits for it to finish. You still have the original process. Exec replaces the current process with a new process. The original process is lost.

2. popen might be what you're looking for.

3. I'd be guessing as to the exact reason, so I'll keep my thoughts to myself on this one.

Ancient Dragon commented: I forgot about that :) +27
aspire1 36 Light Poster

And if they did use that code they won't be graduating from any college soon. It doesn't do a whole lot of much.

aspire1 36 Light Poster

One way you could go about it:

. save the text entered in a String

. use the the String split method to create a String[]

. create a hashmap HashMap<String, Integer> and add entries to it using the values in String[] as the key with an initial value of zero

. iterate through the String[] again add one to the value for each corresponding key in String[]

At the end the hashmap will contain all the words as keys with the corresponding number of times they appear.

aspire1 36 Light Poster

for(i=0;i<limit;i++); <---- semi colon

aspire1 36 Light Poster

Or it can be done quite elegantly using recursion. Easy enough to add the words and lines to an ArrayList too as that seems to be part of the requirement:

private static void reverseLines( Scanner input)
  {
     while( input.hasNextLine() )
     {
      String line = input.nextLine();
      reverseLines( input );
      reverseWords( new Scanner( line ) );
      System.out.println();
     
     }
  }
  
  private static void reverseWords( Scanner line )
  {
     while( line.hasNext() )
     {
        String word = line.next();
        reverseWords( line );
        System.out.print( word + " ");
     }
        
  }