Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By unsensible

Thread: Need URGENT Help

  1. #1
    DoctorDelta is offline Member
    Join Date
    Aug 2014
    Posts
    5
    Rep Power
    0

    Exclamation Need URGENT Help

    Hi everyone, I'm starting school on Monday and I'll be taking AP Computer Science, a course that is java-programming based.

    I'm trying to finish up the summer work I was assigned, but I have no idea how to do it.

    SPECIFICATIONS

    I need to write some code that displays the following:

    *
    **
    ***
    ****
    *****

    However, I MUST use 2 loops in the program.
    I must also use the following statements one time each

    System.out.print(*); //usable only once
    System.out.println(); //usable only once


    Also, the loops must look similar to this (example given in the assignment):

    for(int x=0; x< 100; x++)
    {
    for(int y=0;y<100;y++)
    {
    }
    }
    NOTE: i AM NOT ASKING FOR HINTS, I AM ASKING FOR THE CODE THAT WILL SATISFY THIS ASSIGNMENT

    Once the school year starts, my schedule will be less hectic and I can focus on learning Java. For now, I need the answer.

    Thanks in advance,

    Doctor Delta

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    983
    Rep Power
    2

    Default Re: Need URGENT Help

    What are your expectations at this point? That someone will actually make this for you so *you* can look like a bad ass coder in school? Sorry, you came to the wrong place. Expect your first F in the first week.

    You will find hundreds of people on forums like these that will help you understand and fix every compile and runtime error imaginable. Show us what you got so far and we'll help you with your questions. Please include the question and/or error as well.

    Good luck.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    DoctorDelta is offline Member
    Join Date
    Aug 2014
    Posts
    5
    Rep Power
    0

    Default Re: Need URGENT Help

    I'm not doing this to look like a "bad ass coder."
    I've just been through the most hectic summer of my life (Eagle Scout project), and I need as much help as possible.
    Somehow, our teacher expects us to make this program with NO prior knowledge of Java, which is what he teaches in his class.
    I'd expect a problem like that to be assigned as homework after a lesson, but not assigned to someone who hasn't taken his class yet.

    I could do this in Visual Basic, but not in Java.

    Here's what I have so far.

    Java Code:
    public class SummerAssignmentProgram4
    { 
    public SummerAssignmentProgram4() 
    { 
    	for(int x=1; x< 6; x++) //gives the numbers 1 to 5
    	{ 
    	for(String y="*";;)
    		System.out.println(y);
    	} 
    } 
    public static void main(String args[]) 
    { 
    SummerAssignmentProgram4 app=new SummerAssignmentProgram4(); 
    } 
    }
    This is as far as I've gotten. It gives me an infinite loop of "*".
    I know what I have to do- I need to write code that uses a FOR loop to increase the value of integer X from 1 to 5. Then, for each value of X, print the corresponding number of asterisks, which is String Y.
    What I don't know is how to do this.

    I apologize if I gave the impression that I'm looking for an easy way out, I just haven't had any time to focus on this, and I will have time during the school year.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    983
    Rep Power
    2

    Default Re: Need URGENT Help

    The condition in line 7 does never become false. It will run forever. Look at the example pyramid. I see two loops there: one for the lines, and one for the characters. Inside the inner loop you should print a character. Once you finished the inner loop, the outer loop should print a new line.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    unsensible is offline Member
    Join Date
    Apr 2014
    Posts
    14
    Rep Power
    0

    Default Re: Need URGENT Help

    That's good, your first loop is fine. The second is what's giving you your infinite loop. For loops always take 3 parameters: Increment variable, condition, and how the increment variable is being incremented. You're actually closer than you think. When dealing with inner for the loops, the outer loop will not run until the inner loop increments it's designated number of times Here's what I mean:
    for(int i=0;i<2;i++)
    {
    for(int i=0;i<3;i++)
    {

    }//end inner
    }//end outer

    The inner loop will run 3 times to every 1 time the outer loop runs. So look at your program, you need to print a new line 5 times but you need to print a star (*) a total of 15 times. So the stars need to be in the inner loop, and the println needs to be in the outer.
    The tricky part of this is the condition of the second loop: for(int j=0;j < ?; j++); That's the only kinda tricky part. But you're definitely on the right track.

  6. #6
    DoctorDelta is offline Member
    Join Date
    Aug 2014
    Posts
    5
    Rep Power
    0

    Default Re: Need URGENT Help

    I'M AN IDIOT
    Need URGENT Help-im-idiot.gif
    I figured out the code by looking up a similar program (one that made a triangle instead of a half triangle)

    Here's my code now;
    Java Code:
    public class SummerAssignmentProgram4
    { 
    public SummerAssignmentProgram4() 
    { 
    	for (int x=0; x<6; x++)
    	  {
    	  for (int y=0; y<x; y++)
    	  {
    	  System.out.print("*");
    	  }
    	  System.out.println("");
    	  }
    }
    public static void main(String args[]) 
    { 
    SummerAssignmentProgram4 app=new SummerAssignmentProgram4(); 
    } 
    }
    This code works. Thanks for putting up with my stupidity. I'll definitely ask on here if I have any issues with this course throughout the year.

  7. #7
    unsensible is offline Member
    Join Date
    Apr 2014
    Posts
    14
    Rep Power
    0

    Default Re: Need URGENT Help

    Good work! Two little things that don't really matter but just so you know:
    1. System.out.println(); prints a line regardless of having quotes in it or not
    2. It's typically not a good idea to make the constructor have functionality like the above. It typically acts as a "setter" to set values in the object when instantiated, or just result in a default constructor. People might not want to create stuff by simply making an object, but instead by calling specific functions they want to use.
    TL;DR, it probably would've been a better idea to make that functionality a method instead of a constructor.

    However, it works and it does what the professor wanted. Good stuff!
    RohanChaubey likes this.

  8. #8
    DoctorDelta is offline Member
    Join Date
    Aug 2014
    Posts
    5
    Rep Power
    0

    Default Re: Need URGENT Help

    Thanks for the feedback.

    The System.out.println(""); was required to be in that format by the teacher.
    I'd take the "method instead of a constructor" advice into account if I knew what either of those meant.

    This work was summer work for a high school conceptual computer science class, so I don't know how much we'll really learn about Java itself.

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,079
    Rep Power
    6

    Default Re: Need URGENT Help

    Of course it is, it doesn't even compile if you mismatch quotes.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    DoctorDelta is offline Member
    Join Date
    Aug 2014
    Posts
    5
    Rep Power
    0

    Default Re: Need URGENT Help

    UPDATE FROM OP

    Just so you guys know, I had my first day of AP Computer Science today. Turns out, the teacher only assigned that program as summer work to see which students were willing to actively look for the solution rather than give up. He didn't expect us to be able to write the program on our own, considering that we had no prior experience with Java. He really just wanted to see if we could get Eclipse working correctly. We're not getting a grade for the program.

  11. #11
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    983
    Rep Power
    2

    Default Re: Need URGENT Help

    Thanks for the update. That's a sneaky thing your prof did there. But I must admit, it shows who cares and who doesn't.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 10:04 AM
  2. [very urgent]...
    By mharblez in forum Advanced Java
    Replies: 2
    Last Post: 02-18-2009, 03:15 PM
  3. I need Help Urgent..
    By vidhyaprakash85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-18-2009, 06:49 AM
  4. Urgent Help!!
    By Winniee in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 03:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •