How do you input data into a constructor from scanner? - input

I am trying to take a constructor(string, string, double) and set the value in it with a scanner input. any help is appreciated. The code is list below.
My programs can assign the values that i put in, but I want to be able to assign them from the keyboard and I would like to use only one constructor method to accomplish this. Thanks
I have it broken up into two classes:
import java.util.Scanner;
public class EmployeeTest
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
Employee employee1 = new Employee("james", "ry", 3200);
Employee employee2 = new Employee("jim" , "bob" , 2500.56 );
System.out.println("What is employyee 1's first name? ");
employee1.setFname(input.nextLine());
}
}
class Employee
{
private String fname;
private String lname;
private double pay;
public Employee(String fname, String lname, double pay)
{
this.setFname(fname);
this.lname = lname;
this.pay = pay;
System.out.println("Employee " + fname +" "+ lname + " makes $" +
+ pay + " this month and with a 10% raise, their new pay is $" + (pay * .10 + pay));
}
void setfname(String fn)
{
setFname(fn);
}
void setlname(String ln)
{
lname = ln;
}
void setpay (double sal)
{
pay = sal;
}
String getfname()
{
return getFname();
}
String getlname()
{
return lname;
}
double getpay()
{
if (pay < 0.00)
{
return pay = 0.0;
}
return pay;
}
public String getFname() {
return fname;
}
public void setFname(String fname)
{
this.fname = fname;
}
}

You can modify you EmployeeTest class something like
class EmployeeTest {
public static void main (String...arg) {
Scanner s = new Scanner(System.in);
String[] elements = null;
while (s.hasNextLine()) {
elements = s.nextLine().split("\\s+");
//To make sure that we have all the three values
//using which we want to construct the object
if (elements.length == 3) {
//call to the method which creates the object needed
//createObject(elements[0], elements[1], Double.parseDouble(elements[2]))
//or, directly use these values to instantiate Employee object
} else {
System.out.println("Wrong values passed");
break;
}
}
s.close();
}
}

Related

toString reverse order in java

My method toString() is supposed to return a string representation of the stack. The string representation consists of the stacks's elements in the order they are stored, enclosed in square brackets. My problem is that I am now returning [element0, element1, element2, element3, element4] so I wonder if there is there a simple way to return the string in reverse order i.e. to return [element4, element3, element2, element1, element0] instead?
public class Stack<E> implements IStack<E> {
public String toString() {
String str = "[";
if (head != null) {
str += head.getmElement();
Node<E> tempNode = head.getmNextNode();
while (tempNode != null) {
str += ", " + tempNode.getmElement();
tempNode = tempNode.getmNextNode();
}
}
str += "]";
return str; }
Node class:
public class Node<E> {
private E mElement;
private Node<E> mNextNode;
Node(E data) {
this.setmElement(data);
}
public E getmElement() {
return this.mElement;
}
public void setmElement(E element) {
this.mElement = element;
}
public Node<E> getmNextNode()
{
return this.mNextNode;
}
public void setmNextNode(Node<E> node)
{
this.mNextNode = node;
}}
You could use a StringBuilder and insert every element at the beginning instead of appending it:
public String toString() {
StringBuilder sb = new StringBuilder("[");
if (head != null) {
sb.append(head.getmElement());
Node<E> tempNode = head.getmNextNode();
while (tempNode != null) {
sb.insert(1, ", ").inser(1, tempNode.getmElement());
tempNode = tempNode.getmNextNode();
}
}
sb.append("]");
return sb.toString();
}
Your list is only forward linked, so you could use a temporary ArrayList and add each element at the index 0.

Can't make arraylist make a list using a index and while loop

I'm trying to make a program in java that you can add people's birthdays, names, birthmonths, and birthyears. I want to be able to print out a list with month and number of people born in each month. I have the following code with 2 classes one as a "person" class and "analyzer" class. Here is the following code,
import java.util.*;
/*
* This project will keep track of which day
* (1 to 31) and which month (1 to 12)in which
* people are born.
* Look to LogAnalyzer for clue.
*/
public class Person
{
private int birthDay;
private int birthMonth;
private int birthYear;
private String name;
public Person(String name, int birthDay, int birthMonth, int birthYear)
{
this.name = name;
if(birthDay >= 1 && birthDay <= 31){
this.birthDay = birthDay;
}
else {
this.birthDay = -1;
}
if(birthMonth >= 1 && birthMonth <= 12 ){
this.birthMonth = birthMonth;
}
else {
this.birthMonth = -1;
}
this.birthYear = birthYear;
}
public String getName()
{
return name;
}
public int getBirthDay()
{
return birthDay;
}
public int getBirthMonth()
{
return birthMonth;
}
public int getBirthYear()
{
return birthYear;
}
public String toString()
{
return "Name: " + getName() + " BirthDay: " + getBirthDay() +
" BirthMonth: " + getBirthMonth() + " BirthYear: " +
getBirthYear();
}
}
import java.util.ArrayList;
import java.util.Iterator;
public class Analyzer
{
// instance variables - replace the example below with your own
private int []birthDayStats;
private int []birthMonthStats;
private ArrayList people;
/**
* Constructor for objects of class Analyzer
*/
public Analyzer()
{
people = new ArrayList();
}
public void addPerson(String name, int birthDay, int birthMonth, int
birthYear)
{
Person person = new Person(name, birthDay, birthMonth, birthYear);
if(person.getBirthDay()!=-1|| person.getBirthMonth() != -1) {
people.add(person);
birthMonthStats [birthMonth]++;
birthDayStats[birthDay]++;
}
else
{
System.out.println ("Your current Birthday is " + birthDay + " or "
+ birthMonth + " which is not a correct number 1-31 or 1-12 please put in a
correct number " );
}
}
public void printPeople() //prints all people in form: “ Name: Tom
Month: 5 Day: 2 Year: 1965”
{
int index = 0;
while(index < people.size()){
Person person = (Person) people.get(index);
System.out.println(person);
index++;
}
}
public void printMonthList()//prints the number of people born in each month
Sample output to the right with days being similar
{
int index = 0;
while (index < birthMonthStats.length){
System.out.println (birthMonthStats[index]);
index++;
}
}
}
the code i'm having trouble is the "printmonthlist" method i'm trying to print it but it doesn't print. I want it to print out the month list of 12 months and the number of people born in each month. If any of you could help me figure it out thanks.
You forgot to initialize your arrays. As you can see in my code down here I initialized the arrays with two constants in the Analyzer creation.
NB: for readability I just changed a little bit your log in the printMonthList() method
import java.util.ArrayList;
public class Analyzer
{
// instance variables - replace the example below with your own
private final static int DAYS_PER_MONTH = 31;
private final static int MONTHS_PER_YEAR = 12;
private int []birthDayStats;
private int []birthMonthStats;
private ArrayList<Person> people;
/**
* Constructor for objects of class Analyzer
*/
public Analyzer()
{
this.people = new ArrayList<Person>();
// A default value of 0 for arrays of integral types is guaranteed by the language spec
this.birthDayStats = new int[Analyzer.DAYS_PER_MONTH];
// A default value of 0 for arrays of integral types is guaranteed by the language spec
this.birthMonthStats = new int[Analyzer.MONTHS_PER_YEAR];
}
public void addPerson(String name, int birthDay, int birthMonth, int
birthYear)
{
Person person = new Person(name, birthDay, birthMonth, birthYear);
if(person.getBirthDay()!=-1|| person.getBirthMonth() != -1) {
people.add(person);
birthMonthStats [birthMonth-1]++;
birthDayStats[birthDay-1]++;
}
else
{
System.out.println ("Your current Birthday is " + birthDay + " or "
+ birthMonth + " which is not a correct number 1-31 or 1-12 please put in a correct number " );
}
}
public void printPeople() //prints all people in form: “ Name: Tom Month: 5 Day: 2 Year: 1965”
{
int index = 0;
while(index < people.size()){
Person person = (Person) people.get(index);
System.out.println(person);
index++;
}
}
public void printMonthList()//prints the number of people born in each month Sample output to the right with days being similar
{
int index = 0;
while (index < birthMonthStats.length){
System.out.println ("Month number " + (index+1) + " has " + birthMonthStats[index] + " people");
index++;
}
}
}

Java.lang.String errors & not printing to error file

For this project the end result was for there to be 2 error reports sent to an error file at as well as a listing of account summary information printed out. While i can get a majority of the account information printed out such as Balance before transaction and transaction to the account or if there were insufficient funds for the transaction, that's all that will print out as it should be. I'm receiving no errors or exceptions so i'm in all honesty not too sure where the issue at hand may be. I was hoping a second pair of eyes on my code could possibly point out where my issue may be, below is my code of the Account.java, CheckingAccount.java CreditCard.java and lastly D4.java which contains the main method.
Account.java
public class Account {
protected String accountNo, institution, name;
protected double balance;
public Account (String accountNo, String name, String institution, double balance) {
this.name = name;
this.accountNo = accountNo;
this.balance = balance;
this.institution = institution;
}
public String getAccount() {
return accountNo;
}
public boolean debitAccount(double amt) {
return false;
}
public boolean creditAccount(double amt) {
return false;
}
}
CheckingAccount.java
public class CheckingAccount extends Account {
public CheckingAccount(String acctNo, String name, String inst, double balance) {
super(acctNo, name, inst, balance);
this.name = name;
this.accountNo = acctNo;
this.balance = balance;
this.institution = institution;
}
public double getBalance()
{
return balance;
}
public boolean debitAccount(double amt) {
balance += amt;
return false;
}
public boolean creditAccount(double amt) {
balance -= amt;
return false;
}
}
CreditCard.java
public class CreditCard extends Account {
private double creditLimit;
private double availableCredit;
public CreditCard(String acctNo, String name, String inst, double limit, double balance) {
super(acctNo, name, inst, 0);
this.creditLimit = creditLimit;
this.availableCredit = availableCredit;
this.balance = balance;
}
public boolean debitAccount(double amt) {
balance -= amt;
return false;
}
public double getCreditLimit(){
return creditLimit;
}
public double getBalance()
{
return balance;
}
public boolean creditAccount(double amt) {
balance += amt;
return false;
}
}
D4.java
import java.io.*;
import java.util.*;
public class D4 {
public static void main(String[] args) throws FileNotFoundException
{
Boolean valid;
String transactionFile = args[0];
String theaccount, transaction;
File transactions = new File(transactionFile);
Scanner infile = new Scanner(transactions);
File errorFile = new File(args[1]);
PrintWriter error = new PrintWriter(errorFile);
Vector<Account> account = new Vector<Account>();
while(infile.hasNext())
{
transaction = infile.nextLine();
valid = performTrans(account, transaction, error, errorFile);
}
}
private static Account findAccount(Vector<Account> a, String acctNo) {
for(int index = 0; index < a.size(); index ++)
{
if (a.elementAt(index).getAccount().equals(acctNo))
{
return a.elementAt(index);
}
}
return null;
}
private static boolean Checkingacct(Account a)
{
if(a instanceof CheckingAccount)
{
return true;
}
else
{
return false;
}
}
private static boolean Creditcrd(Account a)
{
if(a instanceof CreditCard)
{
return true;
}
else
{
return false;
}
}
private static String errorLog(Vector<Account> a, String transaction)
{
String[] trans = transaction.split(":");
String error;
if(findAccount(a, trans[1])==null)
{
error = ("Invalid account: " + transaction);
System.out.println(error);
return error;
}
else
{
Account acc = findAccount(a, trans[1]);
if( trans[0] == "debit")
{
error = ("Transaction denied: " + transaction);
System.out.println(error);
return error;
}
else
{
return null;
}
}
}
private static boolean performTrans(Vector<Account> account, String transaction, PrintWriter log, File errorFile)
{
String[] pieces = transaction.split(":");
String trans = pieces[0];
System.out.println(pieces);
if(trans.equals("create"))
{
if( pieces[1].equals("checking"))
{
CheckingAccount checking = new CheckingAccount(pieces[2], pieces[3], pieces[4], Double.parseDouble(pieces[5]));
account.add(checking);
return true;
}
else if (pieces[1].equals("credit"))
{
CreditCard creditCard = new CreditCard(pieces[2], pieces[3], pieces[4], 0, Double.parseDouble(pieces[5]));
account.add(creditCard);
return true;
}
else
{
System.out.println("not sure what to put here");
return false;
}
}
else if(trans.equals("debit"))
{
if(findAccount(account, pieces[1]) == null)
{
return false;
}
else
{
Account a = findAccount(account, pieces[1]);
double amount = Double.parseDouble(pieces[2]);
if(Checkingacct(a) == true)
{
CheckingAccount checking = (CheckingAccount) a;
System.out.println("Balance before transaction: " + checking.getBalance());
checking.creditAccount(amount);
System.out.println("Transaction to account: " + amount);
System.out.println("Balance after transaction: " + checking.getBalance() + "\n");
return true;
}
else if(Creditcrd(a) == true)
{
CreditCard creditCard = (CreditCard) a;
System.out.println("Balance before transaction: " + creditCard.getBalance());
System.out.println("Transaction to account: " + amount);
if(amount + creditCard.getBalance() > creditCard.getCreditLimit())
{
System.out.println("Insufficient funds for transaction");
return false;
}
else
{
creditCard.creditAccount(amount);
return true;
}
}
}
}
else if(trans.equals("credit"))
{
if(findAccount(account, pieces[1]) == null)
{
System.out.println("Print Error Message");
return false;
}
else
{
Account a = findAccount(account, pieces[1]);
double amount = Double.parseDouble(pieces[2]);
if(Creditcrd(a) == true)
{
CheckingAccount checking = (CheckingAccount) a;
System.out.println("Balance before transaction: " + checking.getBalance());
checking.debitAccount(amount);
System.out.println("Transaction to account: " + amount);
System.out.println("Balance after transaction: " + checking.getBalance() + "\n");
return true;
}
else if(Creditcrd(a) == true)
{
CreditCard creditCard = (CreditCard) a;
System.out.println(creditCard.getBalance());
return true;
}
}
}
else if(trans.equals("report"))
{
return true;
}
return false;
}
}
The text file im attempting to read from is called D4.txt and the information inside of it is
create:checking:10-3784665:Chase:Joe Holder:2000
create:credit:1234567898765432:First Card:Bob Badger:4000
create:checking:11-3478645:Dime:Melissa Martin:1000
report
debit:10-3784665:523.67
debit:1234567898765432:3500
credit:10-3784665:50
credit:11-3478645:30
debit:10-839723:200
debit:1234567898765432:600
report
The two errors im supposed to be able to print out and see in the errorFile.txt or whatever you choose to call it is and is where the main problem is as this information for some reason is not being processed and printed onto the outputfle.
Invalid account: debit:10839723:200
Transaction denied: debit:1234567898765432:600
The information printed to the console is supposed to look like
Account Summary:
Checking account #103784665
Bank: Chase
Name on account: Joe Holder
Balance: 1526.33
Credit Account #1234567898765432
Bank: First Card
Issued to: Bob Badger
Credit Limit: 4000
Balance: 3500.00
Available credit: 500.00
Checking account #113478645
Bank: Dime
Name on account: Melissa Martin
Balance: 1030.00
End account summary.
But this is also a part of the issue as currently when i run the code whats being printed out to the console is
run D4 d4.txt errorFile.txt
[Ljava.lang.String;#1d540a51
[Ljava.lang.String;#b31c562
[Ljava.lang.String;#3db12bab
[Ljava.lang.String;#4ff0c6b8
[Ljava.lang.String;#4d40d320
Balance before transaction: 2000.0
Transaction to account: 523.67
Balance after transaction: 1476.33
[Ljava.lang.String;#2c9cc42e
Balance before transaction: 4000.0
Transaction to account: 3500.0
Insufficient funds for transaction
[Ljava.lang.String;#2bb07c61
[Ljava.lang.String;#483b594b
[Ljava.lang.String;#31470572
[Ljava.lang.String;#20aedee
Balance before transaction: 4000.0
Transaction to account: 600.0
Insufficient funds for transaction
[Ljava.lang.String;#2ea4aa4d
I know this is a lot of information to sort through and i just want to thank anyone and everyone in advance for your help and hope its something simple that im just overlooking!

Defining methods and variables

I am a beginner and I am trying to understand what is static, private, public. Please see the following example written by me. It works, but I have very big doubts whether this is a correct way of defining variables and methods. Thanks in advance!
import java.util.Scanner;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Biorhytm {
private static String nameOne;
private static String nameTwo;
private static String dobOneIn;
private static String dobTwoIn;
private static Date dobOne;
private static Date dobTwo;
static int diff;
public static Date getDobOne() {
return dobOne;
}
public static void setDobOne(Date dobOne) {
Biorhytm.dobOne = dobOne;
}
public static Date getDobTwo() {
return dobTwo;
}
public static void setDobTwo(Date dobTwo) {
Biorhytm.dobTwo = dobTwo;
}
public static String getDobOneIn() {
return dobOneIn;
}
public static void setDobOneIn(String dobOneIn) {
Biorhytm.dobOneIn = dobOneIn;
}
public static String getDobTwoIn() {
return dobTwoIn;
}
public static void setDobTwoIn(String dobTwoIn) {
Biorhytm.dobTwoIn = dobTwoIn;
}
public static String getNameOne() {
return nameOne;
}
public static void setNameOne(String nameOne) {
Biorhytm.nameOne = nameOne;
}
public static String getNameTwo() {
return nameTwo;
}
public static void setNameTwo(String nameTwo) {
Biorhytm.nameTwo = nameTwo;
}
public static int diffCalc() {
return diff = Math.abs((int)((getDobOne().getTime() - getDobTwo().getTime()) / (24 * 60 * 60 * 1000)));
}
public static void main(String[] args) {
float physicalBio;
float emotionalBio;
float intellectualBio;
boolean validEntry;
Scanner input = new Scanner(System.in);
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("EEEE, MMMM d, yyyy", java.util.Locale.US);
System.out.println("Enter name of first person!");
setNameOne(input.nextLine());
if (getNameOne().equals("")) {
setNameOne("first person");
}
System.out.println("Enter name of second person!");
setNameTwo(input.nextLine());
if (getNameTwo().equals("")) {
setNameTwo("second person");
}
do {
try {
System.out.println("Enter date of birth of " + getNameOne() + "! (MM/DD/YYYY)");
setDobOneIn(input.nextLine());
setDobOne(format.parse(getDobOneIn()));
validEntry = true;
}
catch (ParseException e) {
validEntry = false;
}
} while (!validEntry);
do {
try {
System.out.println("Enter date of birth of " + getNameTwo() + "! (MM/DD/YYYY)");
setDobTwoIn(input.nextLine());
setDobTwo(format.parse(getDobTwoIn()));
validEntry = true;
}
catch (ParseException e) {
validEntry = false;
}
} while (!validEntry);
System.out.println();
System.out.println("DOB of " + getNameOne() + ": " + format2.format(getDobOne()) + ".");
System.out.println("DOB of " + getNameTwo() + ": " + format2.format(getDobTwo()) + ".");
System.out.println("Difference between DOBs (days): " + diffCalc() + ".");
physicalBio = diffCalc() % 23;
emotionalBio = diffCalc() % 28;
intellectualBio = diffCalc() % 33;
physicalBio /= 23;
emotionalBio /= 28;
intellectualBio /= 33;
if (physicalBio > 0.5) {
physicalBio = 1 - physicalBio;
}
if (emotionalBio > 0.5) {
emotionalBio = 1 - emotionalBio;
}
if (intellectualBio > 0.5) {
intellectualBio = 1 - intellectualBio;
}
physicalBio = 100 - (physicalBio * 100);
emotionalBio = 100 - (emotionalBio * 100);
intellectualBio = 100 - (intellectualBio * 100);
System.out.println("Physical compatibility: " + java.lang.Math.round(physicalBio) + " %.");
System.out.println("Emotional compatibility: " + java.lang.Math.round(emotionalBio) + " %.");
System.out.println("Intellectual compatibility: " + java.lang.Math.round(intellectualBio) + " %.");
}
}
You'd rather have your Biorhythm class be something representing the data about a single person. So you'd create two instances of it (call them "one" and "two", say) and make them non-static. It would have instance variables, not static variables, representing name and date of birth.
class Biorhythm {
private Date dob;
private String name;
Biorhythm(String name, Date dob) {
this.name = name;
this.dob = dob;
}
public String getName() {
return name;
}
public Date getDob() {
return dob;
}
}
public static void main(String[] args) {
Date onedob = /* implementation omitted */
Biorhythm one = new Biorhythm("maxval", onedob);
System.out.println("one: name=" + one.getName() + " date=" + one.getDob());
/* and so forth */
}
You don't really have a need for setXXX() methods because these values aren't probably going to change in your program.
Now create two instances of this class in your main() method. I'll leave the implementation of the calculation methods as an exercise for the time being, since there would be several decent designs for implementing them (in terms of the object-oriented question you asked).
First let me explain what these keywords are-
private,default,protected.public are ACCESS SPECIFIERS.
public-as the word says ,can be accessed everywhere and all members can be public.
protected-can be accessed outside the package in case of inheritance.
default-access able within the package and all members can be default.
private-scope lies within the class,cant be inherited.
And remember these can be used with variables,methods,even classes.
static-can be used when there is no need to invoke methods or access variables with objects.
static members doesn't belong to object and initialised at the time of loading a class.
for ex:
class Converter{
public static long convert(long val){
return val;
}
class User{
long value=Converter.convert(500);//calling convert with class name}

SMPP error code 61,62

I am using the jsmpp lib for sending sms. The SMSC center returns negative response like 61,62 which are Invalid scheduled delivery time and Invalid Validty Period value. After talking with SMSC support, they require to set a default timeout for the message to be delivered, after some search on jsmpp site, didn't find it. Thanks for any suggestions ?
According to SMPP standard it should be possible to leave both of these null, but if Validity Period is required, this can be either an absolute date or a relative one.
The format should be YYMMDDhhmmsstnnp, where
YY is a two digit year (00-99)
MM is month (01-12)
DD is day (01-31)
hh is hours (00-23)
mm is minutes (00-59)
ss is seconds (00-59)
t is tenths of second (00-59)
nn is the time difference in quarter hours between local time and UTC (00-48)
p can be one of the following :-
'+' local time is ahead of UTC.
'-' local time is behind UTC.
'R' This is a relative time.
So to make the validity period 1 hour using a relative time use the following: "000000010000000R"
In my project I didn't have business requirement to schedule delivery time and set validity Period, so I set them null and it's work fine :-)
I use this class to load smpp config from properties file. Code that will using it will looks more readable and simple :-)
SMPPConfigManager is an interface for this class. It's possible to read this config not only from properties file. For example from Db and you can then implement this interface in new class.
package ru.rodin.denis.smpp;
import java.util.Properties;
import org.jsmpp.bean.*;
/**
*
* #author Denis Rodin
*/
public class SMPPFileConfig implements SMPPConfigManager {
private String host;
private int port;
private String systemId;
private String password;
private String systemType;
private TypeOfNumber sourceAddrTon;
private TypeOfNumber destAddrTon;
private NumberingPlanIndicator sourceAddrNpi;
private NumberingPlanIndicator destAddrNpi;
private String addressRange;
private int connectTimeout;
private long reconnectInterval;
private String sourceAddr;
private String destinationAddr;
private SMSCDeliveryReceipt deliveryReceipt;
private RegisteredDelivery registeredDelivery;
private BindType bindType;
private ESMClass esmClass;
private byte protocolId;
private byte priorityFlag;
private String scheduleDeliveryTime;
private String validityPeriod;
private byte replaceIfPresentFlag;
private GeneralDataCoding generalDataCoding;
private boolean generalDataCoding_compressed = true;
private boolean generalDataCoding_containMessageClass = true;
private MessageClass generalDataCoding_messageClass = MessageClass.CLASS1;
private Alphabet generalDataCoding_alphabet = Alphabet.ALPHA_DEFAULT;
private byte smDefaultMsgId;
private long transactionTimer;
private int enquireLinkTimer;
public SMPPFileConfig(Properties prop) {
this.host = prop.getProperty("smpp.host");
this.port = Integer.parseInt(prop.getProperty("smpp.port"));
this.systemId = prop.getProperty("smpp.systemId");
this.password = prop.getProperty("smpp.password");
this.systemType = prop.getProperty("smpp.systemType");
this.sourceAddrTon = getTypeOfNumber(SMPPConfigManager.AddrTon.SOURCE, prop);
this.destAddrTon = getTypeOfNumber(SMPPConfigManager.AddrTon.DEST, prop);
this.sourceAddrNpi = getNumberingPlanIndicator(SMPPConfigManager.AddrNpi.SOURCE, prop);
this.destAddrNpi = getNumberingPlanIndicator(SMPPConfigManager.AddrNpi.DEST, prop);
this.addressRange = prop.getProperty("smpp.addressRange");
this.connectTimeout = Integer.parseInt(prop.getProperty("smpp.connect.timeout"));
this.reconnectInterval = Long.parseLong(prop.getProperty("smpp.reconnect.interval"));
this.sourceAddr = prop.getProperty("smpp.sourceAddr");
this.destinationAddr = null;
this.deliveryReceipt = getSMSCDeliveryReceipt(prop.getProperty("smpp.SMSC.delivery.receipt"));
this.registeredDelivery = new RegisteredDelivery(deliveryReceipt);
this.bindType = getBindTypeFromProp(prop.getProperty("smpp.bindType"));
this.esmClass = createESMClass(prop.getProperty("smpp.ESMClass.MessageMode"), prop.getProperty("smpp.ESMClass.MessageType"), prop.getProperty("smpp.ESMClass.GSMSpecificFeature"));
this.protocolId = new Byte(prop.getProperty("smpp.protocolId"));
this.priorityFlag = new Byte(prop.getProperty("smpp.priorityFlag"));
this.scheduleDeliveryTime = prop.getProperty("smpp.scheduleDeliveryTime");
this.validityPeriod = prop.getProperty("smpp.validityPeriod");
this.replaceIfPresentFlag = new Byte(prop.getProperty("smpp.replaceIfPresentFlag"));
this.generalDataCoding = new GeneralDataCoding(generalDataCoding_compressed, generalDataCoding_containMessageClass, generalDataCoding_messageClass, generalDataCoding_alphabet);
this.smDefaultMsgId = new Byte(prop.getProperty("smpp.smDefaultMsgId"));
this.transactionTimer = Long.parseLong(prop.getProperty("smpp.transactionTimer"));
this.enquireLinkTimer = Integer.parseInt(prop.getProperty("smpp.enquireLinkTimer"));
}
#Override
public String toString() {
return "SMPPFileConfig{" + "host=" + host + ", port=" + port + ", systemId=" + systemId + ", password=" + password + ", systemType=" + systemType + ", sourceAddrTon=" + sourceAddrTon + ", destAddrTon=" + destAddrTon + ", sourceAddrNpi=" + sourceAddrNpi + ", destAddrNpi=" + destAddrNpi + ", addressRange=" + addressRange + ", connectTimeout=" + connectTimeout + ", reconnectInterval=" + reconnectInterval + ", sourceAddr=" + sourceAddr + ", destinationAddr=" + destinationAddr + ", deliveryReceipt=" + deliveryReceipt + ", registeredDelivery=" + registeredDelivery + ", bindType=" + bindType + ", esmClass=" + esmClass + ", protocolId=" + protocolId + ", priorityFlag=" + priorityFlag + ", scheduleDeliveryTime=" + scheduleDeliveryTime + ", validityPeriod=" + validityPeriod + ", replaceIfPresentFlag=" + replaceIfPresentFlag + ", generalDataCoding=" + generalDataCoding + ", generalDataCoding_compressed=" + generalDataCoding_compressed + ", generalDataCoding_containMessageClass=" + generalDataCoding_containMessageClass + ", generalDataCoding_messageClass=" + generalDataCoding_messageClass + ", generalDataCoding_alphabet=" + generalDataCoding_alphabet + ", smDefaultMsgId=" + smDefaultMsgId + '}';
}
#Override
public String getAddressRange() {
return addressRange;
}
#Override
public int getConnectTimeout() {
return connectTimeout;
}
#Override
public SMSCDeliveryReceipt getDeliveryReceipt() {
return deliveryReceipt;
}
#Override
public RegisteredDelivery getRegisteredDelivery() {
return registeredDelivery;
}
#Override
public NumberingPlanIndicator getDestAddrNpi() {
return destAddrNpi;
}
#Override
public TypeOfNumber getDestAddrTon() {
return destAddrTon;
}
#Override
public void setDestinationAddr(String destinationAddr) {
this.destinationAddr = destinationAddr;
}
#Override
public String getDestinationAddr() {
return destinationAddr;
}
#Override
public String getHost() {
return host;
}
#Override
public String getPassword() {
return password;
}
#Override
public int getPort() {
return port;
}
#Override
public long getReconnectInterval() {
return reconnectInterval;
}
#Override
public String getSourceAddr() {
return sourceAddr;
}
#Override
public NumberingPlanIndicator getSourceAddrNpi() {
return sourceAddrNpi;
}
#Override
public TypeOfNumber getSourceAddrTon() {
return sourceAddrTon;
}
#Override
public String getSystemId() {
return systemId;
}
#Override
public String getSystemType() {
return systemType;
}
#Override
public BindType getBindType() {
return bindType;
}
#Override
public ESMClass getESMClass() {
return esmClass;
}
#Override
public void setESMClass(ESMClass esmClass) {
this.esmClass = esmClass;
}
#Override
public byte getProtocolId() {
return protocolId;
}
#Override
public byte getPriorityFlag() {
return priorityFlag;
}
#Override
public String getScheduleDeliveryTime() {
return scheduleDeliveryTime;
}
#Override
public String getValidityPeriod() {
return validityPeriod;
}
#Override
public byte getReplaceIfPresentFlag() {
return replaceIfPresentFlag;
}
#Override
public GeneralDataCoding getGeneralDataCoding() {
return generalDataCoding;
}
#Override
public byte getsmDefaultMsgId(){
return smDefaultMsgId;
}
#Override
public long getTransactionTimer()
{
return transactionTimer;
}
#Override
public int getEnquireLinkTimer()
{
return enquireLinkTimer;
}
private ESMClass createESMClass(String messageMode, String messageType, String GSMSpecificFeature) {
return new ESMClass(getESMClassMessageMode(messageMode), getESMMessageType(messageType), getESMGSMSpecificFeature(GSMSpecificFeature));
}
private MessageMode getESMClassMessageMode(String type) {
if (type.equals("DEFAULT")) {
return MessageMode.DEFAULT;
} else if (type.equals("DATAGRAM")) {
return MessageMode.DATAGRAM;
} else if (type.equals("STORE_AND_FORWARD")) {
return MessageMode.STORE_AND_FORWARD;
} else if (type.equals("TRANSACTION")) {
return MessageMode.TRANSACTION;
} else {
return null;
}
}
private MessageType getESMMessageType(String type) {
if (type.equals("DEFAULT")) {
return MessageType.DEFAULT;
} else if (type.equals("CONV_ABORT")) {
return MessageType.CONV_ABORT;
} else if (type.equals("ESME_DEL_ACK")) {
return MessageType.ESME_DEL_ACK;
} else if (type.equals("ESME_MAN_ACK")) {
return MessageType.ESME_MAN_ACK;
} else if (type.equals("INTER_DEL_NOTIF")) {
return MessageType.INTER_DEL_NOTIF;
} else if (type.equals("SME_DEL_ACK")) {
return MessageType.SME_DEL_ACK;
} else if (type.equals("SME_MAN_ACK")) {
return MessageType.SME_MAN_ACK;
} else if (type.equals("SMSC_DEL_RECEIPT")) {
return MessageType.SMSC_DEL_RECEIPT;
} else {
return null;
}
}
private GSMSpecificFeature getESMGSMSpecificFeature(String type) {
if (type.equals("DEFAULT")) {
return GSMSpecificFeature.DEFAULT;
} else if (type.equals("REPLYPATH")) {
return GSMSpecificFeature.REPLYPATH;
} else if (type.equals("UDHI")) {
return GSMSpecificFeature.UDHI;
} else if (type.equals("UDHI_REPLYPATH")) {
return GSMSpecificFeature.UDHI_REPLYPATH;
} else {
return null;
}
}
private BindType getBindTypeFromProp(String type) {
//String type = prop.getProperty("smpp.bindType");
if (type.equals("BIND_RX")) {
return BindType.BIND_RX;
} else if (type.equals("BIND_TX")) {
return BindType.BIND_TX;
} else if (type.equals("BIND_TRX")) {
return BindType.BIND_TRX;
} else {
return null;
}
}
private TypeOfNumber getTypeOfNumber(SMPPConfigManager.AddrTon ton, Properties prop) {
String type;
if (ton == SMPPConfigManager.AddrTon.SOURCE) {
type = prop.getProperty("smpp.sourceAddrTon");
} else {
type = prop.getProperty("smpp.destAddrTon");
}
if (type.equals("ABBREVIATED")) {
return TypeOfNumber.ABBREVIATED;
} else if (type.equals("ALPHANUMERIC")) {
return TypeOfNumber.ALPHANUMERIC;
} else if (type.equals("INTERNATIONAL")) {
return TypeOfNumber.INTERNATIONAL;
} else if (type.equals("NATIONAL")) {
return TypeOfNumber.NATIONAL;
} else if (type.equals("NETWORK_SPECIFIC")) {
return TypeOfNumber.NETWORK_SPECIFIC;
} else if (type.equals("SUBSCRIBER_NUMBER")) {
return TypeOfNumber.SUBSCRIBER_NUMBER;
} else if (type.equals("UNKNOWN")) {
return TypeOfNumber.UNKNOWN;
} else {
return null;
}
}
private SMSCDeliveryReceipt getSMSCDeliveryReceipt(String type) {
//String type = prop.getProperty("smpp.SMSC.delivery.receipt");
if (type.equals("DEFAULT")) {
return SMSCDeliveryReceipt.DEFAULT;
} else if (type.equals("SUCCESS")) {
return SMSCDeliveryReceipt.SUCCESS;
} else if (type.equals("SUCCESS_FAILURE")) {
return SMSCDeliveryReceipt.SUCCESS_FAILURE;
} else {
return null;
}
}
private NumberingPlanIndicator getNumberingPlanIndicator(SMPPConfigManager.AddrNpi npi, Properties prop) {
String type;
if (npi == SMPPConfigManager.AddrNpi.SOURCE) {
type = prop.getProperty("smpp.sourceAddrNpi");
} else {
type = prop.getProperty("smpp.destAddrNpi");
}
if (type.equals("DATA")) {
return NumberingPlanIndicator.DATA;
} else if (type.equals("ERMES")) {
return NumberingPlanIndicator.ERMES;
} else if (type.equals("INTERNET")) {
return NumberingPlanIndicator.INTERNET;
} else if (type.equals("ISDN")) {
return NumberingPlanIndicator.ISDN;
} else if (type.equals("LAND_MOBILE")) {
return NumberingPlanIndicator.LAND_MOBILE;
} else if (type.equals("NATIONAL")) {
return NumberingPlanIndicator.NATIONAL;
} else if (type.equals("PRIVATE")) {
return NumberingPlanIndicator.PRIVATE;
} else if (type.equals("TELEX")) {
return NumberingPlanIndicator.TELEX;
} else if (type.equals("WAP")) {
return NumberingPlanIndicator.WAP;
} else if (type.equals("UNKNOWN")) {
return NumberingPlanIndicator.UNKNOWN;
} else {
return null;
}
}
}
when you submit current time as scheduled delivery time this error may occur.because it takes some time to send request. so the time you mentioned might be in past .so set the scheduled delivery time to (current time + 10 seconds )
long TEN_SECONDS=10000;//millisecs
Calendar date = Calendar.getInstance();
long t= date.getTimeInMillis();
Date scheduleDeliveryTime=new Date(t + ( TEN_SECONDS));