Help me through this program

public class Reverse{
    int count;
    public void forward( char inp[] ){
       for (count=0 ;inp[count] != '\0'; count++){                                  //error
       System.out.print(inp[count]);
       System.out.print(" | ");
    public void backward(char inp[]){
         while(count != 0){
             System.out.print(inp [count]);
             count--;
public class MainMethod{
    public static void main(String args[]){
        char[] input = {'s','a','u','r','a','b','h'};
        Reverse call = new Reverse();
        call.forward(input);
        call.backward(input);
}i am getting an error. i am not getting through the solution
ERROR:
run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at Reverse.forward(Reverse.java:6)
at MainMethod.main(MainMethod.java:5)
there is some problem in the 'for' loop.
help me

Java is quite a bit different from C. Nul chars are not needed or typically used.
They do not appear in Strings as terminators.
void forward(char[] s) {
    for(int i=0; i < s.length; ++i)
        System.out.println(s);
//or
void forward(char[] s) {
for(char ch : s)
System.out.println(ch);

Similar Messages

  • I'm trying to clean up my mailbox and when I delete an item(s) I get a message that say's "operation could not be completed- file exists. Further, when I do this one message is copied (not deleted) to the trash folder. Can someone help me through this?

    I'm trying to clean my mailbox and when I click on delete or highlight and move to trash I get a message that says "operation could not be completed - file exists. Further, when I select a message or group of messages, one of them is copied (not deleted) to the trash folder. Can someone help me through this?
    Thanks.

    It's a POP account. I decided to clean up my mailbox today after noticing the computer was real slow after USA Today started sending their daily top stories with new graphics. Also before I noticed the problem with mail deletion - two things happened. 1) I updated security sofware as prompted by Apple and 2) downloaded Mackeeper and went throught some preliminary scans but did not buy their package. Thanks forn nstaying with me.

  • PLEASE   CAN SOMEOME HELP ME INSTALL THIS PROGRAM????

    PLease  can someone help me install this program??  I am not computer literate.

    What program specifically are you struggling with? What operating system are you using? What happens when you try?

  • I need help instantly on this program please

    import java.util.*;
    public class D3
              private static int[] z = new int[100000];
    private static int first=z[0];
              private static int last=z[n-1];
              private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
              z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
              int binSearch(z;first;last;50000);
              int seqSearch(z;35467;n); //method call 4 key where key in the left half
              int binSearch(z;first;last;35467);
              int seqSearch(z;89703;n); //method call 4 key where key in the right half
              int binSearch(z;first;last;89703);
              public int seqSearch(int z[];int key;int n)
         long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z[i]=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
         public int binSearch(int z[];int first;int last;int key)
         long start = System.currentTimeMillis();
         int count=0;
         if(last<first){
         count++;
         index=-1;
         else
         count++;
         int mid=(first+last)/2
         if(ket=z[mid]{
         index=mid;
         else
         if(key<z[mid]){
         index = binSearch(z[];first;mid-1;key);
         else
         index=binSearch(z[];mid+1;last;key);
         return index;
         long elapsed = System.currentTimeMillis() - start;
         System.out.print("Execution Time:" + elapsed);
         System.out.print("# of Basic Operations:" + count);
    // if anyone could tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...plz i need help now,,,

    "Guide to a first-time poster"
    you need to add exclamation marks to signify how urgent it is
    e.g.
    i need help instantly on this program please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    capital letters is better
    I NEED HELP INSTANTLY ON THIS PROGRAM PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    starting the italics on line 1, better again
    import java.util.*;
    public class D3
    private static int[] z = new int[100000];
    private static int first=z[0];
    private static int last=z[n-1];
    private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
    z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
    int binSearch(z;first;last;50000);
    int seqSearch(z;35467;n); //method call 4 key where key in the left half
    int binSearch(z;first;last;35467);
    int seqSearch(z;89703;n); //method call 4 key where key in the right half
    int binSearch(z;first;last;89703);
    public int seqSearch(int z[];int key;int n)
    long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    public int binSearch(int z[];int first;int last;int key)
    long start = System.currentTimeMillis();
    int count=0;
    if(last><first){
    count++;
    index=-1;
    else
    count++;
    int mid=(first+last)/2
    if(ket=z[mid]{
    index=mid;
    else
    if(key><z[mid]){
    index = binSearch(z[];first;mid-1;key);
    else
    index=binSearch(z[];mid+1;last;key);
    return index;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    and what about the dukes, offer 10 (never to be awarded, of course)
    do this, then sit back and watch the replies roll in.

  • I can't seem to be able to re-install Elements 7. Can Anyone help me through this?

    Using Windows 7.  My software was corrupt (so I thought) so I uninstalled it ... and tried to re-install (several times).  It appears to install - although very quickly .... but it is not fully installed. Can anyone help me with this?

    I never got an error message.  I am using windows 7 .... un-installed by going to the control panel and using the un-install feature.  Whewn that didn't work ... I went to Computer/ OS(C)/Program Files(x86)/Adobe   ..... and deleted all remnants of Photoshop 7.
    I inserted the program software disc ... entered my serial number .... re-installed .... and it went through some sort of process .... put up a wierd icon on my desktop .... and when I click it ... it says ...
    Windows is searching for Photoshop Elements 7.0.exe.  To locate the file yourself , click Browse."
    I could not find a Photoshop EXE on my computer. 
    I ALSO tried to un-install (whatever was there .... and there were some files ... but no exe) .... using the installation disc to un-install.  Tried re0installing once again .... but no luck .... kept getting the same message.
    I  use Photoshop Elements DAILY .... and I thought it was corrupt because after taking a LONG time to load in my photo ...  it just wasn't working the way it should ...  this went on for a few days ... I re-booted my computer .... even turned it off completely for an hour or two ... hoping things would correct itself when I re-booted .... but it didn't.

  • Can someone help me with this program?

    Can someone make this program for me?
    Make a Java-webapplication containing a few webpages (html-files and servlets, but NO jsp's). With this application you can get bankdata from a database, for example:
    page 1: html-file: Welcome on the website, type your bankaccount and password
    page 2: error if bankaccount doesn't exist or wrong password
    page 3: welcome with name and option to choose for your balance or a list with transactions from that account (the user can give a starting date)
    page 4: showing the balance or the list with transactions, name and accountnumber
    Store the information about the account and name in sessionsvariables
    the database is an access-file with two tables
    table Accounts with colums: accountnumber, name, balance and password
    table Transactions with colums: accountnumber, amount, plus/minus, date, sorttransaction and contra-account
    (when I need to send you the database by mail, you can ask me ...)
    maybe someone can help me,
    thanks in advance
    greetings Bastiaan

    Sure we can help you. Post the code you have already and explain any problems you are currently having together with any and all complete compiler error messages and/or exceptions.
    But no, we are not going to do your homework for you.

  • I Need Help With Making This Program Work

    The directions for this program:
    Enhance the Student class to contain an Advisor. The advisor has a name (type Name), phone number (type String). Place edits in the Name class to validate that the length of the first name is between 1 and 15, middle inital <= 1, and lastName is between 1 and 15. Throw an IllegalArgumentException if the edits are not met. The advisor attribute in the Student class should replace the advisorName. Document the Name, Advisor, and Student classes including the preconditions and postconditions where necessary. Create a test class that will instantiate a Student, fully populate all of its fields and print it out. Do not document the test class. Submit for grade Student.java, Advisor.java, and Name.java.
    public class Student
         private Advisor advisorName;
         private Advisor phoneNumber;
         public void setAdvisorName(Advisor anAdvisorName)
             advisorName = anAdvisorName;
         public Advisor getAdvisorName()
             return advisorName;
         public void setPhoneNumber(Advisor aPhoneNumber)
             phoneNumber = aPhoneNumber;
         public Advisor getPhoneNumber()
             return phoneNumber;
    public class Name
         private String firstName;
         private String midInit;
         private String lastName;
         public String getFullName()
             return firstName + " " + midInit + " " + lastName;
         public String getFirstName()
             return firstName;
         public String getMidInit()
             return midInit;
         public String getLastName()
             return lastName;
            Calculates length of the first name.
            (Postcondition: getFirstName() >= 0)
            @param s the length of the first name to calculate
            (Precondition: length of aFirstName > 0 and <= 15)
         public void setFirstName(String aFirstName)
             if(aFirstName.length() < 1)
               throw new IllegalArgumentException();
             if(aFirstName.length() > 15)
               throw new IllegalArgumentException();
               firstName = aFirstName;
            Calculates length of the middle initial.
            (Postcondition: getMidInit() >= 0)
            @param s the length of the middle initial to calculate
            (Precondition: length of s > 0 and <= 1)
         public void setMidInit(String aMidInit)
             if(aMidInit.length() == 1)
               throw new IllegalArgumentException();
               midInit = aMidInit;
            Calculates length of the last name.
            (Postcondition: getLastName() >= 0)
            @param s the length of the last name to calculate
            (Precondition: length of aLastName > 0 and <= 15)
         public void setLastName(String aLastName)
             if(aLastName.length() < 1)
               throw new IllegalArgumentException();
             if(aLastName.length() > 15)
               throw new IllegalArgumentException();    
               lastName = aLastName;
    public class Advisor
         private Name advisorName;
         private String phoneNumber;
         public String getFullName()
            return advisorName + " " + phoneNumber + " ";
         public Name getAdvisorName()
             return advisorName;
         public String getPhoneNumber()
             return phoneNumber;
         public void setAdvisorName(Name anAdvisorName)
             advisorName = anAdvisorName;
         public void setPhoneNumber(String aPhoneNumber)
             phoneNumber = aPhoneNumber;
    public class Test
         public static void main(String[] args)
            Name name1 = new Name();
            name1.setFirstName("Timothy");
            name1.setLastName("O'Neal");
            name1.setMidInit("J.");
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            Student st = new Student();
            st.setAdvisorName(name1);
            Name name2 = st.getAdvisorName();
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());   
            name2.setFirstName("Timothy");
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());       
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            System.out.println("name1 = " + name1.getFullName());   
            System.out.println("name2 = " + name2.getFullName());
    }I can't get the test class to compile and i'm not sure if this is what i'm suppose to do

    public class Test
    public static void main(String[] args)
    Student st = new Student();
    Advisor advisor = new Advisor();
    st.setAdvisor(advisor);
    Name name1 = new Name();
    name1.setFirstName("Jake");
    name1.setLastName("Schmidt");
    name1.setMidInit("K.");You have the general idea, I think. You are just doing it backwards.
    You create and advisor and assign it to a student. But you don't give
    the advisor a name until after you assign it to the student.
    You should create an advisor, give the advisor a name and then add it to the student.
    //create the name
    Name name1 = new Name();
    name1.setFirstName("John");
    name1.setLastName("Smith");
    name1.setMidInit("K.");
    //create the advisor
    Advisor advisor = new Advisor();
    advisor.setAdvisorName(name1);
    //create the student
    Student student = new Student();
    //assign the advisor to the student
    student.setAdvisor(advisor);
    //now the student has an advisor named John K. Smith
    //What is the name of the advisor?
    String name = st.advisor.getAdvisorName().getFullName();
    //I know that line looks complicated...but that's how you have created your class structure.
    Instead you could have done:
    Class Student{
    private Advisor advisor;
    public String getAdvisorName(){
    return advisor.getFullName();
    class Advisor{
    private Name advisorName;
    public getFullName(){
    return advisorName.getFullName();
    This way, if you wanted to know the advisor's name you would go:
    String name = st.getAdvisorName();
    which is much easier.
    I think it would be much easier to help you if we were both in the same room, on the same computer :)

  • I need Some help to complete this program

    i write this program to call file from my hard drive "the file name is
    input.tex" "the program the file and the result for the program are below"
    please read the program and the file befor you read my question
    now, i need to use 3 arrays
    1) first array to read this part
    include[0]: VAR ZRO 1
    include[1]: +0000000000
    include[2]: VAR I 1
    include[3]: +0000000000
    include[4]: VAR SUM 1
    include[5]: +0000000000
    include[6]: VAR AVG 1
    include[7]: +0000000000
    include[8]: VAR N 1
    include[9]: +0000000000
    include[10]: VAR TMP 1
    include[11]: +0000000000
    include[12]: VAR DTA 990
    include[13]: +0000000000
    in this way
    VAR ZRO 1
    VAR I 1
    VAR SUM 1
    VAR AVG 1
    VAR N 1
    VAR TMP 1
    VAR DTA 990
    2) second array is dimensional array to read this part
    include[15]: READ N
    include[16]: LABL 20
    include[17]: READ TMP
    include[18]: GE TMP ZRO 40
    include[19]: SUB ZRO TMP TMP
    include[20]: LABL 40
    include[21]: PUTA TMP DTA I
    include[22]: LOOP I N 20
    include[23]: MOVE ZRO I
    include[24]: LABL 50
    include[25]: GETA DTA I TMP
    include[26]: ADD TMP SUM SUM
    include[27]: LOOP I N 50
    include[28]: DIV SUM N AVG
    include[29]: PRNT AVG
    include[30]: STOP
    in this way
    READ N
    LABL 20
    READ TMP
    GE TMP ZRO 40
    SUB ZRO TMP TMP
    LABL 40
    PUTA TMP DTA I
    LOOP I N 20
    MOVE ZRO I
    LABL 50
    GETA DTA I TMP
    ADD TMP SUM SUM
    LOOP I N 50
    DIV SUM N AVG
    PRNT AVG
    STOP
    3) the third to read this part
    include[32]: +0000000005
    include[33]: +0000000020
    include[34]: -0000000430
    include[35]: +0000000553
    include[36]: +0000001323
    include[37]: -0000000896
    in this way
    +0000000005
    +0000000020
    -0000000430
    +0000000553
    +0000001323
    -0000000896
    i hope i see some help
    [http://arbshare.net/files-182969.html]

    According to the file name ending with extension .tex, I guess that it's TeX, a markup language, not a programming language.
    Topicstarter: look for a more suitable forum. Good luck.

  • PLEASE HELP ME. THIS PROGRAM IS KILLING ME.

    Hi. I am getting so sick of this program. I have been trying to do it for the past couple of weeks and I am getting nowhere. I really wish someone can help me on it ... like totaly help me on it. I am getting so frustrated. I would appreciate all the help.
    This is the program:
    In Belageusia, a plorg has these properties:
    Data:
         A plorg has a name
         A plorg has a contentment index (CI), which is an integer between 0 and 100
    The population of plorgs in Belagersia is further subdivided into three mutually exclusive classes: Plebeians, Equidians, and Elitians.
    A Plorg?s stature is completely determined by their contentment index and witht that designation comes certain burdens and/or advantages.
    Plebeians have a contentment index in [0, 24].
    Each new Plebeian is welcomed with a contentment index of 2 and burdened with a debt of $10.00
    Plebeians never manage to break even, so they have no taxes imposed upon them. Furthermore, since they can never get out debt, they cannot accumulate any wealth.
    Equidians have a contentment index in [25, 75]
    Each new Equidian is welcomed with a contentment index of 50 and burdened with taxes of $20.00
    Equidians have taxes imposed upon them. Furthermore, since they do manage to break even, they have no debt. However, since they only manager to break even, they do not accumulate any wealth.
    Elitians have a contentment index in [76, 100]
    Each new Elitian is welcomed with a contentment index of 87 and burdened with taxes of $20.00, but also provided with a ?silver spoon? of $30.00 in accumulated wealth.
    Elitians manage to expand upon their wealth, sot hey have taxes imposed upon them. Furthermore, since they are accumulating wealth, they have no debt.
    At each interim time epoch the population of Belageusia retracts with a death rate randomly selected between 0% and 10%. If a plorg survives the purge, they have an opportunity to move one class higher and/or one class lower. However, remember that a plorg?s name is final. It never changes.
    For Plebeians this is transition is determined by randomly selecting a CI in [0, 49]. If this new CI is les than 25 then the plorg remains a Plebeian, with this newly assigned CI, and their debt increases 3.7%. If this new CI is in [25, 49], the Plebeian ascends to a Equidian, with this newly assigned CI, their debt is forgiven, but taxes of $20 are assessed.
    For Equidians this is determined by randomly selecting a CI in [0,100].
    If this new CI is in [25, 75] then the plorg remains a Equidian, with this newly assigned CI, but their taxes are increased 6.1%.
    If this new CI is in [0, 24] then the plorg becomes a Plebeian, with this newly assigned CI, their taxes are forgiven, but they are burdened with a debt of $10.00.
    If this new CI is in [76, 100] then the plorg becomes a Plebeian, with this newly assigned CI, but their taxes are increased 6.1%. However, they are bewtowed a wealth of $30.00.
    For Eletians this is determined by randomly selecting a CI in [51, 100]. If this new CI is greater than 76 then the plorg remains an Eletian, with this newly assigned CI, their taxes increase 6.1% and their wealth increases 4.9%. If this new CI is in [51, 75], then this plorg becomes an Equidian, with this newly assigned CI, their wealth is eliminated, and their taxes are increased 6.1%.
    At each time epoch, the population of Belageusia at a birth rate randomly selected between 0% and 10%. A randomly chosen number between 0-100 determines each newly born plorg?s stature. If this random number is in the range 0-24, create a new Plebeian. In the range 25-75, create a new Equidian, and if in the range 76-100, create a new Elitian.
    We are supposed to output the population characteristics of Belageusia, after 1000 time epochs.
    This is the code that I wrote down but got no where with:
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    public class Belageusiaplorg
         public static void main (String[] args)
              ArrayList Plebs = new ArrayList(350);
              ArrayList Equids = new ArrayList(600);
              ArrayList Elits = new ArrayList(350);
              ArrayList Holding = new ArrayList(600);
              for (int i=0; i<25; i++)
                   Plebs.add(new plebian());
              for (int i=0; i<50; i++)
                   Equids.add(new equidian());
              for (int i=0; i<25; i++)
                   Elits.add(new Elitian());
              long population = Plebs.size() + Equids..size() + Elits.size();
              System.out.println("Current Belageusia Population is "+population);
              System.out.println("Current Plebeians Population is "+Plebs.size);
              System.out.println("Current Equidians Population is "+Equids.size);
              System.out.println("Current Elitians Population is "+Elits.size);
              Random generator = new Random();
              int x = generator.nextInt(11);
              for (int j=0; j=plebs.size(); j++)
                   System.out.println(Plebs.g(j));
              long Equids_size = Equids.size();
              long Elits_size = Elits.size();
              for(int j=1; j<Plebs.size(); j++)
                   Plebian e = (Plebian) Plebs.get(j);
                   int new_ci = generator.nextInt(50);
                   if (new_ci < 25)
                        e.setCI(new_ci);
                        e.raiseDebt();
                   else
                        Plebs.rename(j);
                        Equids.add(new Equidian(e.getName().newCI));
                        j++;
              for(int j=0; j < Equids.size; j++)
                   Equidian e = (Equidian) Equids.get(j);
                   int newCI = generator.nextInt(101);
                   if(new_ci < 25)
                        Equids.remove(j);
                        Plebs.add(nwe Plebian(e.getName().new_ci));
                        Equids_size --;
                        j++;
                   else
                   if (new_ci > 75)
                        Equids.remove(j);
                        Elitian f = new Elitian(e.getName(),new_ci,e.getTaxes());
                        Elits.add(f);
                        Equids_size --;
                        j--;
                   else
                        e.setCI(new_CI);
                        e.raiseTaxes();
              for (int j=0; j<Elits.size; j++)
                   Elitian e = (Elitian) Elits.get(j);
                   int ci = e.getCI();
                   int r = generator.nextINT(50);
                   int new_ci = 51+r;
                   if(new_ci > 75)
                        e.setCI(new_ci);
                        e.raisetaxes();
                        e.raisewealth();
                   else
                        Elitians.remove(j);
                        Equidian g = new Equidian(e.getName(), new_ci);
                        g.raisetaxes();
                        Equids.add(g);
                        Elits_size --;
                        j--;
              if(deathrate != 0)
                   int multiple = 100/deathrate;
                   int count 1;
                   for (int j=0; j=Plebs.size(); j++)
                        if(count % multiple == 0)
                             Plebs.remove(j);
                             j--;
                        count++;
    class Plorg
         private final String name;
         private int CI;
         private static long nextID = 1;
         public Plorg()
              name = "Plorg" + nextID;
              nextID++;
         public Plorg(int CI)
              name = "Plorg" + nextID;
              nextID++;
              this.CI = CI;
         public Plorg (String name, int CI)
              this.name = name;
              this.CI = CI;
         public void setCI(int new_CI)
              CI = new_CI;
         public String getName()
              return name;
         public int getCI()
              return CI;
         public Plorg Plebs()
         public Plorg Equids()
         public Plorg Elits()

    Sounds a lot like a homework question to me. Still it was interesting enough to try out. I have not tried to change your code, just made one of my own. Here is my solution. I have made the Plorg class an inner class of the Belageusia. This is just so I dont have to put up two java files. You could easily split it into two though.
    import java.util.Random;
    import java.util.ArrayList;
    import java.util.Iterator;
    * @author Jonathan Knight
    public class Belageusia
        /** Random number generator - Seeded with the current time. */
        private static Random random = new Random(System.currentTimeMillis());
        /** A list of all of the Plorgs */
        private ArrayList population = new ArrayList();
        /** A list of all of the Plebians. */
        private ArrayList plebians = new ArrayList();
        /** A list of all of the Equidians. */
        private ArrayList equidians = new ArrayList();
        /** A list of all of the Elitians. */
        private ArrayList elitians = new ArrayList();
        /** A count of the Epochs that have passed */
        private int epochs = 0;
         * Main method.
         * Create a new world of Belageusia and run it for 1000 epochs.
        public static void main(String[] args)
            Belageusia world;
            world = new Belageusia();
            for (int i = 0; i < 1000; i++)
                world.epoch();
            System.out.println("The Belageusia population after 1000 epochs");
            world.printPopulation();
         * Create a new World of Belageusia and create some Plorgs to live there.
         * The world will be created with 25 Plebians, 50 Equidians and 25 Elitians.
        public Belageusia()
            for (int i = 0; i < 25; i++)
                plebians.add(Plorg.createPlebian());
            for (int i = 0; i < 50; i++)
                equidians.add(Plorg.createEquidian());
            for (int i = 0; i < 25; i++)
                elitians.add(Plorg.createElitian());
         * Print the current population to System.out
        public void printPopulation()
            int total;
            int plebianCount;
            int equidianCount;
            int elitianCount;
            plebianCount = plebians.size();
            equidianCount = equidians.size();
            elitianCount = elitians.size();
            total = plebianCount + equidianCount + elitianCount;
            System.out.println("Current Belageusia population is " + total);
            System.out.println("Current Plebian population is " + plebianCount);
            System.out.println("Current Equidian population is " + equidianCount);
            System.out.println("Current Elitian population is " + elitianCount);
         * At each interim time epoch the population of Belageusia retracts with a death rate
         * randomly selected between 0% and 10%. If a plorg survives the purge, they have an
         * opportunity to move one class higher and/or one class lower. However, remember that
         * a plorgs name is final. It never changes.
         * For Plebeians this transition is determined by randomly selecting a CI in [0, 49].
         * If this new CI is les than 25 then the plorg remains a Plebeian, with this newly assigned CI,
         * and their debt increases 3.7%. If this new CI is in [25, 49], the Plebeian ascends to a
         * Equidian, with this newly assigned CI, their debt is forgiven, but taxes of $20 are assessed.
         * For Equidians this is determined by randomly selecting a CI in [0,100].
         * If this new CI is in [25, 75] then the plorg remains a Equidian, with this newly assigned CI,
         * but their taxes are increased 6.1%.
         * If this new CI is in [0, 24] then the plorg becomes a Plebeian, with this newly assigned CI,
         * their taxes are forgiven, but they are burdened with a debt of $10.00.
         * If this new CI is in [76, 100] then the plorg becomes a Plebeian, with this newly assigned CI,
         * but their taxes are increased 6.1%. However, they are bewtowed a wealth of $30.00.
         * For Eletians this is determined by randomly selecting a CI in [51, 100].
         * If this new CI is greater than 76 then the plorg remains an Eletian, with this newly assigned CI,
         * their taxes increase 6.1% and their wealth increases 4.9%. If this new CI is in [51, 75],
         * then this plorg becomes an Equidian, with this newly assigned CI, their wealth is eliminated,
         * and their taxes are increased 6.1%.
         * At each time epoch, the population of Belageusia at a birth rate randomly selected between 0% and 10%.
         * A randomly chosen number between 0-100 determines each newly born plorg?s stature.
         * If this random number is in the range 0-24, create a new Plebeian. In the range 25-75, create a new Equidian,
         * and if in the range 76-100, create a new Elitian.
        public void epoch()
            ArrayList newPlebians = new ArrayList();
            ArrayList newEquidians = new ArrayList();
            ArrayList newEletians = new ArrayList();
            Iterator it;
            Plorg plorg;
            int deathRate;
            double deathCount;
            int birthRate;
            double birthCount;
            int population;
            int subClass;
            int newCI;
            int kill;
            epochs++;
            System.out.println("Epoch = " + epochs);
            printPopulation();
            population = plebians.size() + equidians.size() + elitians.size();
            // The death rate is random 0 to 10%
            deathRate = random.nextInt(11);
            // work out the death count. population is cast to a double to avoid rounding errors
            deathCount = (double)population * deathRate / 100;
            // round up the result. We do this as once the population falls below 10
            // we would never kill anything
            deathCount = Math.ceil(deathCount);
            // We now work out the birth rate based on the population before we kill
            // anything otherwise the population tends to go down and down
            // The birth rate is random 0 to 10%
            birthRate = random.nextInt(11);
            // work out the birth count. population is cast to a double to avoid rounding errors
            birthCount = Math.ceil((double)population * birthRate / 100);
            // As with the deathCount round up the result.
            // We do this as once the population falls too low we would never create any more
            birthCount = Math.ceil(birthCount);
            System.out.println("About to kill " + deathRate + "% which is " + deathCount + " Plorgs out of " + population);
            for(int i=0; i<deathCount; i++)
                // get a random number between 0 and 2
                kill = random.nextInt(population);
                population--;
                // kill the specified Plorg
                if( kill < plebians.size() )
                    // kill a random Plebian
                    plebians.remove( random.nextInt(plebians.size()) );
                else if( kill < plebians.size() + equidians.size() )
                    // kill a random Equidian
                    equidians.remove( random.nextInt(equidians.size()) );
                else
                    // kill a random Elitian
                    elitians.remove( random.nextInt(elitians.size()) );
            System.out.println("Transitioning Plebians");
            // Transition period for Plebians
            it = plebians.iterator();
            while ( it.hasNext() )
                plorg = (Plorg) it.next();
                // select a new CI from 0 to 49 at random
                newCI = random.nextInt(50);
                plorg.setCI(newCI);
                if( newCI < 25 )
                    // Oh dear, this one stays as a Plebian; increase its dept by 3.7%
                    plorg.setDept( plorg.getDept() * 1.037 );
                else
                    // Congratulations this one is now an Equidian
                    newEquidians.add(plorg);
                    // remove from the Plebian list.
                    // NOTE we must do the remove via the Iterator
                    it.remove();
                    plorg.setDept(0);
                    plorg.setTaxes(20);
            System.out.println("Transitioning Equidians");
            // Transition period for Equidians
            it = equidians.iterator();
            while ( it.hasNext() )
                plorg = (Plorg) it.next();
                // select a new CI from 0 to 100 at random
                newCI = random.nextInt(101);
                plorg.setCI(newCI);
                if( newCI < 25 )
                    // Oh dear, this one becomes a Plebian
                    newPlebians.add(plorg);
                    // remove from the Equidian list.
                    // NOTE we must do the remove via the Iterator
                    it.remove();
                    plorg.setDept( 10 );
                    plorg.setTaxes(0);
                else if( newCI < 25 )
                    // This one stays as an Equidian; increase its taxes by 6.1%
                    plorg.setTaxes( plorg.getTaxes() * 1.061 );
                else
                    // Congratulations this one is now an Eletian
                    newEletians.add(plorg);
                    // remove from the Equidian list.
                    // NOTE we must do the remove via the Iterator
                    it.remove();
                    plorg.setWealth(30);
                    // Increase its taxes by 6.1%
                    plorg.setTaxes( plorg.getTaxes() * 1.061 );
            System.out.println("Transitioning Elitians");
            // Transition period for Eletians
            it = plebians.iterator();
            while ( it.hasNext() )
                plorg = (Plorg) it.next();
                // Always increase taxes by 6.1%
                plorg.setTaxes( plorg.getTaxes() * 1.061 );
                // select a new CI from 51 to 100 at random
                newCI = 51 + random.nextInt(50);
                plorg.setCI(newCI);
                if( newCI > 76 )
                    // This one stays as an Eletian; increase its wealth by 4.9%
                    plorg.setWealth( plorg.getWealth() * 1.049 );
                else
                    // Oh dear, this one becomes an Equidian
                    newEquidians.add(plorg);
                    // remove from the Plebian list.
                    // NOTE we must do the remove via the Iterator
                    it.remove();
                    // emove its wealth
                    plorg.setWealth(0);
            // now assign the Plorgs that are transitioning
            plebians.addAll(newPlebians);
            equidians.addAll(newEquidians);
            elitians.addAll(newEletians);
            System.out.println("Creating " + birthRate + "% new Plorgs from " + population + " which is " + birthCount);
            //create the new Plorgs
            for (int i = 0; i < birthCount; i++)
                // get a random number between 0 and 100
                subClass = random.nextInt(101);
                // create the specified Plorg
                if( subClass <= 24 )
                    plorg = Plorg.createPlebian();
                    plebians.add(plorg);
                else if( subClass >= 25 && subClass <= 75 )
                    plorg = Plorg.createEquidian();
                    equidians.add(plorg);
                else
                    plorg = Plorg.createElitian();
                    elitians.add(plorg);
        public static class Plorg
            /** Identifier used to generate unique names */
            private static int id = 0;
            /** The Plorgs name */
            private final String name;
            /** The level of wealth for this Plorg */
            private double wealth = 0;
            /** The level of dept for this Plorg */
            private double dept = 0;
            /** The level of taxes for this Plorg */
            private double taxes = 0;
            /** This Plorgs contentment index */
            private int ci = 0;
            /** Create a new Plorg with the given CI.
             * This is a private constructor. The only way for a program to
             * create new Plorgs is by calling either createPlebian(),
             * createEquidian() or createElitian().
             * @param ci
            private Plorg(int ci)
                // Generate a unique name and iincrement the ID
                this.name = "Plorg" + id++;
                // assign the CI
                this.ci = ci;
             * Create a new Plebian.
             * Plebeians have a contentment index in [0, 24].
             * Each new Plebeian is welcomed with a contentment index of 2 and burdened
             * with a debt of $10.00. Plebeians never manage to break even, so they have
             * no taxes imposed upon them. Furthermore, since they can never get out debt,
             * they cannot accumulate any wealth.
             * @return a new Plebian.
            public static Plorg createPlebian()
                Plorg plebian;
                plebian = new Plorg(2);
                plebian.setDept(10);
                return plebian;
             * Create a new Equidian
             * Equidians have a contentment index in [25, 75].
             * Each new Equidian is welcomed with a contentment index of 50 and burdened
             * with taxes of $20.00. Equidians have taxes imposed upon them. Furthermore,
             * since they do manage to break even, they have no debt. However, since they
             * only manager to break even, they do not accumulate any wealth.
             * @return a new Equidian.
            public static Plorg createEquidian()
                Plorg equidian;
                equidian = new Plorg(50);
                equidian.setTaxes(20);
                return equidian;
             * Create a new Elitian.
             * Elitians have a contentment index in [76, 100].
             * Each new Elitian is welcomed with a contentment index of 87 and burdened
             * with taxes of $20.00, but also provided with a ?silver spoon? of $30.00 in
             * accumulated wealth. Elitians manage to expand upon their wealth, so they
             * have taxes imposed upon them. Furthermore, since they are accumulating
             * wealth, they have no debt.
             * @return a new Elitian.
            public static Plorg createElitian()
                Plorg equidian;
                equidian = new Plorg(87);
                equidian.setWealth(30);
                equidian.setTaxes(20);
                return equidian;
             * Returns this Plorgs name.
            public String getName()
                return name;
             * Returns the CI of this Plorg.
            public int getCI()
                return ci;
             * Set the new Contentment index for this Plorg
             * @param ci
            public void setCI(int ci)
                this.ci = ci;
             * Returns the Dept of this Plorg
             * @return
            public double getDept()
                return dept;
             * Set the dept of this Plorg.
             * @param dept - the new dept for the Plorg.
            public void setDept(double dept)
                this.dept = dept;
             * Returns the wealth of this Plorg.
            public double getWealth()
                return wealth;
             * Sets the wealth of this Plorg.
             * @param wealth - the new wealth of this Plorg.
            public void setWealth(double wealth)
                this.wealth = wealth;
             * Returns the taxes of this Plorg.
            public double getTaxes()
                return taxes;
             * Set the taxes of this Plorg.
             * @param taxes - the new taxes for this Plorg.
            public void setTaxes(double taxes)
                this.taxes = taxes;
             * Check for equality. If the object specified is a Plorg with the same name as this
             * Plorg they are deemed to be equal.
             * @param o - The object to check
            public boolean equals(Object o)
                if ( this == o ) return true;
                if ( !(o instanceof Plorg) ) return false;
                final Plorg plorg = (Plorg) o;
                if ( name != null ? !name.equals(plorg.name) : plorg.name != null ) return false;
                return true;
             * Create a Hash Code for this Plorg
            public int hashCode()
                return (name != null ? name.hashCode() : 0);
    }

  • Pls help me with this program - urgent

    Hi,
    I am new to Java. First time to do the program. Stuck here.
    The description of the program:
    Implement a complex number (numbers of the form a+ib, where i2 = -1, i2 is i raised to power 2 ). Recall that a complex number consists of a real part (a) and an imaginary part (b). Provide a reasonable set of constructors; the methods add, subtract, multiply and divide; as well as toString and equals.
    You are to implement a complex number as having two fields, one for the real part another for the imaginary part.
    If z = a + ib and x = c + id are two complex numbers, then their sum z+ x = (a+c) + i(b+d), quotient z/x = (ac+bd)/(c*c+d*d) + i(-ab+bc)/(c*c + d*d). two complex numbers are equal if their real and imaginary parts are equal.
    I really do not have any clues about imaginary parts and how to do it.
    Could you please help me with that.
    Thanks a lot.

    ur dboubt has nothing to do java.. its a mathematical concept..
    as the question says the complexnumbers can be represented in the form of a+ib where i=squre-root of -1 .. and as this is imaginary (ie u cant get a minus number by squring a number) the second part is called imaginay.
    so as a programmer u dont have to give more strain on this but to declare a class having to instance varaiables and inplememts the methods as said.
    and in the toString() method u can return the numbers in the reuired format like
    return ( a + "+i" +b);

  • Please help me debug this program unit!!!!!

    dear sir,
    i tried diligently to find and to debug this tiny program unit,although my observation to the coding rules of the packages ,compilation error still occur.
    therefore,kindly i'm asking you sir to learn me how to correct it.
    thank you.
    create or replace package test_pack is
    type emp_table_type is table of emp.sal%type
    index by binary_integer;
    emp_list emp_table_type;
    function test_sal
    (v_sal in emp.sal%type)
    return emp_table_type;
    end test_pack;
    create or replace package body test_pack is
    temp emp.sal%type;
    cursor emp_cursor is
    select sal from emp;
    i number :=1;
    j number :=1;
    function test_sal
    (v_sal in emp.sal%type)
    return emp_table_type
    is
    open emp_cursor;
    loop
    fetch emp_cursor into temp;
    if temp < v_sal then
    emp_list(i):=temp;
    bms_output.put_line('rowcount i='||emp_cursor%rowcount);
    dbms_output.put_line('iterator i='||i);
    i:=i+1;
    else
    dbms_output.put_line('rowcount j='||emp_cursor%rowcount);
    dbms_output.put_line('iterator j='||j);
    j:=j+1;
    end if;
    if emp_cursor%notfound then
    dbms_output.put_line('cursor closed...');
    close emp_cursor;
    return emp_list;
    exit;
    end if;
    end loop;
    end test_pack;

    You can use "show err" to show the errors after compilation errors occur:
    SQL> create or replace package test_pack is
      2    type emp_table_type is table of emp.sal%type index by binary_integer;
      3    emp_list emp_table_type;
      4    function test_sal(v_sal in emp.sal%type) return emp_table_type;
      5  end test_pack;
      6  /
    Package is aangemaakt.
    SQL> create or replace package body test_pack is
      2    temp emp.sal%type;
      3    cursor emp_cursor is
      4    select sal from emp;
      5    i number :=1;
      6    j number :=1;
      7
      8    function test_sal
      9    (v_sal in emp.sal%type)
    10    return emp_table_type
    11    is
    12      open emp_cursor;
    13      loop
    14        fetch emp_cursor into temp;
    15        if temp < v_sal then
    16          emp_list(i):=temp;
    17          bms_output.put_line('rowcount i='||emp_cursor%rowcount);
    18          dbms_output.put_line('iterator i='||i);
    19          i:=i+1;
    20        else
    21          dbms_output.put_line('rowcount j='||emp_cursor%rowcount);
    22          dbms_output.put_line('iterator j='||j);
    23          j:=j+1;
    24        end if;
    25        if emp_cursor%notfound then
    26          dbms_output.put_line('cursor closed...');
    27          close emp_cursor;
    28          return emp_list;
    29          exit;
    30        end if;
    31      end loop;
    32  end test_pack;
    33  /
    Waarschuwing: package-body is aangemaakt met compilatiefouten.
    SQL> show err
    Fouten voor PACKAGE BODY TEST_PACK:
    LINE/COL ERROR
    14/7     PLS-00103: Symbool "FETCH" aangetroffen terwijl een van de
             volgende werd verwacht:
             constant exception <een ID>
             <een scheidingsteken-ID tussen dubbele aanhalingstekens>
             table LONG_ double ref char time timestamp interval date
             binary national character nchar
    32/5     PLS-00103: Symbool "TEST_PACK" aangetroffen terwijl een van de
             volgende werd verwacht:
             ;To make your program compile, add a begin and end and fix the typo (in bold):
    SQL> create or replace package body test_pack is
      2    temp emp.sal%type;
      3    cursor emp_cursor is
      4    select sal from emp;
      5    i number :=1;
      6    j number :=1;
      7
      8    function test_sal
      9    (v_sal in emp.sal%type)
    10    return emp_table_type
    11    is
    12    begin
    13      open emp_cursor;
    14      loop
    15        fetch emp_cursor into temp;
    16        if temp < v_sal then
    17          emp_list(i):=temp;
    18          dbms_output.put_line('rowcount i='||emp_cursor%rowcount);
    19          dbms_output.put_line('iterator i='||i);
    20          i:=i+1;
    21        else
    22          dbms_output.put_line('rowcount j='||emp_cursor%rowcount);
    23          dbms_output.put_line('iterator j='||j);
    24          j:=j+1;
    25        end if;
    26        if emp_cursor%notfound then
    27          dbms_output.put_line('cursor closed...');
    28          close emp_cursor;
    29          return emp_list;
    30          exit;
    31        end if;
    32      end loop;
    33    end;
    34  end test_pack;
    35  /
    Package-body is aangemaakt.
    SQL> declare
      2    t test_pack.emp_table_type;
      3  begin
      4    t := test_pack.test_sal(2000);
      5    for i in 1..t.count
      6    loop
      7      dbms_output.put_line(t(i));
      8    end loop;
      9  end;
    10  /
    rowcount i=1
    iterator i=1
    rowcount i=2
    iterator i=2
    rowcount i=3
    iterator i=3
    rowcount j=4
    iterator j=1
    rowcount i=5
    iterator i=4
    rowcount j=6
    iterator j=2
    rowcount j=7
    iterator j=3
    rowcount j=8
    iterator j=4
    rowcount j=9
    iterator j=5
    rowcount i=10
    iterator i=5
    rowcount i=11
    iterator i=6
    rowcount i=12
    iterator i=7
    rowcount j=13
    iterator j=6
    rowcount i=14
    iterator i=8
    rowcount i=14
    iterator i=9
    cursor closed...
    800
    1600
    1250
    1250
    1500
    1100
    950
    1300
    1300
    PL/SQL-procedure is geslaagd.To fix the bug of the last iteration and put the variables in the sections they belong:
    SQL> create or replace package test_pack is
      2    type emp_table_type is table of emp.sal%type index by binary_integer;
      3    function test_sal(v_sal in emp.sal%type) return emp_table_type;
      4  end test_pack;
      5  /
    Package is aangemaakt.
    SQL> create or replace package body test_pack
      2  is
      3    function test_sal(v_sal in emp.sal%type) return emp_table_type
      4    is
      5      emp_list emp_table_type;
      6      temp emp.sal%type;
      7      cursor emp_cursor is select sal from emp;
      8      i number :=1;
      9      j number :=1;
    10    begin
    11      open emp_cursor;
    12      loop
    13        fetch emp_cursor into temp;
    14        if emp_cursor%notfound then
    15          dbms_output.put_line('cursor closed...');
    16          exit;
    17        end if;
    18        if temp < v_sal then
    19          emp_list(i):=temp;
    20          dbms_output.put_line('rowcount i='||emp_cursor%rowcount);
    21          dbms_output.put_line('iterator i='||i);
    22          i:=i+1;
    23        else
    24          dbms_output.put_line('rowcount j='||emp_cursor%rowcount);
    25          dbms_output.put_line('iterator j='||j);
    26          j:=j+1;
    27        end if;
    28      end loop;
    29      close emp_cursor;
    30      return emp_list;
    31    end;
    32  end test_pack;
    33  /
    Package-body is aangemaakt.
    SQL> declare
      2    t test_pack.emp_table_type;
      3  begin
      4    t := test_pack.test_sal(2000);
      5    for i in 1..t.count
      6    loop
      7      dbms_output.put_line(t(i));
      8    end loop;
      9  end;
    10  /
    rowcount i=1
    iterator i=1
    rowcount i=2
    iterator i=2
    rowcount i=3
    iterator i=3
    rowcount j=4
    iterator j=1
    rowcount i=5
    iterator i=4
    rowcount j=6
    iterator j=2
    rowcount j=7
    iterator j=3
    rowcount j=8
    iterator j=4
    rowcount j=9
    iterator j=5
    rowcount i=10
    iterator i=5
    rowcount i=11
    iterator i=6
    rowcount i=12
    iterator i=7
    rowcount j=13
    iterator j=6
    rowcount i=14
    iterator i=8
    cursor closed...
    800
    1600
    1250
    1250
    1500
    1100
    950
    1300
    PL/SQL-procedure is geslaagd.To be really efficient and not care about looping, using counters and dbms_output, and assuming the emp table won't ever be a big table (else use the LIMIT clause):
    SQL> create or replace package body test_pack
      2  is
      3    function test_sal(v_sal in emp.sal%type) return emp_table_type
      4    is
      5      emp_list emp_table_type;
      6    begin
      7      select sal bulk collect into emp_list
      8        from emp
      9       where sal < v_sal
    10      ;
    11      return emp_list;
    12    end;
    13  end;
    14  /
    Package-body is aangemaakt.
    SQL> declare
      2    t test_pack.emp_table_type;
      3  begin
      4    t := test_pack.test_sal(2000);
      5    for i in 1..t.count
      6    loop
      7      dbms_output.put_line(t(i));
      8    end loop;
      9  end;
    10  /
    800
    1600
    1250
    1250
    1500
    1100
    950
    1300
    PL/SQL-procedure is geslaagd.Hope it helps.
    Regards,
    Rob.

  • Can anyone help me with this program using the Scanner Class?

    I have to write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. Such as 1 hour will equal 40 miles traveled, 2 hours will equal 80, 3 hours will equal 120, etc. This is what I've come up with thus far. Any help is appreciated.
    import java.util.Scanner;
         public class DistanceTraveled
              public static void main(String[] args)
                   int speed;
                   int hours;
                   int distance;
                   Scanner keyboard = new Scanner(System.in);
                   System.out.print("What is the speed of the vehicle in miles-per-hour?");
                   speed = keyboard.nextInt();
                   System.out.print("How many hours has the vehicle traveled for?");
                   hours = keyboard.nextInt();
                   distance = speed*hours;
                   while (speed < 0)
                   while (hours < 1)
                   System.out.println("Hour     Distance Traveled");
                   System.out.println("------------------------");
                   System.out.println(hours + " " + distance);
    }

    When you post code, wrap it in code tags. Highlight it and click the CODE button above the text input area.
    You seem to be trying to reuse the speed and hours variables in your loop. That's probably a mistake at this point. Keep it simpler by defining a loop variable.
    Also I don't see the need for two loops. You just want to show how far the vehicle has traveled for each one-hour increment, assuming constant speed, for the number of hours it has been traveling, right? So a single for loop should be sufficient.

  • Can anyone help me with this program?

    I have to make program that asks the user for information that they would want on a business card. Then, I am supposed ot take that information that was gathered with a listener and display it on a second panel using graphicsstuff (such as g.drawString(VARIABLEHERE, int x, int y). I can get thepart of the program that would ask for the information, but I can't figure out where to go from there on how to display the information. If anyone could help I would be enternally gratefully. This assignment is due Friday morning at 9:00. Thanks!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PanelPractice extends JPanel
         private static JButton insert;
         private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
         private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
         public static void main (String[] args)
              //Makes two colored panels that are nested within a third.
              JFrame frame = new JFrame ("Business Card");
              frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              //Makes the first subpanel
              JPanel subPanel1 = new JPanel();
                   JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
                   //     Sets up the GUI
                        //Creates labels for the information questions
                        nameLabel = new JLabel ("Type the name you want on the card: ");
                        positionLabel = new JLabel ("Type the person's position: ");
                        areaLabel = new JLabel ("Type the person's area of business: ");
                        telLabel = new JLabel ("Type the person's telephone number: ");
                        faxLabel = new JLabel ("Type the person's fax number: ");
                        emailLabel = new JLabel ("Type the person's e-mail address: ");
                        add1Label = new JLabel ("Type the person's place of business: ");
                        add2Label = new JLabel ("Type the business' street address: ");
                        add3Label = new JLabel ("Type the business' city, state, and zip: ");
                        //Creates a JTextField to hold the person's name
                        nameField = new JTextField (10);
                        positionField = new JTextField (10);
                        areaField = new JTextField (10);
                        telField = new JTextField (10);
                        faxField = new JTextField (10);
                        emailField = new JTextField (10);
                        add1Field = new JTextField (10);
                        add2Field = new JTextField (10);
                        add3Field = new JTextField (10);
                        //add the nameLabel and nameField to the panel
                        subPanel1.add (nameLabel);
                        subPanel1.add (nameField);
                        //add the positionLabel and positionField to the panel
                        subPanel1.add (positionLabel);
                        subPanel1.add (positionField);
                        //add the areaLabel and areaField to the panel
                        subPanel1.add (areaLabel);
                        subPanel1.add (areaField);
                        //add the telLabel and telField to the panel
                        subPanel1.add (telLabel);
                        subPanel1.add (telField);
                        //add the faxLabel and faxField to the panel
                        subPanel1.add (faxLabel);
                        subPanel1.add (faxField);
                        //add the emailLabel and emailField to the panel
                        subPanel1.add (emailLabel);
                        subPanel1.add (emailField);
                        //add the add1Label and add1Field to the panel
                        subPanel1.add (add1Label);
                        subPanel1.add (add1Field);
                        //add the add2Label and add2Field to the panel
                        subPanel1.add (add2Label);
                        subPanel1.add (add2Field);
                        //add the add3Label and add3Field to the panel
                        subPanel1.add (add3Label);
                        subPanel1.add (add3Field);
                        //Creates a button to press to insert the information onto the card
                        insert = new JButton ("Insert Information!");
                        //Creates a Listener and makes it listen for the button to be pressed
                        insert.addActionListener (new ButtonListener());
                        //add the button to the panel
                        subPanel1.add (insert);
                        //set the size of the panel to the width and height constants
                        subPanel1.setPreferredSize (new Dimension (350, 300));
                        //set the color of the panel to whatever you choose
                        subPanel1.setBackground (Color.red);
              //Makes the second subpanel
              JPanel subPanel2 = new JPanel();
              subPanel2.setPreferredSize (new Dimension(500,300));
              subPanel2.setBackground (Color.blue);
              //Makes the primary panel
              JPanel primary = new JPanel();
              primary.setBackground (Color.black);
              primary.add (subPanel1);
              primary.add (subPanel2);
              frame.getContentPane().add(primary);
              frame.pack();
              frame.setVisible(true);
                   //     Represents an action listener for the insert button.
                   private static class ButtonListener implements ActionListener
                        public void actionPerformed (ActionEvent event)
                             //get the text from the textfields
                             nameText = nameField.getText();
                             positionText = positionField.getText();
                             areaText = areaField.getText();
                             telText = telField.getText();
                             faxText = faxField.getText();
                             emailText = emailField.getText();
                             add1Text = add1Field.getText();
                             add2Text = add2Field.getText();
                             add3Text = add3Field.getText();
                   public static class CustomComponent extends JPanel
                   public void paintComponent(Graphics g)
                   super.paintComponent(g);
                   g.drawString(nameText, 5, 5);
    }

    Sorry about that...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PanelPractice extends JPanel
    private static JButton insert;
    private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
    private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
    public static void main (String[] args)
    //Makes two colored panels that are nested within a third.
    JFrame frame = new JFrame ("Business Card");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    //Makes the first subpanel
    JPanel subPanel1 = new JPanel();
    JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
    // Sets up the GUI
    //Creates labels for the information questions
    nameLabel = new JLabel ("Type the name you want on the card: ");
    positionLabel = new JLabel ("Type the person's position: ");
    areaLabel = new JLabel ("Type the person's area of business: ");
    telLabel = new JLabel ("Type the person's telephone number: ");
    faxLabel = new JLabel ("Type the person's fax number: ");
    emailLabel = new JLabel ("Type the person's e-mail address: ");
    add1Label = new JLabel ("Type the person's place of business: ");
    add2Label = new JLabel ("Type the business' street address: ");
    add3Label = new JLabel ("Type the business' city, state, and zip: ");
    //Creates a JTextField to hold the person's name
    nameField = new JTextField (10);
    positionField = new JTextField (10);
    areaField = new JTextField (10);
    telField = new JTextField (10);
    faxField = new JTextField (10);
    emailField = new JTextField (10);
    add1Field = new JTextField (10);
    add2Field = new JTextField (10);
    add3Field = new JTextField (10);
    //add the nameLabel and nameField to the panel
    subPanel1.add (nameLabel);
    subPanel1.add (nameField);
    //add the positionLabel and positionField to the panel
    subPanel1.add (positionLabel);
    subPanel1.add (positionField);
    //add the areaLabel and areaField to the panel
    subPanel1.add (areaLabel);
    subPanel1.add (areaField);
    //add the telLabel and telField to the panel
    subPanel1.add (telLabel);
    subPanel1.add (telField);
    //add the faxLabel and faxField to the panel
    subPanel1.add (faxLabel);
    subPanel1.add (faxField);
    //add the emailLabel and emailField to the panel
    subPanel1.add (emailLabel);
    subPanel1.add (emailField);
    //add the add1Label and add1Field to the panel
    subPanel1.add (add1Label);
    subPanel1.add (add1Field);
    //add the add2Label and add2Field to the panel
    subPanel1.add (add2Label);
    subPanel1.add (add2Field);
    //add the add3Label and add3Field to the panel
    subPanel1.add (add3Label);
    subPanel1.add (add3Field);
    //Creates a button to press to insert the information onto the card
    insert = new JButton ("Insert Information!");
    //Creates a Listener and makes it listen for the button to be pressed
    insert.addActionListener (new ButtonListener());
    //add the button to the panel
    subPanel1.add (insert);
    //set the size of the panel to the width and height constants
    subPanel1.setPreferredSize (new Dimension (350, 300));
    //set the color of the panel to whatever you choose
    subPanel1.setBackground (Color.red);
    //Makes the second subpanel
    JPanel subPanel2 = new JPanel();
    subPanel2.setPreferredSize (new Dimension(500,300));
    subPanel2.setBackground (Color.blue);
    //Makes the primary panel
    JPanel primary = new JPanel();
    primary.setBackground (Color.black);
    primary.add (subPanel1);
    primary.add (subPanel2);
    frame.getContentPane().add(primary);
    frame.pack();
    frame.setVisible(true);
    // Represents an action listener for the insert button.
    private static class ButtonListener implements ActionListener
    public void actionPerformed (ActionEvent event)
    //get the text from the textfields
    nameText = nameField.getText();
    positionText = positionField.getText();
    areaText = areaField.getText();
    telText = telField.getText();
    faxText = faxField.getText();
    emailText = emailField.getText();
    add1Text = add1Field.getText();
    add2Text = add2Field.getText();
    add3Text = add3Field.getText();
    public static class CustomComponent extends JPanel
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    g.drawString(nameText, 5, 5);
    } No..I'm not expecting someone to do it for me. I am having trouble figuring out what to do next. I cannot get anything to show up on the second panel...the part that displays the information that the listener gathered.
    If I could figure out how to get one thing to show up...then I could probably do the rest...it's getting it started that I can't get.

  • Please help me finish this program

    Hi I am currently trying to finish this project with labview...though I have run into some problems.  First off here is the explaination of the project.
    And lastly, the project, a bicycle dash-o-meter, which will return us to using LabVIEW to produce a program which will take the rotations of a wheel (27" diameter, with a sensor mounted at 6" from the center), and calculate distance, speed, time, ...).  We'll use a simulated input of course, but we could interface it to a real bicycle wheel or any wheel or shaft for that matter.
    My problem is that we have only been using labview for 2 weeks and it is now due tomorrow.  I have a program all drawn up but its not controlled by a blinking led...how to I get a simulated signal to run this.  Also how do I get the distance to increase without just changing...for example if I went at 100 km/h for 16 minutes thats roughly 16 km how to I get it to keep that 16 km and then slow down the speed to 50 km/h and get the 16km and hour to increase at the new rate?
    I hope some of that made sense.  Any help is appriciated. 
    Here is what I have...P.S. Labview 7.0 is what we have here at the school.
    Attachments:
    Bike Project.vi ‏44 KB

    Dan's suggestion is really good.
    For your LED to blink, determine logically when you want that to occur.
    One way is to change the state of an LED at each revolution, kind of like a switch. At the start, the LED is OFF. When the distance traveled is greater than the circumference, the LED comes ON, and your distance counter is reset to zero. When the distance traveled is again greater than the circum., change the LED again.
    Another way is that when the wheel rotates one revolution, turn the LED ON for a set time, like 0.5 seconds. However, at speeds greater than 120RPM, the LED will always be ON.
    What you are really doing is counting pulses from the sensor, and the time between them.
    If I might make a couple of suggestions for your code, don't hide the STOP button. Also, try to always keep your wiring to flow in a Left-to-Right direction. That will certainly help with understanding what everything does, and will make troubleshooting a great deal easier.
    B-)

  • I am trying to install a new ram into my mac book air and i am having trouble finding it. can anyone help me through this?

    can anyone help walk me through placing a new ram into a mac book air 2010 model

    The RAM in a MacBook Air cannot be upgraded after purchase.
    https://discussions.apple.com/message/12782306#12782306

Maybe you are looking for

  • Remove and/or change password Sun Java System Web Server 7.0U3

    Running SJSWS 7.0U3 on Solaris 10 U6 I have access to the physical box the server is running on. I must have set something by mistake, now trying to connect to http://ipaddres/host:80 I get prompted for a username password. This is NOT the admin pass

  • Possible to create detailed and Summary in same crystal report?

    Hello I have worked with cyrstal reports back in 2001. Now I am back to creation of reports. I vaguely remember I was able to create summary and detailed reports from one crystal report file. I don't remember if I was using two different stored proce

  • Moving itunes from old pc to new mac

    i just bought my first mac. i need to move my itunes library to my new imac. my first try at manually copying the library (disk use) to my ipod failed (i didn't think to check the size of my "itunes" folder). i pretty much have my 80 g ipod full. The

  • A new way to mess up iPhoto (and have a nervous brake down)

    Occasionally I need to get into the Modified or Originals folder in the iPhoto Library. Usually it's because I mistakenly saved a Photoshop Elements .psd file to one of these folders by mistake or some other dumb thing. So I decided that it would be

  • Mismatch of version of external and kernel dp lib

    Hello All i'm trying to uppgrade a was abap kernel 7.00 from version 133 to 16 on  db2 udb database. I use the files: SAP Kernel 700 64-Bit, Unicode, AIX64bit - FOR ECC60 Landscape: SAPEXEDB_146-20000977.SAR SAPEXE_146-20000978.SAR lib_dbsl_156-20000