1.11M Members

Please lend a little help....assignment due tonight

 
0
 

Hi everyone...

I feel like this is the end of everything....I cannot do this java, I have reviewed the lecture slides again and again and I still cannot do it....Yes I know I am stupid but I really do need help....

This is my assignment, and it is simple (For you guys and girls), so please try to help me...

I have attached the pdf file from my university....

I am up to point 13....where I have to use "charAt" and arrays etc...I am extremely confused here....

Basically the end result is I need to make the program ask the user what letters to put, using S, P, A, R , E.

Then the program will see where each of those letter is placed, and the different possibilities are Spear, Spare, Parse, Reaps, etc.

Sigh....

I hope I can get some help from here...It is due tonight...And yes I have read the lecture slides again and again...I even talked to the teacher, which helped me a lot but still not enough....

Thank you...

*cry*

Attachments ws05.pdf (163.96KB)
 
1
 

I understand it can be difficult, but on this forum we help people that show that they've put in some effort. We do not take your requirements and write a program for you.

Please show what you've done and then ask a specific questions such as "Why isn't my function for printing a character array working?".

You said you're up to point 13. Which part of point 13 do you not understand? You should have the user input section complete from the previous points, so you need write the part that prints each letter of a String.

Here are a few things for you to look into for help in this section:
How do you print to the console/terminal in Java?
What does charAt take as parameters? What does it return?

 
0
 

It's an assignment to show you can do "it" (whatever "it" may be) in Java.
You admit you can't do it. Why the heck should we help you cheat and help you by doing it for you?
We'd end up with incompetent (by their own admission) potential coworkers.

 
0
 

Ok....first of all, do you really need to answer like that to someone in need? I never asked for instant answer. Of course I would love to know how to do it. All I asked was for help.


And yes, I have done my own work, I have done all that I can, and which is why posting on this forum is my last resort. Don't you have any sympathy towards someone who truly needs help? It's not like I came to this forum to ask for insta- answer...... I simply asked for help.... and it's not like I have not done any work....

Now for those who want to help, here, I did my best.

import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import java.util.Scanner;

/**
 * Partial solution for Stage 1 of the digital billboard
 *
 * @author phi
 * @version 2011 2
 */
public class DynamicBillboard

{
    public static void main(String[] args)
    {
        // initial size of the display in pixels
        final int WINDOW_WIDTH = 300;
        final int WINDOW_HEIGHT = 120;
        // size of the grid for the digital billboard
        final int BB_WIDTH = 50;
        final int BB_HEIGHT = 30;

        // create a billboard
        BillboardInterface billboard = new DigitalBillboardFrame(
                "SCSS",
                WINDOW_WIDTH, WINDOW_HEIGHT,
                BB_WIDTH, BB_HEIGHT);

        // we will make letters 5 cells wide and 12 high
        final int LETTER_WIDTH = 5;
        final int LETTER_HEIGHT = 12;
        // and leave a 1 cell gap between letters
        final int GAP = 1;

        // the top left of the first letter in the word will be 2 cells from the left and 1 down
        final int START_X = 2;
        final int START_Y = 1;
        
        Scanner Keyboard = new Scanner (System.in);
        String userMsg ="";
        
        
        
        
        
        
        
        // forever
            for(;;)
            {
              System.out.println("Please enter a message: ");
              userMsg = Keyboard.nextLine();
              String v = "";
              String result = v.trim(); 
            
            // get a message from the user
            
            // for each letter in the message
                int x = START_X; 
                int y = START_Y;
                for(int i = 0; i < 5; i++)
                {
                  // display the i_th letter
                  switch (5)
                  {
                    case 's':
                    billboard.turnOn(START_X+1, START_Y+2);
                    billboard.turnOn(START_X+2, START_Y+2);
                    billboard.turnOn(START_X+3, START_Y+2);
                    billboard.turnOn(START_X+4, START_Y+2);
                    billboard.turnOn(START_X, START_Y+3);
                    billboard.turnOn(START_X, START_Y+4);
                    billboard.turnOn(START_X+1, START_Y+5);
                    billboard.turnOn(START_X+2, START_Y+5);
                    billboard.turnOn(START_X+3, START_Y+5);
                    billboard.turnOn(START_X+4, START_Y+6);
                    billboard.turnOn(START_X+4, START_Y+7);
                    billboard.turnOn(START_X, START_Y+8);
                    billboard.turnOn(START_X+1, START_Y+8);
                    billboard.turnOn(START_X+2, START_Y+8);
                    billboard.turnOn(START_X+3, START_Y+8);
        
                    break;
                    
                    final int START_X1 = 8;
                    final int START_Y1 = 1; 
                                         
                    case 'p':
                    billboard.turnOn(START_X1, START_Y1+2);
                    billboard.turnOn(START_X1+1, START_Y1+2);
                    billboard.turnOn(START_X1+2, START_Y1+2);
                    billboard.turnOn(START_X1+3, START_Y1+2);
                    billboard.turnOn(START_X1, START_Y1+3);
                    billboard.turnOn(START_X1, START_Y1+4);
                    billboard.turnOn(START_X1, START_Y1+5);
                    billboard.turnOn(START_X1, START_Y1+6);
                    billboard.turnOn(START_X1, START_Y1+7);
                    billboard.turnOn(START_X1, START_Y1+8);
                    billboard.turnOn(START_X1, START_Y1+9);
                    billboard.turnOn(START_X1, START_Y1+10);
                    billboard.turnOn(START_X1, START_Y1+11);
                    billboard.turnOn(START_X1+1, START_Y1+8);
                    billboard.turnOn(START_X1+2, START_Y1+8);
                    billboard.turnOn(START_X1+3, START_Y1+8);
                    billboard.turnOn(START_X1+4, START_Y1+3);
                    billboard.turnOn(START_X1+4, START_Y1+4);
                    billboard.turnOn(START_X1+4, START_Y1+5);
                    billboard.turnOn(START_X1+4, START_Y1+6);
                    billboard.turnOn(START_X1+4, START_Y1+7);
                    
                    break;
                    
                    final int START_X2 = 14;
                    final int START_Y2 = 1;
                    
                    case 'a':
                    billboard.turnOn(START_X2, START_Y2+3);
                    billboard.turnOn(START_X2, START_Y2+4);
                    billboard.turnOn(START_X2, START_Y2+5);
                    billboard.turnOn(START_X2, START_Y2+6);
                    billboard.turnOn(START_X2, START_Y2+7);
                    billboard.turnOn(START_X2+1, START_Y2+2);
                    billboard.turnOn(START_X2+1, START_Y2+8);
                    billboard.turnOn(START_X2+2, START_Y2+2);
                    billboard.turnOn(START_X2+2, START_Y2+8);
                    billboard.turnOn(START_X2+3, START_Y2+2);
                    billboard.turnOn(START_X2+3, START_Y2+3);
                    billboard.turnOn(START_X2+3, START_Y2+4);
                    billboard.turnOn(START_X2+3, START_Y2+5);
                    billboard.turnOn(START_X2+3, START_Y2+6);
                    billboard.turnOn(START_X2+3, START_Y2+7);
                    billboard.turnOn(START_X2+4, START_Y2+8);
                    
                    break;
             
                     final int START_X3 = 20;
                     final int START_Y3 = 1;
                    
                    case 'r':
                    billboard.turnOn(START_X3, START_Y3+2);
                    billboard.turnOn(START_X3+1, START_Y3+3);
                    billboard.turnOn(START_X3+1, START_Y3+4);
                    billboard.turnOn(START_X3+1, START_Y3+5);
                    billboard.turnOn(START_X3+1, START_Y3+6);
                    billboard.turnOn(START_X3+1, START_Y3+7);
                    billboard.turnOn(START_X3+1, START_Y3+8);
                    billboard.turnOn(START_X3+2, START_Y2+2);
                    billboard.turnOn(START_X3+3, START_Y2+2);
                    billboard.turnOn(START_X3+4, START_Y2+3);
                    
                    break;
                    
                    final int START_X4 = 26;
                    final int START_Y4 = 1;
                    
                    case 'e':
                     billboard.turnOn(START_X4, START_Y4+3);
                     billboard.turnOn(START_X4, START_Y4+4);
                     billboard.turnOn(START_X4, START_Y4+5);
                     billboard.turnOn(START_X4, START_Y4+6);
                     billboard.turnOn(START_X4, START_Y4+7);
                     billboard.turnOn(START_X4+1, START_Y4+2);
                     billboard.turnOn(START_X4+1, START_Y4+5);
                     billboard.turnOn(START_X4+1, START_Y4+8);
                     billboard.turnOn(START_X4+2, START_Y4+2);
                     billboard.turnOn(START_X4+2, START_Y4+5);
                     billboard.turnOn(START_X4+2, START_Y4+8);
                     billboard.turnOn(START_X4+3, START_Y4+2);
                     billboard.turnOn(START_X4+3, START_Y4+5);
                     billboard.turnOn(START_X4+3, START_Y4+8);
                     billboard.turnOn(START_X4+4, START_Y4+3);
                     billboard.turnOn(START_X4+4, START_Y4+4);
                     billboard.turnOn(START_X4+4, START_Y4+7);
                     
                     break;
                     
                    default:
                   
                  
                  
                  x += LETTER_WIDTH + GAP;
                  
                }
            // display the letter
        }
    }
}
}
 
0
 

You hadn't shown any proof that you had done anything. Were you assuming we'd just post the solution? Anyways, now that we have the code, we're one step closer.

What part of point 13 do you not understand? You haven't used charAt anywhere in your code. Make an attempt at what it asks you to do with the functions it gives you, and then show us what you've done and ask a question about it.

 
0
 

Yes, I do not even understand what charAt is. Normally charAt is followed be something inside a parentheses, is it a number? Or a letter?

And where do I put this charAt? Top part? In the loop? Before the loop? Sigh...this is really confusing...

 
0
 

charAt is a method in the String class. It is used to get a single character from a String.

 
0
 

Normally charAt is followed be something inside a parentheses, is it a number? Or a letter?

And where do I put this charAt? Top part? In the loop? Before the loop? Sigh...this is really confusing...

 
0
 

Use charAt where and when you need to see a character in a String.
Is there a decision you need to make based on which character is where?

 
0
 

wow im on the same problem mate ive done most of it but cant seem to make the word appear in the right order.

 
0
 
import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import javax.swing.JOptionPane;

/**
 * Partial solution for Stage 2 of the digital billboard
 *
 * @author phi
 * @version 2011 2
 */
public class style
{
    public static void main(String[] args)
    {
        // initial size of the display in pixels
        final int WINDOW_WIDTH = 300;
        final int WINDOW_HEIGHT = 120;
        // size of the grid for the digital billboard
        final int BB_WIDTH = 50;
        final int BB_HEIGHT = 30;

        // create a billboard
        BillboardInterface billboard = new DigitalBillboardFrame(
                "SCSS",
                WINDOW_WIDTH, WINDOW_HEIGHT,
                BB_WIDTH, BB_HEIGHT);

        // we will make letters 5 cells wide and 12 high
        final int LETTER_WIDTH = 5;
        final int LETTER_HEIGHT = 12;
        // and leave a 1 cell gap between letters
        final int GAP = 1;

        // the top left of the first letter in the word will be 2 cells from the left and 1 down
        final int START_X = 2;
        final int START_Y = 1;
        
        final boolean isJOptionPaneUsed = true; //for Scanner (0) or JOptionPane (1);
        
        String inputString;  // input string recved

        // Create a Scanner object for keyboard input.
       Scanner keyboard = new Scanner(System.in);

        // first make sure the display is blank
        billboard.allOff();
        
        // forever
        for(;;)
        {
            if (isJOptionPaneUsed)
            {
             
                  //get a message from the user
                  // Get user input  
                   inputString = JOptionPane.showInputDialog("Enter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");
                   
            }
            else
            {
                    keyboard = new Scanner(System.in);
                    System.out.println("\nEnter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");
                    String input = keyboard.nextLine();

            } 
            
                 //for each letter in the message
                int x = START_X; // keep track of where each letter should go
                int y = START_Y;
             for(int i = 0; i < 6  ; i++)
                {
                    // display the i_th letter
                 final int START_X1 = 8;
                 final int START_Y1 = 1; 
                 
                 final int START_X2 = 14;
                 final int START_Y2 = 1;
                 
                 final int START_X3 = 20;
                 final int START_Y3 = 1;
                 
                 final int START_X4 = 26;
                 final int START_Y4 = 1;
                 
                 
                    switch((inputString).charAt(0))
                    {
                    case 's':
                    billboard.turnOn(START_X+1, START_Y+2);
                    billboard.turnOn(START_X+2, START_Y+2);
                    billboard.turnOn(START_X+3, START_Y+2);
                    billboard.turnOn(START_X+4, START_Y+2);
                    billboard.turnOn(START_X, START_Y+3);
                    billboard.turnOn(START_X, START_Y+4);
                    billboard.turnOn(START_X+1, START_Y+5);
                    billboard.turnOn(START_X+2, START_Y+5);
                    billboard.turnOn(START_X+3, START_Y+5);
                    billboard.turnOn(START_X+4, START_Y+6);
                    billboard.turnOn(START_X+4, START_Y+7);
                    billboard.turnOn(START_X, START_Y+8);
                    billboard.turnOn(START_X+1, START_Y+8);
                    billboard.turnOn(START_X+2, START_Y+8);
                    billboard.turnOn(START_X+3, START_Y+8);
                    break;
                    
                    case 'p':
                    
                    billboard.turnOn(START_X1, START_Y1+2);
                    billboard.turnOn(START_X1+1, START_Y1+2);
                    billboard.turnOn(START_X1+2, START_Y1+2);
                    billboard.turnOn(START_X1+3, START_Y1+2);
                    billboard.turnOn(START_X1, START_Y1+3);
                    billboard.turnOn(START_X1, START_Y1+4);
                    billboard.turnOn(START_X1, START_Y1+5);
                    billboard.turnOn(START_X1, START_Y1+6);
                    billboard.turnOn(START_X1, START_Y1+7);
                    billboard.turnOn(START_X1, START_Y1+8);
                    billboard.turnOn(START_X1, START_Y1+9);
                    billboard.turnOn(START_X1, START_Y1+10);
                    billboard.turnOn(START_X1, START_Y1+11);
                    billboard.turnOn(START_X1+1, START_Y1+8);
                    billboard.turnOn(START_X1+2, START_Y1+8);
                    billboard.turnOn(START_X1+3, START_Y1+8);
                    billboard.turnOn(START_X1+4, START_Y1+3);
                    billboard.turnOn(START_X1+4, START_Y1+4);
                    billboard.turnOn(START_X1+4, START_Y1+5);
                    billboard.turnOn(START_X1+4, START_Y1+6);
                    billboard.turnOn(START_X1+4, START_Y1+7);
                    x += LETTER_WIDTH + GAP;
                    break;
                    
                    case 'a':
                    billboard.turnOn(START_X2, START_Y2+3);
                    billboard.turnOn(START_X2, START_Y2+4);
                    billboard.turnOn(START_X2, START_Y2+5);
                    billboard.turnOn(START_X2, START_Y2+6);
                    billboard.turnOn(START_X2, START_Y2+7);
                    billboard.turnOn(START_X2+1, START_Y2+2);
                    billboard.turnOn(START_X2+1, START_Y2+8);
                    billboard.turnOn(START_X2+2, START_Y2+2);
                    billboard.turnOn(START_X2+2, START_Y2+8);
                    billboard.turnOn(START_X2+3, START_Y2+2);
                    billboard.turnOn(START_X2+3, START_Y2+3);
                    billboard.turnOn(START_X2+3, START_Y2+4);
                    billboard.turnOn(START_X2+3, START_Y2+5);
                    billboard.turnOn(START_X2+3, START_Y2+6);
                    billboard.turnOn(START_X2+3, START_Y2+7);
                    billboard.turnOn(START_X2+4, START_Y2+8);
                    
                    break;
                   
                    case 'r':
                    billboard.turnOn(START_X3, START_Y3+2);
                    billboard.turnOn(START_X3+1, START_Y3+3);
                    billboard.turnOn(START_X3+1, START_Y3+4);
                    billboard.turnOn(START_X3+1, START_Y3+5);
                    billboard.turnOn(START_X3+1, START_Y3+6);
                    billboard.turnOn(START_X3+1, START_Y3+7);
                    billboard.turnOn(START_X3+1, START_Y3+8);
                    billboard.turnOn(START_X3+2, START_Y2+2);
                    billboard.turnOn(START_X3+3, START_Y2+2);
                    billboard.turnOn(START_X3+4, START_Y2+3);
                   
                    break;
                    
                    case 'e':
                     billboard.turnOn(START_X4, START_Y4+3);
                     billboard.turnOn(START_X4, START_Y4+4);
                     billboard.turnOn(START_X4, START_Y4+5);
                     billboard.turnOn(START_X4, START_Y4+6);
                     billboard.turnOn(START_X4, START_Y4+7);
                     billboard.turnOn(START_X4+1, START_Y4+2);
                     billboard.turnOn(START_X4+1, START_Y4+5);
                     billboard.turnOn(START_X4+1, START_Y4+8);
                     billboard.turnOn(START_X4+2, START_Y4+2);
                     billboard.turnOn(START_X4+2, START_Y4+5);
                     billboard.turnOn(START_X4+2, START_Y4+8);
                     billboard.turnOn(START_X4+3, START_Y4+2);
                     billboard.turnOn(START_X4+3, START_Y4+5);
                     billboard.turnOn(START_X4+3, START_Y4+8);
                     billboard.turnOn(START_X4+4, START_Y4+3);
                     billboard.turnOn(START_X4+4, START_Y4+4);
                     billboard.turnOn(START_X4+4, START_Y4+7);
                 
                    break;
                    
                    default:
                }
                  x += LETTER_WIDTH + GAP;
                  // display the letter
                
             
                
            }
                // OK - ready to update the display
                billboard.redisplay(0);
    }
}
}
 
0
 

everytime i try to run it. it only display the first letter of the word

 
0
 

Not too useful posting code to use for testing if there are missing packages: billboard

Can you post the console contents showing your input and the programs output?
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

 
0
 

eddieteddie, it sounds like you're not familiar with functions. If you're in school, I'm guessing you have a book. Review functions and specifically String functions if your book has them.

Instead of just guessing where to put something, think about what you are trying to do. The assignment starts with pseudocode and has you fill in parts slowly with blocks of code so you can understand logically you need to do.

You are storing the user input into the String userMsg. Point 12 explains that you need to use a for loop to display each letter in order. This means that each time through the loop, you should display one letter on the console.

First, figure out how to display a letter on the console. Next, figure out how to use charAt to retrieve one letter from a string. Finally, put those concepts together, and have the code in the loop print the i_th letter in the String.

Hopefully that helps. Try something and post your results.

 
0
 

Bob1000, on line 87, you're getting the 1st character of the string (index 0) every time, not the i_th character:

(inputString).charAt(0)
 
0
 

i see . but what is the i_th character? i figured it would be a number?

@ Norm ill try post the other packages xD

 
0
 

not sure how to post the outputs. but when i run the program the question box pops up and asks me "Enter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ " and it will keep asking me. however when i enter a word "spear" for example only the S would display on the billboard, or when i spell "pears" only P would display and they would display in the same spot the S P would appear if i wrote SPARE.

 
0
 

The "i_th character" is a phrase to mean a character at position i in a string. Instead of giving it a number like the 4th character, you make it more general. If you use a loop to print out a string, you can do it one character at a time by having the loop go from i = 0 to i = strlen(your_string) and print your_string each iteration.

 
0
 

If you want to post the output, you can take a screenshot and post it.

Did you see my earlier post about line 87 of your code?

 
0
 

i changed the charAt(0) to (i) seems to work better. and now it displays SPARE but if i try makes another word seems like my characters are hardlocked into those specific position. how do i change it for it to display in the correct location?

cheers

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article