Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class array?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
0
0
US
Not sure what I should call this. I am creating a new class that gets the next bench warrant number to be issued and return it to another process. Sound easy, but of course, there's something or else I wouldn't be posting!

The warrant number is actually made up of two pieces of data. The "special character" and the number. The special characters consist of # @ % & *. This character is appended to the beginning of the number. If the number is 99990 then I need to switch to the next special character.

So, currently we are using the #; if I get the next number and it is 99990 I want to change the special character to @.

Can someone give me an idea of how I would store the character array and select the "next" one if the BW number matches 99990?

Thanks!

Leslie

In an open world there's no need for windows and gates
 
Well how are the characters assigned? I think I might have an idea, but I am not sure if it is set up the way I am thinking of it.
 
Does the numerical part have leading zeroes? And when the next special character has to be shown, does the numerical part has to go back to 1? If that is the case then this may do the trick:


public class BenchWarrant {
private static final String characters = "#@%&*";

public static void main(String[] args) {
System.out.println(getNextNumber("#99990"));
}

public static String getNextNumber(String lastNumber) {
char leadChar = lastNumber.charAt(0);
int number = Integer.valueOf(lastNumber.substring(1)) + 1;
int index = characters.indexOf(leadChar, 0);
final String filler = "00000";

if (number > 99990) {
index++;
number = 1;
if(index == characters.length()) {
return "We ran out of our leading characters";
}
}

String numberPart = Integer.toString(number);
StringBuffer buf = new StringBuffer(6);
buf.append(characters.substring(index, index + 1));
buf.append(filler.substring(0, filler.length() - numberPart.length()));
buf.append(numberPart);
return buf.toString();
}
}

 
Thanks for the example! I'm waiting on access to a co-worker to get some more details about the process. Once I have some answers I'll post back.

I do know that the special characters are looped:
# @ % & * # @ % & * # @ % & *

so that we won't run out of leading characters, but I have some confusion on the reseting of the number portion.

Leslie


 
Well, if the special characters are looped this would mean that your program is going to regenerate older bench warrant numbers. To loop though the special characters in my example and leaving out the leading zeroes you could do the following:

public static String getNextNumber(String lastNumber) {
char leadChar = lastNumber.charAt(0);
int number = Integer.valueOf(lastNumber.substring(1)) + 1;
int index = characters.indexOf(leadChar, 0);

if (number > 99990) {
index++;
number = 1; // reset number portion
if(index == characters.length()) {
index = 0; // Reset special character
}
}

StringBuffer buf = new StringBuffer(6);
buf.append(characters.substring(index, index + 1));
buf.append(Integer.toString(number));
return buf.toString();
}
}

Good luck!

Tom
 
actually what happens is this. There are two dataareas that contain the current special character and the last number used. On December 31 12:00 am each year the number is automatically set to: 0 + 2 digit year.

So this year we started on 0000008. Next year we start on 0000009.

Then I need to get the special character and append it and increment the stored number by 100, so the first few warrants will be:
#0000108
#0000208
#0000308
#0000408

now when I get to:
#9999908 I need to increment the special character and reset the number:
@0000108
@0000208

Does that make more sense?

Leslie
 
Ok, I have another question....lets assume that I've created the NextBWNumber class and it does exactly what it's suppose to do, gives me a string that represents the special character and the number.

Now, I have another class..IssueWarrant. In that class I would like to do this:

Code:
private void IssueWarrant(String CasePrefix, String CaseNumber, String Division, String HearingType){
	    [b]NextBWNumber WarrantNumber = new NextBWNumber();[/b]
[i] lots of other code that eventually uses the WarrantNumber[/i]
}

How do I include the NextBWNumber in the IssueWarrant class? (btw - this is only my 3rd Java program, so technically I'm still a newbie!!!). I've tried creating a jar file from the NextBWNumber class and importing that to the IssueWarrant class, but that doesn't work. The only thing that I've found that works is to copy the NextBWNumber.java file into the IssueWarrant class, but that's not really what I want to do. I want to include the class, but not the code....does that make sense?

Leslie

 
Ok, back to my original issue.

I need to get the special character and the last used number from a data area on the AS400. Then I need to update those data areas. I always have to update the number area and I only have to update the special character if it is changed during the process.

Here's what I have so far...(again, be gentle with me, i'm new at this!)
Code:
package functions;

import com.ibm.as400.access.*;
import java.math.*;

//----------------------------------------------------------------------------------------
//Creates docket entries into CMS from TA Web Application (Plea/J&S)
/*
 * Created April 2008 
 * Author: Leslie Andrews
 * 
 * 
 */

//----------------------------------------------------------------------------------------
public class NextBWNumber {	

	private static String ReturnInfo = ""; 

	public static String getNextBWNumber(){
		return ReturnInfo;
	}

	public NextBWNumber(String args)	{
	  ReturnInfo = NextWarrant();
	}
	
	private String NextWarrant() {	
    	
    	String temp = null;
    	
    	temp = GetPrefix() + GetNextBWNumber();
    	
    	return temp;
    }
	
	private String GetPrefix(){
		String tPrefix = null;
		
		AS400 system = new AS400("iSeries", "username", "password");
        
    	QSYSObjectPathName path2 = new QSYSObjectPathName("Y2K", "NXTBWPR", "DTAARA");
        CharacterDataArea dataArea2 = new CharacterDataArea(system, path2.getPath());
        try {
        	tPrefix = dataArea2.read();
        }
    	catch (Exception e) {
    		System.out.println("error reading dataarea getPrefix");
    		e.printStackTrace();
    	}
    	
    	return tPrefix;

	}
	
	private String GetNextBWNumber(){
		String tNumber = null;
		BigDecimal b = null;
		int i = 0;
		
		AS400 system = new AS400("iSeries", "username", "password");
		
        
    	QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWNO", "DTAARA");
        DecimalDataArea dataArea = new DecimalDataArea(system, path.getPath());
        try {
        	b = dataArea.read();
        }
    	catch (Exception e) {
    		System.out.println("error reading dataarea getNextBWNumber2");
    		e.printStackTrace();
    	}
    	tNumber = b.toString();
    	
    	i = Integer.parseInt(tNumber.trim());
    	i = i+100;
    	tNumber = String.valueOf(i);
    	
    	final String filler = "00000";
        StringBuffer buf = new StringBuffer(6);
        
        buf.append(filler.substring(0, filler.length() - tNumber.length()));
        buf.append(tNumber);
        
        return buf.toString();
    	
		
	}
	
	private void SetLastBWNumber(String LastBWNumber){
		BigDecimal b = null;
		
		b = BigDecimal.valueOf(Long.valueOf(LastBWNumber).longValue());
    	AS400 system = new AS400("iSeries", "username", "password");
        
    	QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWNO", "DTAARA");
        DecimalDataArea dataArea = new DecimalDataArea(system, path.getPath());
        try {
          dataArea.write(b);
        }
    
        catch (Exception e) {
    		System.out.println("error writing dataarea SetLastBWNumber");
    		e.printStackTrace();
    	}
    }
}

Leslie

In an open world there's no need for windows and gates
 
ok here's what I ended up with that does what I need in case anyone else needs the help!!
Code:
package functions;

import com.ibm.as400.access.*;
import java.math.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

//----------------------------------------------------------------------------------------
//Creates docket entries into CMS from TA Web Application (Plea/J&S)
/*
 * Created April 2008 
 * Author: Leslie Andrews
 * 
 * 
 */

//----------------------------------------------------------------------------------------
public class NextBWNumber {	

	private static String ReturnInfo = "";
	AS400 system = new AS400("iSeries", "dbaccess", "dbaccess1");

	public static String getNextBWNumber(){
		return ReturnInfo;
	}

	public NextBWNumber(String args)	{
	  ReturnInfo = NextWarrant();
	}
	
	private String NextWarrant() {	
    	
    	String temp = null;
    	
    	temp = GetPrefix() + GetNextBWNumber();
    	System.out.println("used warrant:" + temp);
    	return temp;
    }
	
	private String GetPrefix(){
		String tPrefix = null;
		
		
    	
    	//QSYSObjectPathName path = new QSYSObjectPathName("CMLIB", "NXTBWPR", "DTAARA");
        
    	QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWPR", "DTAARA");
        CharacterDataArea dataArea = new CharacterDataArea(system, path.getPath());
        try {
        	tPrefix = dataArea.read();
        }
    	catch (Exception e) {
    		System.out.println("error reading dataarea getPrefix");
    		e.printStackTrace();
    	}
    	
    	return tPrefix;

	}
	
	private String GetNextBWNumber(){
		String tNumber = null;
		
		BigDecimal b = null;
		int i = 0;
		
		//QSYSObjectPathName path = new QSYSObjectPathName("CMLIB", "NXTBWNO", "DTAARA");
        
    	QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWNO", "DTAARA");
        DecimalDataArea dataArea = new DecimalDataArea(system, path.getPath());
        try {
        	b = dataArea.read();
        }
    	catch (Exception e) {
    		System.out.println("error reading dataarea getNext BWNumber2");
    		e.printStackTrace();
    	}
    	tNumber = b.toString();
    	
    	if (tNumber.length() > 2) {
    		tNumber = tNumber.substring(0, tNumber.length() - 2);
    	}
    	else {
    		tNumber = "0";
    	}
    	  	
    	
    	
    	i = Integer.parseInt(tNumber.trim());
    	i++;

        tNumber = String.valueOf(i) + getYear();
    	
    	final String filler = "0000000";
        StringBuffer buf = new StringBuffer(7);
        
        buf.append(filler.substring(0, filler.length() - tNumber.length()));
        buf.append(tNumber);
        
       if (i == 99999) {
        	SetLastBWNumber("0" + getYear());
        	IncrementCharacter(GetPrefix());
        } 
       else {
    	   SetLastBWNumber(buf.toString());
       }
        
        return buf.toString();
    	
		
	}

	
	private void IncrementCharacter(String CurrentChar){
		 String characters = "#@%&*";
		 
		 int index = characters.indexOf(CurrentChar, 0);
		 
		 index++;
	     if(index > characters.length()) {
	       index = 0; // Reset special character
	     }
	     
	     QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWPR", "DTAARA");
	        CharacterDataArea dataArea = new CharacterDataArea(system, path.getPath());
	        try {
	           dataArea.write(characters.substring(index, index + 1));
	        }
	    	catch (Exception e) {
	    		System.out.println("error reading dataarea getPrefix");
	    		e.printStackTrace();
	    	}
	    	
		 
	}
	private void SetLastBWNumber(String LastBWNumber){
		BigDecimal b = null;
		
		b = BigDecimal.valueOf(Long.valueOf(LastBWNumber).longValue());

		
    	//QSYSObjectPathName path = new QSYSObjectPathName("CMLIB", "NXTBWNO", "DTAARA");
        
    	QSYSObjectPathName path = new QSYSObjectPathName("Y2K", "NXTBWNO", "DTAARA");
        DecimalDataArea dataArea = new DecimalDataArea(system, path.getPath());
        try {
          dataArea.write(b);
        }
    
        catch (Exception e) {
    		System.out.println("error writing dataarea SetLastBWNumber");
    		e.printStackTrace();
    	}
    }
	
	private String getYear() {
        DateFormat dateFormat = new SimpleDateFormat("yy");
        java.util.Date date = new java.util.Date();
        return dateFormat.format(date);
    }  
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top