Help me my assignment!!!

Now you have to think. In many areas of science (e.g., computer graphics, computational geometry, image analysis, robotics, physics) , it is often necessary to determine whether or not two line segments intersect. Assume that we have two 2D line segments one line segment has endpoints (Ax,Ay) and (Bx,By) and the other segment has endpoints (Cx,Cy) and (Dx,Dy).
Write a static main method for a class called IntersectionTester that asks the user for the eight values of the integer coordinates for two line segments and then displays a message indicating whether or not the line segments intersect. Assume that all coordinates are entered as integer values. Here are two equations which you must use to determine whether or not the intersection occurs:
(1 - s)Ax + sBx = (1-t)Cx + tDx
(1 - s)Ay + sBy = (1-t)Cy + tDy
You will need to solve for s and t and see if both s and t lie in the decimal range from 0 to 1. Your output should display the entered values and the result in a format similar to this:
Enter coordinates:
Ax = 2
Ay = 8
Bx = 5
By = 5
Cx = 5
Cy = 7
Dx = 1
Dy = 3
Line segment (2,8)(5,5) intersects with segment (5,7)(1,3).
Make sure to test at least each of the following cases:
i) parallel horizontal lines that intersect
ii) parallel horizontal lines that do not intersect
iii) parallel vertical lines that intersect
iv) parallel vertical lines that do not intersect
v) non-parallel lines that intersect
vi) non-parallel lines that do not intersect
You should also hand in a single picture (.gif or .jpg file using a Paint program) showing properly scaled drawings of ALL of your test cases so that the TA knows what you tested. Each linesegment should have its endpoints properly labelled with the values you entered during testing. Note that to do this part, you'll need to understand the "if" statement which is described in notes #4. Here is an idea as to how you will use it (replace the green code with your own java statements):
if (/*there is an intersection */) {
//DO SOMETHING
else {
//DO SOMETHING ELSE
following is my code:
public class Intersection {
     public void isitintersect() {
          int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy;
          System.out.println("Enter segment endpoints :");
          Ax = Keyboard.getInteger();
          Ay = Keyboard.getInteger();
          Bx = Keyboard.getInteger();
          By = Keyboard.getInteger();
          Cx = Keyboard.getInteger();
          Cy = Keyboard.getInteger();
          Dx = Keyboard.getInteger();
          Dy = Keyboard.getInteger();
     double s = ((Ax-Cx) + (((Cy-Ay)+s * (Ay-By))/(Cy-Dy))*(Cx-Dx));
     double t = (((Cy-Ay) + (((Ax-Cx) + t * (Cx-Dx))/(Ax-Bx)) * (Ay-By))/(Cy-Dy));
     if ((s>0)&&(s<1)&&(t>0)&&(t<1))
System.out.println("Line segment"+(AxAyBxBy)+"intersects with segment"+(CxCyDxDy));
else
System.out.println("Sorry,It can not intersect for ever.");
QUESTION:
I input any integer, the computer tell me it is not intersect.

I'd rewrite this as a matrix equation, where s and t are the unknowns to solve for. (The inverse of the matrix is easy to calculate by hand.)
Degenerate cases are flagged by a zero determinant in this case - no inverse is possible.
It'd be an elegant solution to the problem. Try it and see.

Similar Messages

  • Need help in my assignment, Java programing?

    Need help in my assignment, Java programing?
    It is said that there is only one natural number n such that n-1 is a square and
    n + 1 is a cube, that is, n - 1 = x2 and n + 1 = y3 for some natural numbers x and y. Please implement a program in Java.
    plz help!!
    and this is my code
    but I don't no how to finsh it with the right condition!
    plz heelp!!
    and I don't know if it right or wrong!
    PLZ help me!!
    import javax.swing.JOptionPane;
    public class eiman {
    public static void main( String [] args){
    String a,b;
    double n,x,y,z;
    boolean q= true;
    boolean w= false;
    a=JOptionPane.showInputDialog("Please enter a number for n");
    n=Double.parseDouble(a);
    System.out.println(n);
    x=Math.sqrt(n-1);
    y=Math.cbrt(n+1);
    }

    OK I'll bite.
    I assume that this is some kind of assignment.
    What is the program supposed to do?
    1. Figure out the value of N
    2. Given an N determine if it is the correct value
    I would expect #1, but then again this seem to be a strange programming assignment to me.
    // additions followI see by the simulpostings that it is indeed #1.
    So I will give the tried and true advice at the risk of copyright infringement.
    get out a paper and pencil and think about how you would figure this out by hand.
    The structure of a program will emerge from the mists.
    Now that I think about it that advice must be in public domain by now.
    Edited by: johndjr on Oct 14, 2008 3:31 PM
    added additional info

  • Need help with this assignment!!!!

    Please help me with this. I am having some troubles. below is the specification of this assignment:
    In geometry the ratio of the circumference of a circle to its diameter is known as �. The value of � can be estimated from an infinite series of the form:
    � / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ...
    There is another novel approach to calculate �. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine that you throw darts at that dart board randomly. Then the ratio of the number of darts that fall within the circle to the total number of darts thrown is the same as the ratio of the area of the circle to the area of the square dart board. The area of a circle with unit radius is just � square unit. The area of the dart board is 4 square units. The ratio of the area of the circle to the area of the square is � / 4.
    To simuluate the throwing of darts we will use a random number generator. The Math class has a random() method that can be used. This method returns random numbers between 0.0 (inclusive) to 1.0 (exclusive). There is an even better random number generator that is provided the Random class. We will first create a Random object called randomGen. This random number generator needs a seed to get started. We will read the time from the System clock and use that as our seed.
    Random randomGen = new Random ( System.currentTimeMillis() );
    Imagine that the square dart board has a coordinate system attached to it. The upper right corner has coordinates ( 1.0, 1.0) and the lower left corner has coordinates ( -1.0, -1.0 ). It has sides that are 2 units long and its center (as well as the center of the inscribed circle) is at the origin.
    A random point inside the dart board can be specified by its x and y coordinates. These values are generated using the random number generator. There is a method nextDouble() that will return a double between 0.0 (inclusive) and 1.0 (exclusive). But we need random numbers between -1.0 and +1.0. The way we achieve that is:
    double xPos = (randomGen.nextDouble()) * 2 - 1.0;
    double yPos = (randomGen.nextDouble()) * 2 - 1.0;
    To determine if a point is inside the circle its distance from the center of the circle must be less than the radius of the circle. The distance of a point with coordinates ( xPos, yPos ) from the center is Math.sqrt ( xPos * xPos + yPos * yPos ). The radius of the circle is 1 unit.
    The class that you will be writing will be called CalculatePI. It will have the following structure:
    import java.util.*;
    public class CalculatePI
    public static boolean isInside ( double xPos, double yPos )
    public static double computePI ( int numThrows )
    public static void main ( String[] args )
    In your method main() you want to experiment and see if the accuracy of PI increases with the number of throws on the dartboard. You will compare your result with the value given by Math.PI. The quantity Difference in the output is your calculated value of PI minus Math.PI. Use the following number of throws to run your experiment - 100, 1000, 10,000, and 100,000. You will call the method computePI() with these numbers as input parameters. Your output will be of the following form:
    Computation of PI using Random Numbers
    Number of throws = 100, Computed PI = ..., Difference = ...
    Number of throws = 1000, Computed PI = ..., Difference = ...
    Number of throws = 10000, Computed PI = ..., Difference = ...
    Number of throws = 100000, Computed PI = ..., Difference = ...
    * Difference = Computed PI - Math.PI
    In the method computePI() you will simulate the throw of a dart by generating random numbers for the x and y coordinates. You will call the method isInside() to determine if the point is inside the circle or not. This you will do as many times as specified by the number of throws. You will keep a count of the number of times a dart landed inside the circle. That figure divided by the total number of throws is the ratio � / 4. The method computePI() will return the computed value of PI.
    and below is what i have so far:
    import java.util.*;
    public class CalculatePI
        public static boolean isInside ( double xPos, double yPos )   
            boolean result;  
            double distance = Math.sqrt( xPos * xPos + yPos * yPos );
            if (distance < 1)               
                result = true;
            return result;
        public static double computePI ( int numThrows )
            Random randomGen = new Random ( System.currentTimeMillis() );       
            double xPos = (randomGen.nextDouble()) * 2 - 1.0;
            double yPos = (randomGen.nextDouble()) * 2 - 1.0;
            boolean isInside = isInside (xPos, yPos);
            int hits = 0;
            double PI = 0;        
            for ( int i = 0; i <= numThrows; i ++ )
                if (isInside)
                    hits = hits + 1;
                    PI = 4 * ( hits / numThrows );
            return PI;
        public static void main ( String[] args )
            Scanner sc = new Scanner (System.in);
            System.out.print ("Enter number of throws:");
            int numThrows = sc.nextInt();
            double Difference = computePI(numThrows) - Math.PI;
            System.out.println ("Number of throws = " + numThrows + ", Computed PI = " + computePI(numThrows) + ", Difference = " + Difference );       
    }when i tried to compile it says "variable result might not have been initialized" Why is this? and please check this program for me too see if theres any syntax or logic errors. Thanks.

    when i tried to compile it says "variable result might not have been
    initialized" Why is this?Because you only assigned it if distance < 1. What is it assigned to if distance >= 1? It isn't.
    Simple fix:
    boolean result = (distance < 1);
    return result;
    or more simply:
    return (distance < 1);
    and please check this program for me too see if theres any syntax or
    logic errors. Thanks.No, not going to do that. That's much more your job, and to ask specific questions about if needed.

  • I need some help on an assignment

    Ok, first off I'm only looking for some help I don't want anyone writing the program for me. I have an assignment where i have to make part of an Asteroids game and it's based off of a program in my book called DirectioPanel.java. I had it going good until my Professor told the class we had to use an array when it would be better to do it without an array. Here's the instructions.
    Design and implement a class that represents a spaceship. The spaceship can be drawn (side view) in the two horizontal or two vertical directions. When the left arrow key is pressed, turn the spaceship to the left. When the right arrow key is pressed, turn the spaceship to the right. When the space key is pressed, have a laser beam shoot out of the front of the spaceship.
    Do one or more of the following extra features:
    a) Provide a title screen
    b) Add a star field in the background
    c) Change the background color when the laser shoots
    d) Add more than the four directions for the spaceship
    e) Add a collection of asteroids moving around the screen
    a. Allow your spaceship to shoot down the asteroids
    b. Allow the asteroids to destroy your spaceship
    f) Assign the up arrow key the function to move the spaceship forward
    g) Add “alien” spaceships that shoot at you
    h) Keep score
    i) Control the spaceship with the mouse instead of the keyboard
    j) Anything else that you think might enhance this assignment (check with me first)
    Here's the code it's supposed to be based off of.
    [directionpanel.java|http://www.cs.dartmouth.edu/~cs5/examples/chap07/DirectionPanel.java]
    And here is what i have so far. My question is how would I use an array in the program, by the way i only have time to program in D, F, and E, maybe B.
    And if there are any other suggestions I'm open to them because i haven't done any programming in 8 months or more because of other classes.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Asteroids extends JPanel {
         private final int WIDTH = 500, HEIGHT = 500;
         private final int JUMP = 10;
         private int x, y, currentX, currentY, startX, startY;
         public AsteroidsPanel() {
              addKeyListener(new AsteroidsListener());
              startX = WIDTH / 2;
              startY = HEIGHT / 2;
         public void paintComponent(Graphics screen) {
              super.paintComponent(screen);
    }Thanks

    Create a 2-dimensional array of boolean values, true represents where the spaceship is, false otherwise. From this you can draw a grid containing one black square the rest white. Create a spaceship class which has the 4 possible looks of the spaceshift {up, down, left, right}, attributes in the spaceship such as direction its facing would be handy. Then work out from your grid what are legal or illegal moves, e.g. moving your spaceship off the grid would obviously be an illegal move.

  • I need help with an assignment

    I have several issues. I am doing a project for a class and I'm stuck. the message doesn't appear in the textbox.  That's the only problem with this code so far. Next thing I haven't been able to figure out is  that
    I need to add two "do", "do while", "do until", or "for-next" loops. I am stuck. I tried to add a "do" loop for adding up the totals but Visual Basic 2010 Express froze up every time I tried to run the program
    after that. Here is my code:
    Public Class IceCream
        Private Sub totalButton_Click(sender As System.Object, e As System.EventArgs) Handles totalButton.Click
            Dim small As Integer
            Dim medium As Integer
            Dim large As Integer
            Dim total As Decimal = 0
            Dim result As Decimal = 0
            Dim result1 As Decimal = 0
            Dim result2 As Decimal = 0
            ' assign values from user input
            small = Val(chocTextBox.Text)
            medium = Val(strawTextBox.Text)
            large = Val(vaniTextBox.Text)
            ' alert if checkbox unchecked
            If (chocCheckBox.Checked = False AndAlso
                strawCheckBox.Checked = False AndAlso
                vaniCheckBox.Checked = False) Then
                'display error message in dialog for input violation
                MessageBox.Show("what's your flavor?", "flavor error", MessageBoxButtons.OK,
                                MessageBoxIcon.Question)
            End If
            ' calculate prices
            result = small * 2.0
            result1 = medium * 3.0
            result2 = large * 4.0
            total = result + result1 + result2
            ' display total
            totalChocLabel.Text = String.Format("{0:C}", result)
            totalStrawLabel.Text = String.Format("{0:C}", result1)
            totalVaniLabel.Text = String.Format("{0:C}", result2)
            totalLabel.Text = String.Format("{0:C}", total)
            Dim message As String ' displays message
            Dim chocolate As Integer
            Dim strawberry As Integer
            Dim vanilla As Integer
            message = chocCheckBox.Checked & strawCheckBox.Checked & vaniCheckBox.Checked
            Select Case message
                Case chocolate
                    message = "You got Chocolate!"
                Case strawberry
                    message = "You got Strawberry!"
                Case vanilla
                    message = "You got Vanilla!"
                    ' display message in TextBox
                    iceCreamTextBox.Text = (ControlChars.Tab & message & ControlChars.CrLf)
            End Select
        End Sub
    End Class

    BG,
    Knowing that this is homework (and thank you for stating that - many here don't), please understand that the members here are somewhat reluctant to do more than prod you in the right direction. I'm sure that you agree - handing you an answer wouldn't be
    your own work and you'd never learn anything from it.
    I'd like to make some suggestions though:
    At the top of your form's code, put the following:
    Option Strict On
    Option Explicit On
    Option Infer Off
    This will ensure that you're using the "tightest" code possible and that you're not relying on the compiler to figure out what you mean about anything. You'll likely find some compile errors shown (little blue 'squigly' lines beneath variables
    in your code) so you need to work through those until there are none.
    That can be a challenge itself! If you find yourself lost in a sea of 'blue squigglies' (if there's such a term), then bit at at time, post back with one and we'll help you work through it and explain why you got them to start with.
    Don't use the Val() function. It's old and should, in my opinion, be removed from use forever; it's more than deprecated but that aside, it will seem to work when it shouldn't. As an off-the-cuff-example:
    Dim s As String = "111 1st Avenue"
    Dim d as Double = Val(s)
    Did that work?
    Unfortunately, yes it did but what does that tell you? It should have failed - it didn't.
    Use the numeric type's .TryParse method as a test to see if the string can be parsed to that type and, if so, then proceed from there or inform the user that what they entered isn't valid. I could go into this part alone for the next 45 minutes ... and I'll
    come up with an example if you're interested, but my point is: Don't rely on Val() to work like you think it does.
    Once you have all of that sorted out, put a breakpoint in (as already mentioned) and line-by-line, step into each. When the program halts at the end of each, hover your mouse over each variable and look to see what it/they are.
    At some point, you'll have an "ahHA!" moment and you'll have solved your problem!
    I hope that helps. :)
    Still lost in code, just at a little higher level.

  • Please Help. Problem Assigning Datasource

    I created a test Master data Infoobject abc_xxx and loaded data and then after testing deleted it. Now when I am trying to assign  a new datasource to an existing Infosource from where I loaded data into the test Infoobject , I am getting error message that there there is no InfoProvider or data target named abc_xxx.
    Could anybody please help me out here?
    Thanks in advance.

    I am getting error message that there "there is no InfoProvider or data target named abc_xxx(name of Infoobject)"
    If you are not trying to use this infoobject, the above message should not appear at all.
    Please follow the following steps to assign a source system.
    1. Goto Source Systems and check the source system u want to use is in Active state.
    2. right-click on ur InfoSource -> Assign Datasource
    3. from the drop-down, selet ur source system
    4. choose a datasource if the source is r/3
    5. modify/change transfer structure/comm structure/transfer rules
    6. save n activate.
    Hope this helps.

  • Search help for Acct Assignment not working

    Hi,
       When I create a PO and go into the account assignment tab at the item level and try to bring up the search help by clicking on the Binoculars , nothing happens. The backend has been upgraded to ERP2005. We are on SRM 5.0
    Any thoughts on why this could happen?
    Can you shed some light on how I could investigate this issue.
    Your help is appreciated.
    Joe

    Hi
    This is a bug in the System.  Are you talking of customer fields / standard fields - search help ?
    You need to raise an OSS message with SAP on this.
    Meanwhile, try these SAP OSS notes.
    <u>Note 739509 BBPPO01: SEARCH FOR ACCOUNT ASSIGNMENT CATEGORY DOESN'T WORK
    Note 746788 - Back-end system search help for cost center
    Note 656633 - Search help requires dialog users
    Note 907016 - Error when you select search help</u>
    Also ensure, proper authorization objects are provided by BASIS team.
    Let me know incase you need any assistance.
    Regards
    - Atul

  • Help desk cannot assign retention policies to new mailboxes

    I am running Exchange 2010 SP1.  I would like to give my help desk the ability to create new mailboxes.  When a new mailbox is created, we select the option to assign a Retention policy to it.  I added the help desk members to the "Recipient
    Management" group.  They can now create new mailboxes but they get an access denied error when they select a retention policy to be assigned to it.  As a member of the "Organization Management" group, I am able to assign retention policies to new
    mailboxes.
    With the RBAC editor, I created a custom management role group called "Mailbox Management" based on the "Recipient Management" group and added the "Retention Management" role to the group.  I believe this will give them the permissions to apply retention
    policies to new mailboxes but it also gives them the permissions to create/modify/delete retention policies themselves.  I only want to give them the rights to add mailboxes to retention policies. 
    I assume I need to create a custom management role and assign this new role to my new management role group but can someone tell me the minimum role entries I need for my help desk to be able to assign rentention policies during the mailbox creation
    wizard process?
    Steve

    Hi Steve,
    Due to you post the issue in a wrong type, and we changed the type to give you a suggestion.
    Please refer to below information:
    http://technet.microsoft.com/en-us/library/dd638205.aspx 
    The permissions required to configure messaging policy and compliance vary depending on the procedure being performed or the cmdlet you want to run. For more information about messaging policy and compliance, see
    Messaging Policy and Compliance, refer to above article you could find out what permissions you need to perform the procedure or run the cmdlet, then you coudl create a roleassignment
    for the customized role group.
    Regards!
    Gavin
    TechNet Community Support

  • Please Help me in Assigning New Id for Different persons

    version 11g
    please Help me in assiging new person id for dirrerent persons if there middle name is different
    I listed Out Three Scenarios in the below example. Please help me out
    WITH NAMES AS(
    /* Scenario1 -- Three dirrerent people so assign Three diffrrent ID,
                      keeping 1 id as is and assign two new ids from sequence*/
    SELECT 47540310 ID , 'WO' LAST_NAME , 'ROBERT' FIRST_NAME , 'C' MIDDLE_NAME FROM DUAL UNION ALL 
    SELECT 47540310 ID , 'WO' LAST_NAME , 'ROBERT' FIRST_NAME , 'W' MIDDLE_NAME FROM DUAL  UNION ALL 
    SELECT 47540310 ID , 'WO' LAST_NAME , 'ROBERT' FIRST_NAME , 'X' MIDDLE_NAME FROM DUAL  UNION ALL 
      /* Scenario2 NULL can be equal to any value if there is only one value to equate with
        In the below case we have two values that can equate with null so assign three diffrent ids */
    SELECT 47540300 ID , 'AMATUZIO' LAST_NAME , 'ALBERT' FIRST_NAME , 'J' MIDDLE_NAME FROM DUAL UNION ALL 
      SELECT 47540300 ID , 'AMATUZIO' LAST_NAME , 'ALBERT' FIRST_NAME , NULL MIDDLE_NAME FROM DUAL  UNION ALL
    SELECT 47540300 ID , 'AMATUZIO' LAST_NAME , 'ALBERT' FIRST_NAME , 'L' MIDDLE_NAME FROM DUAL  UNION ALL
      /* Scenario3 NULL can be equal to any value if there is only one value to equate with
        In the below case we have ONE VALUE  that can equate with null so DONT ASSIGN ANY IDS*/
    SELECT 17540300 ID , 'AMARONE' LAST_NAME , 'JOSEPH' FIRST_NAME , 'J' MIDDLE_NAME FROM DUAL UNION ALL  
    SELECT 17540300 ID , 'AMARONE' LAST_NAME , 'JOSEPH' FIRST_NAME , NULL MIDDLE_NAME FROM DUAL
    Select * from names
    o/P Required
    ID    LAST_NAME    FIRST_NAME    MIDDLE_NAME
    47540310    WO      ROBERT          C
    99999990    WO      ROBERT          W                   -- New Sequence Number
    99999991     WO      ROBERT         X                   -- New Sequence Number
    47540300    AMATUZIO    ALBERT    J
    99999992    AMATUZIO    ALBERT                          -- New Sequence Number
    99999993    AMATUZIO    ALBERT    L                     -- New Sequence Number
    17540300    AMARONE    JOSEPH    J
    17540300    AMARONE    JOSEPH    Thanks
    Edited by: new learner on Jun 7, 2012 2:12 PM

    I don't understand what this line is doing:
    FIRST_VALUE (fn_get_person_id) -- sequence for the functionI have the impression that the only difference with my query is to select distinct values not to consider duplicates. Correct me if I'm wrong.
    To me this one should give the same result as your query:
    WITH NAMES AS ( /* Scenario1 -- Three dirrerent people so assign Three diffrrent ID, keeping 1 id as is and assign two
    new ids from sequence*/
                   SELECT   47540310 ID,
                            'WO' LAST_NAME,
                            'ROBERT' FIRST_NAME,
                            'C' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   47540310 ID,
                            'WO' LAST_NAME,
                            'ROBERT' FIRST_NAME,
                            'C' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   47540310 ID,
                            'WO' LAST_NAME,
                            'ROBERT' FIRST_NAME,
                            'W' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   47540310 ID,
                            'WO' LAST_NAME,
                            'ROBERT' FIRST_NAME,
                            'X' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   /* Scenario2 NULL can be equal to any value if there is only one value to equate with
                     In the below case we have two values that can equate with null so assign three diffrent ids */
                   SELECT   47540300 ID,
                            'AMATUZIO' LAST_NAME,
                            'ALBERT' FIRST_NAME,
                            'J' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   47540300 ID,
                            'AMATUZIO' LAST_NAME,
                            'ALBERT' FIRST_NAME,
                            NULL MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   47540300 ID,
                            'AMATUZIO' LAST_NAME,
                            'ALBERT' FIRST_NAME,
                            'L' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   /* Scenario3 NULL can be equal to any value if there is only one value to equate with
                     In the below case we have ONE VALUE  that can equate with null so DONT ASSIGN ANY IDS*/
                   SELECT   17540300 ID,
                            'AMARONE' LAST_NAME,
                            'JOSEPH' FIRST_NAME,
                            'K' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   17540300 ID,
                            'AMARONE' LAST_NAME,
                            'JOSEPH' FIRST_NAME,
                            'Y' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   17540300 ID,
                            'AMARONE' LAST_NAME,
                            'JOSEPH' FIRST_NAME,
                            NULL MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   17540300 ID,
                            'AMARONE' LAST_NAME,
                            'JOSEPH' FIRST_NAME,
                            'M' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   17540300 ID,
                            'AMARONE' LAST_NAME,
                            'JOSEPH' FIRST_NAME,
                            'M' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   99999999 ID,
                            'LO' LAST_NAME,
                            'CHRISTY' FIRST_NAME,
                            NULL MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   99999999 ID,
                            'LO' LAST_NAME,
                            'CHRISTY' FIRST_NAME,
                            'M' MIDDLE_NAME
                     FROM   DUAL
                   UNION ALL
                   SELECT   99999999 ID,
                            'LO' LAST_NAME,
                            'CHRISTY' FIRST_NAME,
                            'M' MIDDLE_NAME
                     FROM   DUAL),
    sel_names AS (  SELECT id
                              , last_name
                              , first_name
                              , middle_name
                              , COUNT (middle_name) OVER (PARTITION BY id ORDER BY middle_name) cnt
                              , ROW_NUMBER () OVER (PARTITION BY id  ORDER BY middle_name) rown
                           FROM (SELECT DISTINCT * FROM names) -- use SELECT DISTINCT here to remove duplicates
                       ORDER BY 1, 2, 3, 4
    SELECT 8888888 new_id, id, last_name, first_name
         , middle_name
      FROM sel_names
    WHERE cnt > 1 AND rown > 1;As you can see I have only replace the the table with an inline view using SELECT DISTINCT *
                           FROM (SELECT DISTINCT * FROM names) -- use SELECT DISTINCT here to remove duplicatesFor the new id I have put a dummy value 888888, you may use a function or a sequence according to your needs.
    Regards.
    Al

  • Problems with search help for cost assignment

    We have recently applied SP 10 to our Dev and QA systems. We have our system set up in such a way that when the user clicks on the binoculars for cost assignments and does a search, they will only see the accounts they are authorized to use (coming from the backend security).  This works just fine in Production (without SP10).
    But, depending on the test user, I am getting mixed results in our QA system. I have already sent a message to OSS but am hoping someone in this forum can point me in the right direction.
    I have searched the forum and found several topics on this issue.  But, I was not able to find something that is the same as my problem.
    For my test users, they click on the binoculars then click Start. One test user was brought back to the shopping cart without any results. Another test user was given several entries.  But, they did not belong to that user.
    Can someone please point me in the right direction to get the binoculars working correctly?

    Hello,
    For First::
    In general the CO Area (here: cost center) is derived from R/3 Backend Enterprise
    Structure and should be re-determined if another acc. objects is
    entered that belongs to a different CO Area. Please also check the
    settings in R/3 Backend IMG, path:
    ->Enterprise Structure ->Assignment ->Controlling
    ->Assign company code to controlling area
    The company code is assigned to the CO Area through the following
    assignment:
    ->Materials Management
    ->Assign purchasing organization to company code
    The CO Area is in general the organizational object in
    highest (CO) level. Assignments to other MM/CO objects are located
    in lower Enterprise hierarchy level. Hence, the CO Area does not
    change if a different CO object of a lower level (here: cost center)
    is assigned to a SRM document.
    For Second::
    The only possibility I see is to set the message to error message in
    the customizing in the backend. The message number is KI 170. When you
    look at the long text of this message in transaction SE91 in the
    backend, you will find the description where to look in the customizing.
    When you have set this message to ERROR, then no purchase order will be
    created in the backend. Instead the shopping basket gets the status
    'ERROR' and the administrator will recieve a work item in his inbox.
    Then he can check the backend and either post the purchase orders again
    after solving the problem, or he can delete the shopping baskets.
    Please check the note for more infos or the documentation.
    Setting the message KI 170 to error message will solve your problem.
    See note 333136.  I would think that if you create
    a PO directly in the backend if you do not have the message configured
    as and error you will be able to create the PO.
    I hope this information helps.
    Kind regards,
    Gaurav

  • Need help on an assignment using methods.

    The assignment I'm working on uses methods to input an integer and a character and then output a hollow square of the size of the integer and made up of the character entered. This is what I have so far, I'm not quite sure how to fill in the methods....
    import java.util.Scanner; //For scanner class
    public class Methods
    {public static void giveInstructions()
         //instructions
         {System.out.println("Enter a character and an integer. A hollow square of size n times n made up of the character" +
              " will be constructed.");
    public static int getSize (Scanner kbd)
         int size;
         Scanner kbd = new Scanner (System.in);
         System.out.println("     Enter the size: ");
         size = kbd.nextInt();
    public static char getCharacter (Scanner kbd)     
         System.out.println("Enter the Character: ");
         final char ch;
         ch = kbd.nextLine();
    public static void drawSquare(int size, char ch)
    public static void drawSolidLine( int size, char ch )
           String s;
            for( int i = 0; i < size ; i++ )
                    // ADD ch       
           System.out.println( s );
    public static void drawHollowLine( int size, char ch )
                String s = "";
                // add char to s   
               for( int i = 0 ; i < ( size - 2) ; i++ )
                       s = s + " ";
               // Add char to s
              System.out.println( s );
    }I would appreciate any kind of help!

    > I'm really confused. I can't think of anything that I
    would need to write under the main method because
    everything that I need would be under the other
    methods.
    I assume you're replying to me(?). Did you compile and run my example? What is it you don't understand about it? I see your methods are all static so you could do something like this:
    public class Test {
        public static void printA() {
            System.out.println("A");
        public static void printB() {
            System.out.println("B");
        public static void printSomething(String s) {
            System.out.println(s);
        public static void main(String[] args) {
            Test.printA();
            Test.printB();
            Test.printSomething("AB");
    }

  • Requesting a bit of help with my assignment - Pretty basic...

    I have an assignment where I have to create "public double findAverage()" and use if statements to determine the average based on different equations would be. I'll post it down in the thread. I feel confident I have that one properly done. Then I have to create "public char findLetterGrade()" and use if statements to determine the letter grade based on that average from the first one. When I compile it, the compiler highlights "if(average >= 90)" and says it cannot find symbol - variable average. Here's my full code, any help would be very much appreciated.
    public class CompSciStudent
        private String name;
        private String year;
        private int labGrade;
        private int examGrade;
        public CompSciStudent(String inName, String inYear, int inLabGrade, int inExamGrade)
            name = inName;
            year = inYear;
            labGrade = inLabGrade;
            examGrade = inExamGrade;
        public CompSciStudent(String inName, String inYear)
            name = inName;
            year = inYear;
        public void setName(String inName)
            name = inName;
        public void setYear(String inYear)
            year = inYear;
        public void setLabGrade(int inLabGrade)
            labGrade = inLabGrade;
        public void setExamGrade(int inExamGrade)
            examGrade = inExamGrade;
        public String getName()
            return name;
        public String getYear()
            return year;
        public int getLabGrade()
            return labGrade;
        public int getExamGrade()
            return examGrade;
        public double findAverage()
            double average;
            if (year == "Fr")
                average = 0.70*examGrade + 0.30*labGrade;
            else if (year == "So")
                average = 0.65*examGrade + 0.35*labGrade;
            else if (year == "Jr")
                average = 0.60*examGrade + 0.40*labGrade;
            else if (year == "Sr")
                average = 0.50*examGrade + 0.50*labGrade;
            else
                average = 0.00;
             return average;
        public char findLetterGrade()
            char letterGrade;
            if (average >= 90)
                letterGrade = 'A';
            else if (90 > average >= 80)
                letterGrade = 'B';
            else if (80 > average >= 70)
                letterGrade = 'C';
            else if (70 > average >= 55)
                letterGrade = 'D';
            else if (average < 55)
                letterGrade = 'F';
            else
                letterGrade = 'E';
            return letterGrade;
    }

    public class CompSciStudent
        private String name;
        private String year;
        private int labGrade;
        private int examGrade;
        public CompSciStudent(String inName, String inYear, int inLabGrade, int inExamGrade)
            name = inName;
            year = inYear;
            labGrade = inLabGrade;
            examGrade = inExamGrade;
        public CompSciStudent(String inName, String inYear)
            name = inName;
            year = inYear;
        public void setName(String inName)
            name = inName;
        public void setYear(String inYear)
            year = inYear;
        public void setLabGrade(int inLabGrade)
            labGrade = inLabGrade;
        public void setExamGrade(int inExamGrade)
            examGrade = inExamGrade;
        public String getName()
            return name;
        public String getYear()
            return year;
        public int getLabGrade()
            return labGrade;
        public int getExamGrade()
            return examGrade;
        public double findAverage()
            double average=0.0; //change
            if (year == "Fr")
                average = 0.70*examGrade + 0.30*labGrade;
            else if (year == "So")
                average = 0.65*examGrade + 0.35*labGrade;
            else if (year == "Jr")
                average = 0.60*examGrade + 0.40*labGrade;
            else if (year == "Sr")
                average = 0.50*examGrade + 0.50*labGrade;
            else
                average = 0.00;
             return average;
        public char findLetterGrade()
            char letterGrade= 'A'; //change
            if (average >= 90)
                letterGrade = 'A';
            else if (90 > average >= 80)
                letterGrade = 'B';
            else if (80 > average >= 70)
                letterGrade = 'C';
            else if (70 > average >= 55)
                letterGrade = 'D';
            else if (average < 55)
                letterGrade = 'F';
            else
                letterGrade = 'E';
            return letterGrade;
    }The Java Compiler has an issue when you send a variable into an if statement that hasn't been properly initialized (AKA with a value). This should work though.

  • Help needed for assignment????

    Hi there everbody! Well I'm quite new to this, therfore I would greatly appreciated if some1 could help me with my assignment.
    Assignment:Make a Game applet that makes an object(red oval) move around the applet window by using only four buttons(Up, Right, Down, Left).
    I managed to do the button and the oval but both are not connected. Can some1 help me with the codes coz my assignment is due this week!!
    Here are what I've already done:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Game extends Applet implements ActionListener{
    Button up1 = new Button("Up");
    Button down1 = new Button("Down");
    Button right1 = new Button("Right");
    Button left1 = new Button("Left");
    public void init() {
    Panel p = new Panel(new GridLayout(3, 3));
    p.setBackground(Color.white);
    p.add(new Label(""));
    p.add(up1);
    up1.addActionListener(this);
    p.add(new Label(""));
    p.add(left1);
    left1.addActionListener(this);
    p.add(new Label(""));
    p.add(right1);
    right1.addActionListener(this);
    p.add(new Label(""));
    p.add(down1);
    down1.addActionListener(this);
    add(p);
    public void actionPerformed(ActionEvent event) {
    repaint();
    public void paint(Graphics g) {
    Font font = new Font("serif", Font.BOLD, 20);
    g.setColor(Color.black);
    g.setFont(font);
    g.drawString("Click on button to move the object.",80,350);
    Color c = Color.red;
    g.setColor(c);
    g.fillOval(200, 150, 155, 95);
    As for the "g.fillOval(200, 150, 155, 95);" my lecturer told me that I should not use fix variables and I have to find out what the variables are so that the oval could move in the applet window upon clicking at the four buttons....I would be greatly appreciated if some1 could help me...

    Hi the main thing is you will need 2 classes, one for the applet, and one for the drawing panel.
    You create a class that extends Panel, call it PaintPanel and override paint(), which is where you do the drawing.
    In the applet you add your buttons, and the PaintPanel. When the buttons are clicked they change the state in the DrawPanel.
    The big thing to remember is you don't override paint() in the applet, only in your PaintPanel.

  • Help! Self-assigned IP?

    Hello! I'm a new Mac user and I just installed all the updates released today(December 8th, 2009) for my late 2008 unibody Macbook Pro with Snow Leopard installed.
    After the updates, I noticed my clock/date was set back to the year 2000 and a screen came up after reboot that asked me to allow access for "configd." Not knowing what this was and thinking it could be malicious I denied it, and that's when I realized I couldn't connect to the internet using Airport (WIFI) or Ethernet through my ATT DSL line. It keeps saying that I have a "self-assigned IP." I can't access the internet at all(through WIFI or ethernet)so can't download anything.
    I've tried to restart and turn a lot of things off and on with airport and the firewall settings with no luck. Has anyone else experienced these problems? Is something buggy with the updates? How can I fix this?
    I find it very unusual that my date/time would be set to the year 2000 and after the update, and it would affect my internet access. I would hope after an update nothing would get corrupted or ask me something about giving access to "configd" even though many users like me probably have no idea what it is. I wish it wouldn't of asked me that and gave it access automatically.
    Thanks for your time, and I hope to hear from some folks!

    Hi Alex6969,
    Welcome to the Support Communities!  The articles below will help you troubleshoot the issue you are having with your wired ethernet connection.
    Connecting to the Internet via cable, DSL, or local area network (LAN) in Mac OS X v10.6 or later
    http://support.apple.com/kb/HT5304
    OS X Mavericks: Choose a manual IP address or use DHCP
    http://support.apple.com/kb/PH14009
    I hope this information helps ....
    - Judy

  • Beginner needs help with programming assignment

    So I have been working on it and it is reading everything and posting everything to the output file, but it looks like this
    MonthlyRainfall(cm)
    Average: 3.66
    January 7.29, above averageApril3.55, below averageNovember0.15, below average
    When instead it should look like this. Don't know what I need to do to get it to work like this. If I have to much regarding the IF Else statements or I just don't have it laid out right. Any help is appreciated. Thanks.
    Monthly Rainfall (cm)
    Average: 3.66
    January 7.29, above average
    April 3.55, below average
    November 0.15, below average
    Here is the code I have so far:
    package assign4;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.PrintWriter;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class Rainfall2 {/** main method
    * This is where the program starts.
    * @param args
    public static void main(String[] args) throws FileNotFoundException {
    * Title: Assignment 4
    * Description: CS 161 Assignment #4
    * date: October 27th 2008
    final String fileName = "src/assign4/rain2.txt";
    Scanner myFile = new Scanner( new FileReader( fileName ) );
    PrintWriter outFile = new
    PrintWriter ("src/assign4/rainfalloutput.out");
    //declares variables
    String title;
    String subtitle;
    String units;
    String date;
    int month1, month2, month3;
    double rain1, rain2, rain3;
    double average;
    * Read 6 lines from the input file
    title = myFile.next();
    subtitle = myFile.next();
    units = myFile.next();
    month1 = myFile.nextInt();
    rain1 = myFile.nextDouble();
    month2 = myFile.nextInt();
    rain2 = myFile.nextDouble();
    month3 = myFile.nextInt();
    rain3 = myFile.nextDouble();
    myFile.close(); //close the input file
    average = (rain1 + rain2 + rain3) / 3.0; //computes the average rainfall from data points
    outFile.println( title + subtitle + units);
    outFile.printf ("Average: %5.2f %n", average);
    if (month1 == 1)
    outFile.print ("January ");
    else if (month1 == 2)
    outFile.print ("February");
    else if (month1 == 3)
    outFile.print ("March");
    else if (month1 == 4)
    outFile.print ("April");
    else if (month1 == 5)
    outFile.print ("May");
    else if (month1 == 6)
    outFile.print ("June");
    else if (month1 == 7)
    outFile.print ("July");
    else if (month1 == 8)
    outFile.print ("August");
    else if (month1 == 9)
    outFile.print ("September ");
    else if (month1 == 10)
    outFile.print ("October");
    else if (month1 == 11)
    outFile.print ("November");
    else if (month1 == 12)
    outFile.print ("December");
    if (rain1 > average)
    outFile.print ( rain1 + ", above average");
    else
    if (rain1 == average)
    outFile.print ( rain1 + ", average");
    else
    if (rain1 < average)
    outFile.print ( rain1 + ", below average");
    if (month2 == 1)
    outFile.printf ("January");
    else if (month2 == 2)
    outFile.printf ("February");
    else if (month2 == 3)
    outFile.printf ("March");
    else if (month2 == 4)
    outFile.printf ("April");
    else if (month2 == 5)
    outFile.printf ("May");
    else if (month2 == 6)
    outFile.printf ("June");
    else if (month2 == 7)
    outFile.printf ("July");
    else if (month2 == 8)
    outFile.printf ("August");
    else if (month2 == 9)
    outFile.printf ("September");
    else if (month2 == 10)
    outFile.printf ("October");
    else if (month2 == 11)
    outFile.printf ("November");
    else if (month2 == 12)
    outFile.printf ("December");
    if (rain2 > average)
    outFile.printf ( rain2 + ", above average");
    else
    if (rain2 == average)
    outFile.printf ( rain2 + ", average");
    else
    if (rain2 < average)
    outFile.printf ( rain2 + ", below average");
    if (month3 == 1)
    outFile.printf ("January");
    else if (month3 == 2)
    outFile.printf ("February");
    else if (month3 == 3)
    outFile.printf ("March");
    else if (month3 == 4)
    outFile.printf ("April");
    else if (month3 == 5)
    outFile.printf ("May");
    else if (month3 == 6)
    outFile.printf ("June");
    else if (month3 == 7)
    outFile.printf ("July");
    else if (month3 == 8)
    outFile.printf ("August");
    else if (month3 == 9)
    outFile.printf ("September");
    else if (month3 == 10)
    outFile.printf ("October");
    else if (month3 == 11)
    outFile.printf ("November");
    else if (month3 == 12)
    outFile.printf ("December");
    if (rain3 > average)
    outFile.printf ( rain3 + ", above average");
    else
    if (rain3 == average)
    outFile.printf ( rain3 + ", average");
    else
    if (rain3 < average)
    outFile.printf ( rain3 + ", below average");
    outFile.close();
    }

    The printf method does not inlcude a LF/CR. You will have to add it yourself.
    In future when you post code, highlight it and click the CODE button to retain formatting.

  • Need help with an assignment

    first of all, who has heard of the game called zuul? It is a very boring text based game I am currently having the pleasure of improving.
    Basically, you are in a room, that is connected to a bunch of other rooms and depending on the room you are in, you have different exists and different items in the room.
    The goal is to navigate through the collection of Rooms and there is no real win condition, It is more for learning then for actually playing.
    You navigate by a series of commands such as: go (direction)( as in "direction of exit", NSEW), quit, a few other odd bits.
    ex: go south, quit, go west etc
    The game has several classes: Game, Command, CommandWords, Item, Parser, Room.
    Obviously Game is the main central head conch, (it is not the super class.)
    Game makes use of Item, Room, Parser, and Command.
    Item is the class that deals with the number of items in the Room.
    Room is the class that deals with the rooms the player will navigate to and from.
    Command reads in the commands such as "go-(direction)" or "quit".
    Parser makes everybody understand each other by using both Command and CommandWords.
    CommandWords is a list of commands such as "go", "quit" etc.
    The problem I am having right now is to allow a player to move through the rooms while holding a certain item. The item has to come from the rooms and the player should be able to drop it.
    So I have to add two new commands: take and drop. The problem is that I have been asked to do this without creating a new class. Otherwise I would have just created class Player and be done with it. So I am trying to figure out whose responsibility should it be to take care of the take and drop command. I have done some preliminary work in class Game, it is the take(Command command) and drop() methods.
    I have also a few questions concerning other aspects of the project, I have listed their locations here:
    1. The take() method in class Game, the for-each loop, a complier error with ArrayList
    2. class Parser, a general question about the string tokenzier
    If you want to see how the game is suppose to run, just comment out the bodies of take() and drop(). Not the declaration. Everything else works.
    I shall now provide the code to all classes. I wish there were an option to upload a zip file, then you don't have to read through all the codes and copy&paste all the codes. The complier I am using is BlueJ. And the SDK version is 1.6. With the exception of class Game, everything else can be assumed to be error free.
    Thank you for your time,
    Davy
    class Game
    import java.util.*;
    *  This class is the main class of the "World of Zuul" application.
    *  "World of Zuul" is a very simple, text based adventure game.  Users
    *  can walk around some scenery. That's all. It should really be extended
    *  to make it more interesting!
    *  To play this game, create an instance of this class and call the "play"
    *  method.
    *  This main class creates and initialises all the others: it creates all
    *  rooms, creates the parser and starts the game.  It also evaluates and
    *  executes the commands that the parser returns.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    public class Game
        private Parser parser;
        private Room currentRoom;
        private Room previousRoom;
        private Stack<Room> previousRooms;
         * Create the game and initialise its internal map.
        public Game()
            createRooms();
            parser = new Parser();
         * Create all the rooms and link their exits together.
        private void createRooms()
            Room outside, theatre, pub, lab, office;
            // create the rooms
            outside = new Room("outside the main entrance of the university");
            theatre = new Room("in a lecture theatre");
            pub = new Room("in the campus pub");
            lab = new Room("in a computing lab");
            office = new Room("in the computing admin office");
            // create some items
            Item desk, chair, beer, podium, tree;
            desk = new Item("desk", "student desk",10);
            chair = new Item("chair", "student chair",5);
            beer = new Item("beer", "glass of beer", 0.5);
            podium = new Item("podium", "lecture podium", 100);
            tree = new Item("tree", "a tree", 500.5);
            // put items in some of the rooms
            outside.addItem(tree);
            theatre.addItem(desk);
            theatre.addItem(chair);
            theatre.addItem(podium);
            pub.addItem(beer);
            pub.addItem(beer);
            office.addItem(desk);
            lab.addItem(chair);
            lab.addItem(beer);
            // initialise room exits
            outside.setExit("east", theatre);
            outside.setExit("south", lab);
            outside.setExit("west", pub);
            theatre.setExit("west", outside);
            pub.setExit("east", outside);
            lab.setExit("north", outside);
            lab.setExit("east", office);
            office.setExit("west", lab);
            currentRoom = outside;  // start game outside
            previousRooms = new Stack<Room>(); // no rooms on the stack
            previousRoom = null;
         *  Main play routine.  Loops until end of play.
        public void play()
            printWelcome();
            // Enter the main command loop.  Here we repeatedly read commands and
            // execute them until the game is over.
            boolean finished = false;
            while (! finished) {
                Command command = parser.getCommand();
                finished = processCommand(command);
            System.out.println("Thank you for playing.  Good bye.");
         * Print out the opening message for the player.
        private void printWelcome()
            System.out.println();
            System.out.println("Welcome to the World of Zuul!");
            System.out.println("World of Zuul is a new, incredibly boring adventure game.");
            System.out.println("Type 'help' if you need help.");
            System.out.println();
            System.out.println(currentRoom.getLongDescription());
         * Given a command, process (that is: execute) the command.
         * @param command The command to be processed.
         * @return true If the command ends the game, false otherwise.
        private boolean processCommand(Command command)
            boolean wantToQuit = false;
            if(command.isUnknown()) {
                System.out.println("I don't know what you mean...");
                return false;
            String commandWord = command.getCommandWord();
            if (commandWord.equals("help")) {
                printHelp();
            else if (commandWord.equals("go")) {
                goRoom(command);
            else if (commandWord.equals("look")) {
                look(command);
            else if (commandWord.equals("eat")) {
                eat(command);
            else if (commandWord.equals("back")) {
                back(command);
            else if (commandWord.equals("stackBack")) {
                stackBack(command);
            else if (commandWord.equals("take")){
                take(command);
            else if (commandWord.equals("drop")) {
                drop(command);
            else if (commandWord.equals("quit")) {
                wantToQuit = quit(command);
            // else command not recognised.
            return wantToQuit;
        // implementations of user commands:
         * Print out some help information.
         * Here we print some stupid, cryptic message and a list of the
         * command words.
        private void printHelp()
            System.out.println("You are lost. You are alone. You wander");
            System.out.println("around at the university.");
            System.out.println();
            System.out.println("Your command words are:");
            System.out.println(parser.getCommands());
         * Try to go to one direction. If there is an exit, enter the new
         * room, otherwise print an error message.
         * @param command The command entered.
        private void goRoom(Command command)
            if(!command.hasSecondWord()) {
                // if there is no second word, we don't know where to go...
                System.out.println("Go where?");
                return;
            String direction = command.getSecondWord();
            // Try to leave current room.
            Room nextRoom = currentRoom.getExit(direction);
            if (nextRoom == null) {
                System.out.println("There is no door!");
            else {
                previousRooms.push(currentRoom);
                previousRoom = currentRoom;
                currentRoom = nextRoom;
                System.out.println(currentRoom.getLongDescription());
         * "Look" was entered.
         * @param command The command entered.
        private void look(Command command)
            if(command.hasSecondWord()) {
                System.out.println("Look what?");
                return;
            System.out.println(currentRoom.getLongDescription());
         * "Eat" was entered.
         * @param command The command entered.
        private void eat(Command command)
            if(command.hasSecondWord()) {
                System.out.println("Eat what?");
                return;
            System.out.println("You have eaten and are no longer hungry!");
         * "Back" was entered.
         * @param command The command entered.
        private void back(Command command)
            if(command.hasSecondWord()) {
                System.out.println("Back what?");
                return;
            if (previousRoom==null) {
                System.out.println("Can't go back.");
                return;
            // push current room on stack (for stackBack)
            previousRooms.push(currentRoom);
            // swap current and previous rooms (for back)
            Room temp = currentRoom;
            currentRoom = previousRoom;
            previousRoom = temp;
            // You could replace the previous three lines with the following
            // which use the stack to get the previous room
            // but note that this makes "back" dependent on "stackBack".
            // (If you do it this way you no longer need "temp".
            // currentRoom = previousRoom;
            // previousRoom = previousRooms.peek();
            System.out.println("You have gone back:");
            System.out.println(currentRoom.getLongDescription());
         * "StackBack" was entered.
         * @param command The command entered.
        private void stackBack(Command command)
            if(command.hasSecondWord()) {
                System.out.println("StackBack what?");
                return;
            if (previousRooms.isEmpty()) {
                System.out.println("Can't go StackBack.");
                return;
            // set previous room (for "back")
            previousRoom = currentRoom;
            // set new current room (using stack)
            currentRoom = previousRooms.pop();
            System.out.println("You have gone StackBack:");
            System.out.println(currentRoom.getLongDescription());
         * allows a player to take something from the room
         * @param command
        private void take(Command command){
        String a;
        a=command.getSecondWord();
        for (Item i:currentRoom.items()) { //a for each loop, since the room's items are kept in a list, but this gives a                                           //compiler error, it doesn't work because items is an ArrayList, but I need a way to pick up the item. I thought that if //given the item's name, I could run a check through the room's ArrayList of items via a for-each loop
            if (a==i.getName()) {
            removeItem (i);
            return;
         * allows a player to drop an item in the room
         * @param command
        private void drop(Command command) {
            if(command.hasSecondWord()) {
                System.out.println("drop what?");
                return;
            //add item method is suppose to be used here
         * "Quit" was entered. Check the rest of the command to see
         * whether we really quit the game.
         * @param command The command entered.
         * @return true, if this command quits the game, false otherwise.
        private boolean quit(Command command)
            if(command.hasSecondWord()) {
                System.out.println("Quit what?");
                return false;
            else {
                return true;  // signal that we want to quit
    }class Room
    import java.util.*;
    * Class Room - a room in an adventure game.
    * This class is part of the "World of Zuul" application.
    * "World of Zuul" is a very simple, text based adventure game. 
    * A "Room" represents one location in the scenery of the game.  It is
    * connected to other rooms via exits.  For each existing exit, the room
    * stores a reference to the neighboring room.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    * @author L.S. Marshall
    * @version 1.03 October 25, 2007
    public class Room
        private String description;
        private HashMap<String, Room> exits;        // stores exits of this room.
        // The items in the room
        private ArrayList<Item> items;
         * Create a room described "description". Initially, it has
         * no exits. "description" is something like "a kitchen" or
         * "an open court yard".
         * @param description The room's description.
        public Room(String description)
            this.description = description;
            exits = new HashMap<String, Room>();
            items = new ArrayList<Item>();
         * Define an exit from this room.
         * @param direction The direction of the exit.
         * @param neighbor  The room to which the exit leads.
        public void setExit(String direction, Room neighbor)
            exits.put(direction, neighbor);
         * Gives a short description of the room.
         * @return The short description of the room
         * (the one that was defined in the constructor).
        public String getShortDescription()
            return description;
         * Return a description of the items in the room
         * (Note that this could be combined with getLongDescription, but
         * this way shows better cohesion, and could avoid code duplication
         * for future enhancements.)
         * @return A description of the items in this room
        public String getItemsDescription()
            String s = new String();
            if (items.size()==0)
                s += "There are no items in this room.\n";
            else {
                s += "The item(s) in the room are:\n";
                for (Item item : items ) {
                   s += item.getInfo() + "\n";
            return s;
         * Return a description of the room in the form:
         *     You are in the kitchen.
         *     Exits: north west
         *     and information on the items in the room
         * @return A long description of this room
        public String getLongDescription()
            String s = "You are " + description + ".\n" + getExitString() + "\n";
            s += getItemsDescription();
            return s;
         * Return a string describing the room's exits, for example
         * "Exits: north west".
         * @return Details of the room's exits.
        private String getExitString()
            String returnString = "Exits:";
            Set<String> keys = exits.keySet();
            for(String exit : keys) {
                returnString += " " + exit;
            return returnString;
         * Return the room that is reached if we go from this room in direction
         * "direction". If there is no room in that direction, return null.
         * @param direction The exit's direction.
         * @return The room in the given direction.
        public Room getExit(String direction)
            return exits.get(direction);
         * Adds the given item to the room.
         * @param item The item to be added
        public void addItem(Item item)
            items.add(item);
         * Removes an item if the person picks it up
         * @param item the item to be removed
        public void removeItem (Item item)
            items.remove(item);
    }class Item
    * This represents an item in a room in zuul.
    * @author L.S. Marshall
    * @version 1.00 October 9, 2007
    public class Item
        // The description of the item
        private String description;
        // The weight of the item
        private double weight;
        private String name;
         * Constructor for objects of class Item
         * @param desc description of the item
         * @param weight the weight of the item
        public Item(String name, String desc, double weight)
            description = desc;
            this.weight = weight;
            this.name=name;
         * Returns a string representing this item
         * @return string representing this item
        public String getInfo()
            return ("Item: " + description + ", weighs " + weight + ".");
         * returns the name of the string
         * @ return the name in a string
        public String getName()
            return ( name );
    }class Command
    * This class is part of the "World of Zuul" application.
    * "World of Zuul" is a very simple, text based adventure game. 
    * This class holds information about a command that was issued by the user.
    * A command currently consists of two strings: a command word and a second
    * word (for example, if the command was "take map", then the two strings
    * obviously are "take" and "map").
    * The way this is used is: Commands are already checked for being valid
    * command words. If the user entered an invalid command (a word that is not
    * known) then the command word is <null>.
    * If the command had only one word, then the second word is <null>.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    public class Command
        private String commandWord;
        private String secondWord;
         * Create a command object. First and second word must be supplied, but
         * either one (or both) can be null.
         * @param firstWord The first word of the command. Null if the command
         *                  was not recognised.
         * @param secondWord The second word of the command.
        public Command(String firstWord, String secondWord)
            commandWord = firstWord;
            this.secondWord = secondWord;
         * Return the command word (the first word) of this command. If the
         * command was not understood, the result is null.
         * @return The command word.
        public String getCommandWord()
            return commandWord;
         * @return The second word of this command. Returns null if there was no
         * second word.
        public String getSecondWord()
            return secondWord;
         * @return true if this command was not understood.
        public boolean isUnknown()
            return (commandWord == null);
         * @return true if the command has a second word.
        public boolean hasSecondWord()
            return (secondWord != null);
    }class Parser
    import java.util.Scanner;
    import java.util.StringTokenizer;
    //I read the documentation for String Tokenizer, and I have a few questions relating to a pet project of mine. The //project is to build a boolean algebra simplifer. I would give it a boolean expression and it will simplify it for me.
    //Which is very similar to what this class does. The documentation mentioned a delimiter for separating the tokens.
    //yet I see none here, is the delimiter at default, the space between the words? and if I were to set manually //delimiters, how do I do that?
    //Once I read in the string, should it be Parser's job to execute the boolean simplification part? According the RDD,
    //it shouldn't, but doing so would keep everything in fewer classes and therefore easier to manage, wouldn't it?
    * This class is part of the "World of Zuul" application.
    * "World of Zuul" is a very simple, text based adventure game. 
    * This parser reads user input and tries to interpret it as an "Adventure"
    * command. Every time it is called it reads a line from the terminal and
    * tries to interpret the line as a two word command. It returns the command
    * as an object of class Command.
    * The parser has a set of known command words. It checks user input against
    * the known commands, and if the input is not one of the known commands, it
    * returns a command object that is marked as an unknown command.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    * @author L.S. Marshall
    * @version 1.01 October 9, 2007
    public class Parser
        private CommandWords commands;  // holds all valid command words
        private Scanner reader;         // source of command input
         * Create a parser to read from the terminal window.
        public Parser()
            commands = new CommandWords();
            reader = new Scanner(System.in);
         * Command returns the command typed by the user.
         * @return The next command from the user.
        public Command getCommand()
            String inputLine;   // will hold the full input line
            String word1 = null;
            String word2 = null;
            System.out.print("> ");     // print prompt
            inputLine = reader.nextLine();
            // Find up to two words on the line.
            Scanner tokenizer = new Scanner(inputLine);
            if(tokenizer.hasNext()) {
                word1 = tokenizer.next();      // get first word
                if(tokenizer.hasNext()) {
                    word2 = tokenizer.next();      // get second word
                    // note: we just ignore the rest of the input line.
            // Now check whether this word is known. If so, create a command
            // with it. If not, create a "null" command (for unknown command).
            if(commands.isCommand(word1)) {
                return new Command(word1, word2);
            else {
                return new Command(null, word2);
         * Returns a list of valid command words.
         * @string list of valid command words
        public String getCommands()
            return commands.getCommandList();
    }class CommandWords
    * This class is part of the "World of Zuul" application.
    * "World of Zuul" is a very simple, text based adventure game.
    * This class holds an enumeration of all command words known to the game.
    * It is used to recognise commands as they are typed in.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    * @author L.S. Marshall
    * @version 1.01 October 9, 2007
    public class CommandWords
        // a constant array that holds all valid command words
        private static final String[] validCommands = {
            "go", "quit", "help", "look", "eat", "back", "stackBack",
            "take", "drop",
         * Constructor - initialise the command words.
        public CommandWords()
            // nothing to do at the moment...
         * Check whether a given String is a valid command word.
         * @param aString the command word
         * @return true if it is, false if it isn't.
        public boolean isCommand(String aString)
            for(int i = 0; i < validCommands.length; i++) {
                if(validCommands.equals(aString))
    return true;
    // if we get here, the string was not found in the commands
    return false;
    * Return a string containing all valid commands.
    * @return string of all valid commands
    public String getCommandList()
    String s="";
    for(String command: validCommands) {
    s += command + " ";
    return s;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    right, sorry, that was thoughtless of me.
    class Parser
    import java.util.Scanner;
    import java.util.StringTokenizer;
    //I read the documentation for String Tokenizer, and I have a few questions relating to a pet project of mine. The //project is to build a boolean algebra simplifer. I would give it a boolean expression and it will simplify it for me.
    //Which is very similar to what this class does. The documentation mentioned a delimiter for separating the tokens.
    //yet I see none here, is the delimiter at default, the space between the words? and if I were to set manually //delimiters, how do I do that?
    //Once I read in the string, should it be Parser's job to execute the boolean simplification part? According the RDD,
    //it shouldn't, but doing so would keep everything in fewer classes and therefore easier to manage, wouldn't it?
    * This class is part of the "World of Zuul" application.
    * "World of Zuul" is a very simple, text based adventure game. 
    * This parser reads user input and tries to interpret it as an "Adventure"
    * command. Every time it is called it reads a line from the terminal and
    * tries to interpret the line as a two word command. It returns the command
    * as an object of class Command.
    * The parser has a set of known command words. It checks user input against
    * the known commands, and if the input is not one of the known commands, it
    * returns a command object that is marked as an unknown command.
    * @author  Michael Kolling and David J. Barnes
    * @version 2006.03.30
    * @author L.S. Marshall
    * @version 1.01 October 9, 2007
    public class Parser
        private CommandWords commands;  // holds all valid command words
        private Scanner reader;         // source of command input
         * Create a parser to read from the terminal window.
        public Parser()
            commands = new CommandWords();
            reader = new Scanner(System.in);
         * Command returns the command typed by the user.
         * @return The next command from the user.
        public Command getCommand()
            String inputLine;   // will hold the full input line
            String word1 = null;
            String word2 = null;
            System.out.print("> ");     // print prompt
            inputLine = reader.nextLine();
            // Find up to two words on the line.
            Scanner tokenizer = new Scanner(inputLine);
            if(tokenizer.hasNext()) {
                word1 = tokenizer.next();      // get first word
                if(tokenizer.hasNext()) {
                    word2 = tokenizer.next();      // get second word
                    // note: we just ignore the rest of the input line.
            // Now check whether this word is known. If so, create a command
            // with it. If not, create a "null" command (for unknown command).
            if(commands.isCommand(word1)) {
                return new Command(word1, word2);
            else {
                return new Command(null, word2);
         * Returns a list of valid command words.
         * @string list of valid command words
        public String getCommands()
            return commands.getCommandList();
    }

Maybe you are looking for

  • I can't watch videos on most websites. Help!

    i can't watch videos on most sites. the only one which i can watch videos so far is youtube. i upgraded the latest driver for my graphics card (nvidia geforce) and also adobe flash but still doesn't help. thanks in advance for your assistance.

  • Bex Query using BICS running fine in Rich client but v. slow in Launchpad

    Hi guys, At my client client we are using BICS to use Bex Query in Web Intellience, and i created a report that takes less than 10 seconds once run in Rich client but when i create the same Webi report in Launch pad: the list of values take forever t

  • 8830 Stops checking email until a battery pull

    Hello:   I'm pretty new to BB's, the 8830 being my first one. My problem is that I have it set up to check a pop account but it seems that I need to pull the battery almost daily because it stops checking for new messages.  I've tried turning it off/

  • Deployment error in netbeans

    hi i have a problem deploying my application to the Sun Java System Application server..i'm trying to deploy it through netbeans and i'm getting this error.. Finished registering server resources Deployment of application failed - Server returned HTT

  • New Infotype Framework

    Hello! I'm just going to implement a new Infotype that should use the Data Sharing functionality for Concurrent Employment. I've read a document about the implementation of the "new" Infotype Framework, but I haven't found an example how to use it fo