Results 1 to 6 of 6
  1. #1
    roberteto is offline Member
    Join Date
    Jul 2015
    Posts
    1
    Rep Power
    0

    Exclamation URGENT: School Assignment Woes !

    Hi all, I'm currently stuck with an assignment which requires immediate attenton as I had to submit the follwing assignemnet in 2 days time.

    Just a brief run-through on the scenario:
    I'm required to write up a program, using only FOR loop, to track the different train types that went passec the train station. The different types of trains are shown below:
    Train types Train code
    Inter-city: 23
    Regional: 51
    Overnight: 72

    The user is required to enter five sets of train codes (as shown above) and will then should then count the number of train codes entered and display the statistics.

    Sample output
    Enter train type #1: 23
    Enter train type #2: 23
    Enter train type #3: 51
    Enter train type #4: 72
    Enter train type #5: 23

    Statistics:
    3 Inter-city trains
    1 Regional train
    1 Overnight train

    Here's the code that I write-up so far:

    import java.util.Scanner;
    public static void main(String[] args)
    {
    Scanner sc = new Scanner(System.in);
    int train1;
    int train2;
    int train3;
    int train4;
    int train5;

    System.out.print("Enter train type #1: ");
    train1 = sc.nextInt();
    sc.nextLine();

    System.out.print("Enter train type #2: ");
    train2 = sc.nextInt();
    sc.nextLine();

    System.out.print("Enter train type #3: ");
    train3 = sc.nextInt();
    sc.nextLine();

    System.out.print("Enter train type #4: ");
    train4 = sc.nextInt();
    sc.nextLine();

    System.out.print("Enter train type #5: ");
    train5 = sc.nextInt();
    sc.nextLine();

    int[] numArr = {23, 51, 72};
    for (int i = 0; i < numArr.length; i++ )
    {
    if(numArr[i] == 23)
    {
    numArr[i] = train1;
    numArr[i] = train2;
    numArr[i] = train3;
    numArr[i] = train4;
    numArr[i] = train5;

    System.out.println( numArr[i] +" Inter-city train");
    }

    else if (numArr[i] == 51)
    {
    numArr[i] = train1 +train2 + train3+ train4+ train5;
    System.out.println( numArr[i] +" Regional Train");
    }

    else if (numArr[i] == 72)
    {
    umArr[i] = train1 +train2 + train3+ train4+ train5;
    System.out.println( numArr[i] +" Overnight Train");
    }

    }

    A million thanks for those peepes out there helping out!! :)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: URGENT: School Assignment Woes !

    You need to do the following things:

    1. Make certain your posted code compiles.
    2. Place your code between code tags to provide formatting (see BB Code List - Java Programming Forum - Learn Java Programming)
    3. Explain the errors you are getting and what you expect the output to be.

    Now, here is a specific question. What do you really want to do here (since each train assignment squashes the previous one)?

    Java Code:
    if(numArr[i] == 23)  {    
        numArr[i] = train1;
        numArr[i] = train2;
        numArr[i] = train3;
        numArr[i] = train4;
        numArr[i] = train5;
     
        System.out.println( numArr[i] +"  Inter-city train");
    }
    Regards,
    Jim
    Last edited by jim829; 07-24-2015 at 09:04 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: URGENT: School Assignment Woes !

    Quote Originally Posted by roberteto View Post
    Hi all, I'm currently stuck with an assignment which requires immediate attenton as I had to submit the follwing assignemnet in 2 days time.
    So you didn't start working on your assignment early enough; to quote Jim829: "Poor planning on your part does not constitute an emergency on my part".

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    Xen
    Xen is offline Member
    Join Date
    Jan 2015
    Posts
    86
    Rep Power
    0

    Default Re: URGENT: School Assignment Woes !

    Quote Originally Posted by JosAH View Post
    So you didn't start working on your assignment early enough; to quote Jim829: "Poor planning on your part does not constitute an emergency on my part".

    Jos
    Heh, I like that. A school assigment doesn't seem like an emercency to me in any case. What's the big deal, where is the creative impetus, in finishing an assignment that a million other students have done before you. Where is the great Cause ;-).

    I must say I am flabbergasted by the amount of bad questions, that amount to "I don't know what I am doing and want someone else to get me out of the mess". Is that what you get when you learn it in school? It's like that friend of mine when I was like 12 that asked me "My program is so much spaghetti code that I can't find out how it works for me anymore. Can you clean it up for me?" Yeah, right. Weird people, silly people, stupid questions.

    Arguably it is worse here than on e.g. the WordPress forums, or much worse than the newsgroups in the past (e.g. comp.lang.java or something). I guess Java is still very much a chosen language for teaching programming courses, like it was in my day.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: URGENT: School Assignment Woes !

    Quote Originally Posted by Xen View Post
    Arguably it is worse here than on e.g. the WordPress forums, or much worse than the newsgroups in the past (e.g. comp.lang.java or something). I guess Java is still very much a chosen language for teaching programming courses, like it was in my day.
    With good reason as it is also an often used language.

    This kind of spiteful dogpiling is worse than a bad question. What Jos said is enough of a reality check, don't turn it into something nasty.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Xen
    Xen is offline Member
    Join Date
    Jan 2015
    Posts
    86
    Rep Power
    0

    Default Re: URGENT: School Assignment Woes !

    Spite. I'll think about that. Thank you, I don't mind getting reality checks either. (Ill will towards others? Throwing around petty insults?). I think I can recognise myself in that? First time anyone has really made some assessment that was on the mark (or to the point). Am I doing it again? :P.

Similar Threads

  1. new to java, school assignment
    By Limens in forum New To Java
    Replies: 3
    Last Post: 02-22-2012, 05:10 PM
  2. I need help with my school assignment, please
    By burnenator in forum New To Java
    Replies: 13
    Last Post: 11-21-2011, 04:54 AM
  3. Need help with school assignment
    By sljkbn in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 01:07 PM
  4. Help with noob school assignment
    By debo3381 in forum New To Java
    Replies: 3
    Last Post: 09-23-2009, 04:02 AM
  5. Please help... assignment for school
    By confused2000 in forum New To Java
    Replies: 3
    Last Post: 11-12-2007, 08:12 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
  •