Help with writing a static method in my test case class inside blue j

I have this method that I have to test. below is the method I need to test and what I have to create inside my test case file to test it Im having big time problems getting going. Any help is appreciated.
public String introduceSurprise ( String first, String last ) {
int d1 = dieOne.getFace();
Die.roll();
if (d1 %4 == 2){
return Emcee.introduce(first);
else {
return this.introduceSpy (first,last);
So how do write tests to verify that every fourth call really does give a randomized answer? Write a static method showTests which
creates an EmCee,
calls introduceSurprise three times (doing nothing with the result (!)),
and then calls it a fourth time, printing the result to the console window.
Write this code inside your test class TestEmCee, not inside EmCee!

hammer wrote:
So how do write tests to verify that every fourth call really does give a randomized answer? Write a static method showTests which
creates an EmCee,
calls introduceSurprise three times (doing nothing with the result (!)),
and then calls it a fourth time, printing the result to the console window.
Write this code inside your test class TestEmCee, not inside EmCee!Those instructions couldn't be anymore straightforward. Make a class called TestEmCee. Have it create an EmCee object. Call introduceSurprise on that object 3 times. Then print the results of calling it a 4th time.

Similar Messages

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Help with writing a formula

    Hi all,
    I am creating a report, and need help with writing a formula...
    I am creating a report that shows how many visits/touches our reps have made to various grade accounts. It is broken down by calendar week, and I currently have a weekly "goal" number set that the reps have to meet. That "goal" number increases each week to keep a running total. (example: week 1: 7, week 2: 14, week 3: 21)
    I have created some different formulas and one is this:
    SUM("Activity Metrics"."# of Activities" BY Date."Calendar Week")
    What this shows me is how many "visits" there are per calendar week to customers, however it show me the total for all reps per week.
    What I need is that total to show, but totaled for each rep individually.
    What I was trying is this:
    SUM("Activity Metrics"."# of Activities" BY Date."Calendar Week") BY Employee."Employee Name"
    But...I keep getting an error.
    Any suggestions?
    I have the reporting book by Lairson, and have been referring to it...but my brain at this point is fried.
    Thanks in advance for any help...(please forgive...I am new to OnDemand, and I am sure this is easy)

    Thanks for helping!
    I created this formula as a column: SUM ("Activity Metrics"."# of Activities" BY Date."Calendar Week"), it is called "total number of visits per week" and it shows the totaled number of visits that all the reps have done per calendar week. For example: Week 1: 10 visits, Week 2: 37 visits, Week 3: 20 visits.
    What I would like to do is take that column and break it down further, to show instead how many visits per week by sales rep there have been
    So what I was trying was to take the "total number of visits per week" (SUM ("Activity Metrics"."# of Activities" BY Date."Calendar Week")) and use "Activity Owner" (Employee."Employee Name") to break it down further.
    What I need to use is the total number of visits each rep has per calendar week.
    I think I am getting the error because you can't use "BY" twice in a formula?

  • Help with writing .bashrc file

    I would like help with writing a .bashrc file.
    The only thing I want right now is colored output and slashes for directories like what "ls -GF" does -- for each new terminal window.
    Can you guys give me a hand?
    Running Mac OS 10.4.6. Bash is default shell.
    Thanks.

    Hi Paul,
       You can get Apple's "ls" command to always output color with the following in your .bashrc:
    export CLICOLOR=""
    You can have an effect on the colors used with settings like the following:
    export LSCOLORS="gxfxcxdxbxegedabafacad"
       I have a color prompt in my bash startup scripts, bashrc.tgz. If you unpack the tarball in the root of your home directory, the files will be put in a ~/Library/init/bash directory. The file named "prompt" sets the color prompt string.
    Gary
    ~~~~
       I know you think you thought you knew what you
       thought I said, but I'm not sure you understood what
       you thought I meant.

  • Please help with writing a class

    i need help getting started with this assignment. i haven't done anything with writing classes, so i don't know where to start.
    i need to create a bank account class that will keep a name, balance, up to 50 deposits, and up to 50 withdrawls. i need to include 2 arrays for the deposits and withdrawls.
    Here's what i know:
    I need a constructor that takes zero arguments. This constructor would initialize the numeric value to zero.
    I need a 2nd constructor that takes one argument, a name as a String value. This constructor would initialize the numeric value to zero.
    I need a 3rd constructor that takes two arguments, a name as a String value and a starting "balance" as a double value

    Sorry, I was watching a movie with my wife ...imagine that. Study my examples here and try to understand what I have done. You will follow the same methodology for the rest of the program. Use main to test the methods in your program.
    public class mdlAccount {
      String name;
      double balance;
      int currentDeposit = 0;
      int currentWithdrawl = 0;
      double[] deposits = new double[50];
      double[] withdrawals = new double[50];
      public mdlAccount() {
        name = "";
        balance = 0.0;
      public mdlAccount(String name) {
        this.name = name;
        balance = 0.0;
      public mdlAccount(String name, double balance) {
        this.name = name;
        this.balance = balance;
      // When the instructor says: Have a method that does deposits...
      // You need to create a method, similar to the constructors,
      // but with a return value, even if it returns void (nothing).
      // Like this:
      public void deposit( double amount ) {
        // Do some error checking.
        if ( currentDeposit < 50 && amount > 0 ) { // > is a greater than sign
          // If all is ok, add to the balance...
          balance += amount;
          // and add the entry to the array of deposits
          deposits[currentDeposit] = amount;
          // Finally, add 1 to the currentDeposit variable.
          currentDeposit++;
      // We need the 'return the balance' method so we can see if
      // the program runs correctly. This time we return a double,
      // instead of void. (void means don't return anything at all).
      public double getBalance() {
        return balance;
    // Now you create the next method for withdrawals...
    //  if ( currentWithdrawl < 50 ) {
    //    deposits[currentWithdrawl] = amount;
    //    currentWithdrawl++;
      // You want a main method so this class can be executed.
      // You can remove it later if you want to use this class
      // from within another larger program.
      public static void main(String[] args) {
        mdlAccount acct = new mdlAccount( "GumB", 100.0 );
        System.out.println("Initial balance is " + acct.getBalance());
        acct.deposit( 50.0 );
        System.out.println("Current balance is " + acct.getBalance());

  • Need help with usage of static functions

    Hi,
    I tried instantiating objects within static functions as follows: It gives error:
    If someone can explain an alternate way of doing things, I would appreciate:
    public class C {
    * @param args
    public static void main(String[] args) {
    Y.Fn1();
    public class X {
    public void Fn2(){
    int b=2;
    System.out.println("hello");
    public class Y {
    public static void Fn1()
    int a=2;
    X obj = new X();
    obj.Fn2();
    The actual error is:
    Cannot make a static referencxe to the nonstatic method Fn2() from the type X Y.java
    Need Help : If someone can comment on the following, I would appreciate:
    I have a class Session, which has a method ProcessEvent()
    public class Session{
    public synchronized void processEvent(Event e)
    // Processing of the event
    // Generate a response for the Event
    This Session class is the mainstream code..
    Now I want to write a TestClass that will test the main code.
    So I have a Test class as below:
    public class Test {
    public static void sendReq()
    // Construct an event and call processEvent Function from the main code
    Event ev = new Event();
    // Fill the event with parameters
    Session sess = new Session();
    sess.processEvent(ev);
    What I am thinking of doing is: Call the static method in another class called Manager of the mainstream code for test purpose as follows:
    public class Manager {
    public void somefunction()
    //*** Just for test purpose: do the following line **//
    Test.sendReq();
    I am not sure what I am trying to do will work. I would appreciate if you can comment on that or suggest something that would work for me.
    Another thing which I want to do is:
    Inside ProcessEvent(), I want to call another static method ParseandValidateResponse() of the TestClass This looks odd, but as long as it works, it would be fine for me because this is only for test purpose.
    In this case, I would write,
    public class Session{
    public synchronized void processEvent(Event e)
    // Processing of the event
    // Generate a response for the Event
    Test.parseandValidateResponse(Response res);
    public class Test {
    public static void sendReq()
    // AS SHOWN PREVIOUSLY
    public static void parseandValidateResponse(Response resp)
    // validate the response
    }

    Sorry I thought no one had replied. When I posted here, I missed seeing yr reply. Later just now I saw yr reply It was in the second Page
    (Earlier I was looking only in first page by mistake)
    Meena

  • Help with writing a batch file

    Hi :
    does anyone know anyplace online that I can get help in writing batch files?? I have never worked much with batch files before....
    any help is greatly appreciated
    thnx

    I suppose, since you're in a Java forum, you need batch files to load java applications.
    If you use windows :
    go to ms console (start/run/"cmd")
    type edit mybatch.bat
    write your command to load a java application, something like
    java myclass.class
    save and exit.
    Be sure the bat file and the class are in the same folder.
    And make certain you've set the classpath, and path variables correctly.
    If this was what you needed and you need more help just ask.
    (In this case it could be better to make executable jars)
    If you wanted to know about linux batches, it works pretty the same way.

  • Need help with writing a rule

    Need help with some rules. I want to book a number to a specific Entity at a Specific Custom 4 only. I don't want this formula to work at all C4 levels. How can this be done?
    for example if Entity is "XBM1123" and we use C4 for tracking and the tracking level I want to book it to is IMPORT, how can this be done for a specific account 4400221
    I have my formula as
    If pov_value = "<Entity Currency>" or pov_value = "<Entity Curr Adjs>" Then
    If HS.Entity.Member = "XBM1123" or HS.Custom4.Member = "IMPORT" then
    HS.EXP "A#4400221= A#4521111 + A#3526644 + A#635210"
    End If
    End if
    this did not work. I got hte following error
    Calculate started.<BR>Error executing VBScript Microsoft VBScript runtime
    error, Line 259:Object doesn't support this property or method:
    'HS.Custom4.Member'.<BR>Calculate finished.<BR>Error executing
    VBScript %0.
    I then changed it to the below and it still did not work
    If pov_value = "<Entity Currency>" or pov_value = "<Entity Curr Adjs>" Then
    If HS.Entity.Member = "XBM1123" then
    HS.EXP "A#4400221.C4#IMPORT= A#4521111 + A#3526644 + A#635210"
    End If
    End if
    error
    Invalid Custom1 member
    specified for this function.
    Invalid Destination specified for this function:
    A#4400221.C4#IMPORT.

    You are close.
    Try:
    If pov_value = "<Entity Currency>" or pov_value = "<Entity Curr Adjs>" Then
        If HS.Entity.Member = "XBM1123" then
           HS.EXP "A#4400221.C4#IMPORT= A#4521111.C4#IMPORT + A#3526644.C4#IMPORT + A#635210.C4#IMPORT"
        End If
    End if
    or replace IMPORT with with Top_C4 or what ever member you need to copy to C4#IMPORT.
    Rule of thumb, to be on the safe side and for most simple calcs, is if you mention a dimension on the left side, you need to define it on the right side as well.

  • Help with writing, reading a file...

    I'm writing a program that writes a number to a file and then reads it again each time it is loaded. It's like a counter, the number starts out being 0, then when the program is run again the number will be two, and so on and so on. I've never been good with writing incrementer type things and files, so could you help me out? Remember, the program writes a single number to the file, and then adds one to that number each time the program is run, so it starts at zero and goes up by one each time it is run.
    -Thanks... I just came back from vacation and my Java skills are somewhat lacking :P

    open old file -> get the number -> create a new file -> write new number

  • Help to solve the static method....pls.

    package readtext;
    import java.io.*; // For input & output classes
    import java.util.Date; // For the Date class
    public class Main {
    public Main() {
    public static void main(String[] args)
    throws IOException{
    BufferedReader in = new BufferedReader(
    new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));
    *use ' ' as a separator, and rearrange back the datastream column
    String text;
    while ((text = in.readLine()) != null)
    int count = 0; // Number of substrings
    char separator = ' '; // Substring separator
    // Determine the number of substrings
    int index = 0;
    do
    ++count; // Increment count of substrings
    ++index; // Move past last position
    index = text.indexOf(separator, index);
    while (index != -1);
    // Extract the substring into an array
    String[] subStr = new String[count]; // Allocate for substrings
    index = 0; // Substring start index
    int endIndex = 0; // Substring end index
    for(int i = 0; i < count; i++)
    endIndex = text.indexOf(separator,index); // Find next separator
    if(endIndex == -1) // If it is not found
    subStr[i] = text.substring(index); // extract to the end
    else // otherwise
    subStr[i] = text.substring(index, endIndex); // to end index
    index = endIndex + 1; // Set start for next cycle
    String dirName = "C:/Documents and Settings/seng/Desktop/testfile";
    // Directory name
    File aFile = new File(dirName, "data.txt");
    aFile.createNewFile(); // Now create a new file if necessary
    if(!aFile.isFile()) // Verify we have a file
    System.out.println("Creating " + aFile.getPath() + " failed.");
    return;
    BufferedWriter out = new BufferedWriter(new FileWriter(aFile.getPath(), true));
    * Display output at data.txt file
    // provide initial (X,Y,Z) coordinates for mobiles
    out.write("$node_(" + subStr[0] + ") set X_ " + subStr[0] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Y_ " + subStr[1] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Z_ " + subStr[2] +
    System.getProperty("line.separator"));
    out.flush();
    out.close();
    package readtext;
    import java.io.*; // For input & output classes
    import java.util.Date; // For the Date class
    public class create_table {
    public create_table() {
    public static void main(String[] args)
    throws IOException{
    BufferedReader in = new BufferedReader(
    new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));
    *use ' ' as a separator, and rearrange back the datastream column
    String text;
    while ((text = in.readLine()) != null)
    substring(subStr); //problem at here
    String dirName = "C:/Documents and Settings/seng/Desktop/testfile";
    // Directory name
    File aFile = new File(dirName, "data.txt");
    aFile.createNewFile(); // Now create a new file if necessary
    if(!aFile.isFile()) // Verify we have a file
    System.out.println("Creating " + aFile.getPath() + " failed.");
    return;
    BufferedWriter out = new BufferedWriter(new FileWriter(aFile.getPath(), true));
    * Display output at data.txt file
    // problem at here
    // provide initial (X,Y,Z) coordinates for mobiles
    out.write("$node_(" + subStr[0] + ") set X_ " + subStr[0] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Y_ " + subStr[1] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Z_ " + subStr[2] +
    System.getProperty("line.separator"));
    out.flush();
    out.close();
    static void substring(String[] subStr)
    int count = 0; // Number of substrings
    char separator = ' '; // Substring separator
    String text;
    // Determine the number of substrings
    int index = 0;
    do
    ++count; // Increment count of substrings
    ++index; // Move past last position
    index = text.indexOf(separator, index);
    while (index != -1);
    // Extract the substring into an array
    subStr = new String[count]; // Allocate for substrings
    index = 0; // Substring start index
    int endIndex = 0; // Substring end index
    for(int i = 0; i < count; i++)
    endIndex = text.indexOf(separator,index); // Find next separator
    if(endIndex == -1) // If it is not found
    subStr[i] = text.substring(index); // extract to the end
    else // otherwise
    subStr[i] = text.substring(index, endIndex); // to end index
    index = endIndex + 1; // Set start for next cycle
    *on top is the original code, bottom is after modified
    i would like to create a static method for the static void substring(String[] subStr). But when i use the substring() on the main program, the compiler give me error. Is that my substring () created wrongly?? pls help...

    package readtext;
    import java.io.*; // For input & output classes
    import java.util.Date; // For the Date class
    public class Main {
    public Main() {
    public static void main(String[] args)
    throws IOException{
    BufferedReader in = new BufferedReader(
    new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));
    *use ' ' as a separator, and rearrange back the datastream column
    String text;
    while ((text = in.readLine()) != null)
    int count = 0; // Number of substrings
    char separator = ' '; // Substring separator
    // Determine the number of substrings
    int index = 0;
    do
    ++count; // Increment count of substrings
    ++index; // Move past last position
    index = text.indexOf(separator, index);
    while (index != -1);
    // Extract the substring into an array
    String[] subStr = new String[count]; // Allocate for substrings
    index = 0; // Substring start index
    int endIndex = 0; // Substring end index
    for(int i = 0; i < count; i++)
    endIndex = text.indexOf(separator,index); // Find next separator
    if(endIndex == -1) // If it is not found
    subStr = text.substring(index); // extract to the end
    else // otherwise
    subStr = text.substring(index, endIndex); // to end index
    index = endIndex + 1; // Set start for next cycle
    String dirName = "C:/Documents and Settings/seng/Desktop/testfile";
    // Directory name
    File aFile = new File(dirName, "data.txt");
    aFile.createNewFile(); // Now create a new file if necessary
    if(!aFile.isFile()) // Verify we have a file
    System.out.println("Creating " + aFile.getPath() + " failed.");
    return;
    BufferedWriter out = new BufferedWriter(new FileWriter(aFile.getPath(), true));
    * Display output at data.txt file
    // provide initial (X,Y,Z) coordinates for mobiles
    out.write("$node_(" + subStr[0] + ") set X_ " + subStr[0] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Y_ " + subStr[1] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Z_ " + subStr[2] +
    System.getProperty("line.separator"));
    out.flush();
    out.close();
    package readtext;
    import java.io.*;                            // For input & output classes
    import java.util.Date;                       // For the Date class
    public class create_table {
       public create_table() {
       public static void main(String[] args)
       throws IOException{
      BufferedReader in = new BufferedReader(
              new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));
       *use ' ' as a separator, and rearrange back the datastream column
       String text;
       while ((text = in.readLine()) != null)
        String[] subStr;
         String[] substring;
         int i;
       substring(subStr); //PROBLEM: substring in readtext can not apply
    String dirName = "C:/Documents and Settings/seng/Desktop/testfile";
    // Directory name
    File aFile = new File(dirName, "data.txt");
    aFile.createNewFile(); // Now create a new file if necessary
    if(!aFile.isFile()) // Verify we have a file
    System.out.println("Creating " + aFile.getPath() + " failed.");
    return;
    BufferedWriter out = new BufferedWriter(new FileWriter(aFile.getPath(), true));
    * Display output at data.txt file
    // provide initial (X,Y,Z) coordinates for mobiles
    out.write("$node_(" + subStr[0] + ") set X_ " + subStr[0] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Y_ " + subStr[1] +
    System.getProperty("line.separator") +
    "$node_(" + subStr[0] + ") set Z_ " + subStr[2] +
    System.getProperty("line.separator"));
    out.flush();
    out.close();
    static void substring(String[] subStr)
    int count = 0; // Number of substrings
    char separator = ' '; // Substring separator
    String text;
    // Determine the number of substrings
    int index = 0;
    do
    ++count; // Increment count of substrings
    ++index; // Move past last position
    index = text.indexOf(separator, index);
    while (index != -1);
    // Extract the substring into an array
    subStr = new String[count]; // Allocate for substrings
    index = 0; // Substring start index
    int endIndex = 0; // Substring end index
    for(int i = 0; i < count; i++)
    endIndex = text.indexOf(separator,index); // Find next separator
    if(endIndex == -1) // If it is not found
    subStr[i] = text.substring(index); // extract to the end
    else // otherwise
    subStr[i] = text.substring(index, endIndex); // to end index
    index = endIndex + 1; // Set start for next cycle
    the problem is here
       String text;
       while ((text = in.readLine()) != null)
        String[] subStr;
         String[] substring;
         int i;
       substring(subStr); //PROBLEM: substring in readtext can not apply
    String dirName = "C:/Documents and Settings/seng/Desktop/testfile";
    the system say that my substring(subStr[i]) (java.lang.String[])in read.text can not applied to (java.lang.String)...how can i solve for tis problem? is that i have to use for loop to create an array for subStr???

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Help with Deque, insertRight() removeLeft() Methods in particular

    Hello,
    I am attempting to implement a deque, I have working insert left and remove right methods as a normal queue works. --->
    However I am having trouble implementing my insert right and remove left methods... keep hitting an array out of bounds problem, guess my wrap arounds aren't working properly. I've tried drawing this out, and I still can't seem to get this to work, can someone please help?
          * Javadoc Here
         public void insertRight(long j) {
              if (front == - 1)
                   front = maxSize-1;
              queArray[++front] = j;
              nItems++; // one more item
          * Javadoc Here
         public long removeLeft() {
              long temp = queArray[rear--];
              if (rear == -1)
                   rear = maxSize;
              nItems--; // one less item
              return temp;
         }

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
         at Deque.removeLeft(Deque.java:71)
         at DequeApp.main(Deque.java:134)
    My javadocs are written because im still in the process of writing the damn thing, give me a break please?
    * This class is to demonstrate.....
    * @version 1.0
    public class Deque {
         private int maxSize;
         private long[] queArray;
         private int front;
         private int rear;
         private int nItems;
          * Java Doc
         public Deque(int s) // constructor
              maxSize = s;
              queArray = new long[maxSize];
              front = 0;
              rear = -1;
              nItems = 0;
          * Javadoc Here
         public void insertLeft(long j) {
              if (rear == maxSize - 1) // deal with wraparound
                   rear = -1;
              queArray[++rear] = j; // increment rear and insert
              nItems++; // one more item
          * Javadoc Here
         public long removeRight() {
              long temp = queArray[front++]; // get value and incr front
              if (front == maxSize) // deal with wraparound
                   front = 0;
              nItems--; // one less item
              return temp;
               * Javadoc Here
              public void insertRight(long j) {
                   if (front == - 1)
                        front = maxSize-1;
                   queArray[++front] = j;
                   nItems++; // one more item
               * Javadoc Here
              public long removeLeft() {
                   long temp = queArray[rear--];
                   if (rear == -1)
                        rear = maxSize;
                   nItems--; // one less item
                   return temp;
          * Javadoc Here
         public boolean isEmpty() {
              return (nItems == 0);
          * Javadoc Here
         public boolean isFull() {
              return (nItems == maxSize);
    }// end Deque Class
    class DequeApp {
         public static void main(String[] args) {
              Deque q1 = new Deque(5); // queue holds 5 items
              q1.insertLeft(10); // insert 4 items
              q1.insertLeft(20);
              q1.insertLeft(30);
              q1.insertLeft(40);
              q1.removeRight(); // remove 3 items
              q1.removeRight(); // (10, 20, 30)
              q1.removeRight();
              q1.insertLeft(50); // insert 4 more items
              q1.insertLeft(60); // (wraps around)
              q1.insertLeft(70);
              q1.insertLeft(80);
              while (!q1.isEmpty()) // remove and display
              { // all items
                   long n = q1.removeRight(); // (40, 50, 60, 70, 80)
                   System.out.print(n);
                   System.out.print(" ");
              System.out.println("----->");
              Deque q2 = new Deque(5); // queue holds 5 items
              q2.insertRight(10); // insert 4 items
              q2.insertRight(20);
              q2.insertRight(30);
              q2.insertRight(40);
              q2.removeLeft(); // remove 3 items
              q2.removeLeft(); // (10, 20, 30)
              q2.removeLeft();
              q2.insertRight(50); // insert 4 more items
              q2.insertRight(60); // (wraps around)
              q2.insertRight(70);
              q2.insertRight(80);
              while (!q2.isEmpty()) // remove and display
              { // all items
                   long n = q2.removeLeft(); // (40, 50, 60, 70, 80)
                   System.out.print(n);
                   System.out.print(" ");
              System.out.println("<-----");
         } // end main()
    } // end class DequeApp
    // //////////////////////////////////////////////////////////////

  • Need help with a reverse number method

    hey all..
    i have this program which should return the integer reversed ..
    i have done this program using methods.. but the problem is if the
    number endes with 0 when it reversed the output doesn't contain the number 0
    for example:
    input
    123450
    output
    54321
    where before the 5 there should be 0
        This program that reads an integer and then calls a method
          that receives an integer and returns the integer with its digits reversed.
          Main prints the resulting integer.
       import java.util.Scanner; // program uses class Scanner
        class Sh9q4
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int number; // The number entered by the user
             System.out.println("Enter an integer"); // prompt for input
             number = input.nextInt(); // read the the integer
             reverse (number); // print the method reverse
          } // end method main
           public static void reverse ( int num )
             int lastDigit; // the last digit returned when reversed
             int reverse = 0;
             do
                lastDigit = num % 10;
                reverse = (reverse * 10) + lastDigit;
                num = num / 10;
             while (num > 0);
             System.out.println("The integer with its digits reversed " + reverse); // print the integer reversed
          }// end method reverse
       } // end class Sh9q4thanks for your help :)

    If you need the leading zero to display, then you will have to do as Keith recommended and convert the input number to a String, then reverse that String and print it as a String.
    A number is a number is a numerical value, and there is no difference between the value of 054321 and 54321 except when written as a literal, when the first is an octal, and the second a decimal, value.
    If you are still confused, plug in these few lines of code and run them:String str = "012345";
    int x = Integer.parseInt (str);
    System.out.println(str);
    System.out.println(x);db

  • Help with writing to a file

    First off...I'm just a student so please bear with me...
    I'm having problems with the following bit of code. I don't seem to be understanding the correct way to write to a file. It's not a complete program and my drop down box isn't set up to write yet...but I'm just trying to get SOMETHING as output to the file. Any help is appreciated! Here's my code:
    Mid-Term Test
    Programmer: Abraham Violett
    Date: 8-12-04
    Filename: MowersInc.java
    Purpose: This will be a data entry and retrival system
    for a
    small lawn mowing company.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MowersInc extends JFrame implements ActionListener
    JLabel blankLabel = new JLabel("");
    JLabel titleLabel = new JLabel(" Mowers Incorporated");
    JLabel firstNameLabel = new JLabel("First Name:");
    JTextField firstNameTextField = new JTextField(15);
    JTextField lastNameTextField = new JTextField(15);
    JLabel lastNameLabel = new JLabel("Last Name:");
    JComboBox lawnSizeCombo = new JComboBox();
    JButton submitInfoButton = new JButton("Submit");
    JButton clearInfoButton = new JButton("Clear");
    DataOutputStream output;
    public MowersInc()
    super("Mowers Inc.");
    try
    output = new DataOutputStream(new FileOutputStream("customers.dat"));
    catch(IOException io)
    JOptionPane.showMessageDialog(null, "Could not create storage location.", "Error", JOptionPane.INFORMATION_MESSAGE);
    System.exit(1);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public void actionPerformed(ActionEvent e)
    String arg = e.getActionCommand();
    int fee;
    if (e.getSource() == lawnSizeCombo)
    switch (lawnSizeCombo.getSelectedIndex())
    case 0:
    fee = 50;
    break;
    case 1:
    fee = 75;
    break;
    default:
    break;
    if(arg == "Submit")
    try
    output.writeUTF(firstNameLabel.getText());
    output.writeUTF(lastNameLabel.getText());
    catch(IOException io)
    JOptionPane.showMessageDialog(null, "Could not create storage location.", "Error", JOptionPane.INFORMATION_MESSAGE);
    System.exit(1);
    public Container createContentPane()
    lawnSizeCombo.addItem("Please select Lawn Size...");
    lawnSizeCombo.addItem("Lawn less than 1000 sq/ft.");
    lawnSizeCombo.addItem("Lawn more than 1000 sq/ft.");
    lawnSizeCombo.addActionListener(this);
    JPanel mainPanel = new JPanel();
    mainPanel.add(titleLabel);
    mainPanel.add(blankLabel);
    mainPanel.add(firstNameLabel);
    mainPanel.add(firstNameTextField);
    mainPanel.add(lastNameLabel);
    mainPanel.add(lastNameTextField);
    mainPanel.add(lawnSizeCombo);
    mainPanel.add(blankLabel);
    mainPanel.add(submitInfoButton);
    mainPanel.add(clearInfoButton);
    lawnSizeCombo.setToolTipText("Select the appropriate lawn size from this list.");
    mainPanel.setLayout(new FlowLayout());
    //mainPanel.setLayout(new GridLayout(6, 2, 10, 10));
    return mainPanel;
    public static void main(String args[])
    MowersInc test = new MowersInc();
    test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    test.setContentPane(test.createContentPane());
    test.setSize(200, 215);
    test.setVisible(true);
    //lawnSize.addItem("Less than 1000 sqr/ft.");
    //lawnSize.addItem("More than 1000 sqr/ft.");
    }

    Use a program development method called Stepwise
    Refinement. Start out with a small working program.
    Then expand it little by little and in each step make
    sure that it works and you understand why. Very soon
    you have a big working program. Try it, it always
    works -:)Pay heed to UlrikaJ -:) sweety's advice, you'll be happy! ;-)
    UlrikaJ cutie would you like to go out with me someday? : )

  • Need help with writing to a file

    I am writing a program that is a file sharing program where i read in bytes from a socket in a BufferedReader into a char[]. Then i want to write to a file using FileOutputStream which only lets me write with a byte[]. Is there a way to read in the info into a byte[] rather a char[]?

    may be this code helps
    import java.io.*;
    public class cp
            public static void main(String args[])
                    try
                    File my=new File("source.txt");
                    FileReader fr=new FileReader(my);
                    BufferedReader br=new BufferedReader(fr);
                    String a;
                    FileWriter fw=new FileWriter(args[5]);
                    while((a=br.readLine())!=null)
                            System.out.println(a);
    fw.write(a);
    fw.close();
                    }catch(Exception e){}

Maybe you are looking for

  • How many web.xml in a java application

    Hi, can anyone give tell the answer for this question "How many web.xml in a java application?"

  • Absolute URL IMAGE UI control in Web Dynpro ABAP fails

    I would like to display a .jpg from the Internet, either using a URL or an RFC Destination as the source. The "Web Dynpro ABAP Development in Detail" manual says that this can be done using only the Source attribute of the IMAGE UI control (see page

  • ESS/MSS configuration documents

    Hi Xperts,   do any one can forward me ESS/MSS configuration document if you have? Pls forward to me to [email protected]

  • JATO UML?

    Is there any UML documentation of JATO? I would love to see generic sequence diagrams and conceptual class diagrams is they exist. Steve

  • ACFS and ASM

    I want to ensure by db_recovery destination_size value whenever i create ACFS filesystem. Example: I created ACFS file system of 10 GB from the Flash diskgroup (PTMCM_FRA) of size 17GB. I would like to know what would be size of db_recovery_destinati