Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: I want to make a sample program!

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want to make a sample program!

    i want to make a program this should be the output!

    Enter Students names:
    Enter a number, how many are there in your family:
    2
    You entered: 2 in you family members
    name 1: age:
    name 2: age:


    then if you want to enter another student we have a question (yes/no) then if it is yes it will repeat form the student names up to the questions.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Do you have any specific questions about the program you want to make?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    okay this is I want to do.

    Create a java program that would
    (1) use arrays and looping;
    (a)Enter the name of the student;
    (b)Enter the name of each family member(s);
    (c)Enter the age of each family member(s);
    (d) when through or done with one student date, Enter a sentinel value to end the loop;
    (e)Output: Name of student and No. of family members;
    (f)Make an option: Do you want to enter another student`s Date [ Y/N]
    (g)If yes, you must loop again from (A) to (F);

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Ok, what have you done so far and where are you having problems.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    this is the program that I`ve done so far after that I dont know what`s next :/ what should be the next? I`m not familiar in java

    import java.util.*;
    class Array
    {
    public static void main(String[] args)
    {

    Scanner input=new Scanner(System.in);



    System.out.println("Enter Students names: ");
    String Studentnames[]=new String[1];


    for(int i=0;i<Studentnames.length;i++){
    Studentnames[i]=input.next();
    }


    System.out.println("Enter a number, how many are there in your family: ");
    int [] num=new int[1];



    for(int i=0;i<num.length;i++){
    num[i]=input.nextInt();
    }














    }
    }

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: I want to make a sample program!

    Quote Originally Posted by hirohashimoto View Post
    ... I dont know what`s next :/ what should be the next? I`m not familiar in java
    Consider getting more familiar with Java. There are decent tutorials to be found here: The Really Big Index

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    what should be the next?
    You made a list of steps the code should do in post#3
    Which of the steps are now done?
    What is the next step you need to do?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    sorry I`m beginner here java I just wanna make a program that will help me for the future activity so that I`m asking to help me to continue my program regarding to the question I gave :/

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    what should be the next?
    You made a list of steps the code should do in post#3
    Which of the steps are now done?
    What is the next step you need to do?
    Please ask a specific question about the problem you are having with the next step to be done.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    will you please provide me program so that I can study how do you do that program :/

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Sorry, we do not write code for students. We'll help you with your problems and make suggestions.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    okay thank you for your time :/
    I`ll study on my own

  13. #13
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default want to know whats wrong with my code. i want it to go back to the start enter name student but it wont work.

    import java.util.*;
    class Array
    {
    public static void main(String[] args)
    {

    Scanner input=new Scanner(System.in);



    System.out.println("Enter Students names: ");
    String Studentnames[]=new String[1];


    for(int i=0;i<Studentnames.length;i++){
    Studentnames[i]=input.next();
    }


    System.out.println("Enter number, How many are you in your family?");
    int num = input.nextInt();

    int array[] = new int[num];
    String name[] = new String[num];
    int age[] = new int[num];



    System.out.println("The number you entered is " + num + " as your family members.");

    for (int i = 0 ; i < array.length; i++ ) {

    System.out.print("Enter name: ");
    String Fname=input.next();
    System.out.print("Enter age: ");
    int Ages=input.nextInt();


    }

    //this is my problem
    do {

    System.out.println("Add more? (y/n)");
    if (stdin.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(stdin.next());
    } else {
    break;
    }
    } while (true);

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    };

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }











    }
    }

  14. #14
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    this is my code
    import java.util.*;
    class Array
    {
    public static void main(String[] args)
    {

    Scanner input=new Scanner(System.in);



    System.out.println("Enter Students names: ");
    String Studentnames[]=new String[1];


    for(int i=0;i<Studentnames.length;i++){
    Studentnames[i]=input.next();
    }


    System.out.println("Enter number, How many are you in your family?");
    int num = input.nextInt();

    int array[] = new int[num];
    String name[] = new String[num];
    int age[] = new int[num];



    System.out.println("The number you entered is " + num + " as your family members.");

    for (int i = 0 ; i < array.length; i++ ) {

    System.out.print("Enter name: ");
    String Fname=input.next();
    System.out.print("Enter age: ");
    int Ages=input.nextInt();


    }


    do {

    System.out.println("Add more? (y/n)");
    if (stdin.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(stdin.next());
    } else {
    break;
    }
    } while (true);

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }











    }
    }

    and it`s not working i want to go back from the Enter student after asking [y/n]
    this is the code that I think is wrong

    do {

    System.out.println("Add more? (y/n)");
    if (stdin.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(stdin.next());
    } else {
    break;
    }
    } while (true);

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }


    so what should it be? will you tip me some possible solution?

  15. #15
    Member
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: want to know whats wrong with my code. i want it to go back to the start enter name student but it wont work.

    Hi,
    I don,t know what you want exactly but i solve your problem on do while loop. The problem is you are used stdin.next() but you don't declare the scanner. So it displays issue and also you don't declare the list.that is also the problem. I attach the code below you create the code like this...


    //first you declare the list on globally like this...

     static ArrayList<String> list=new ArrayList<String>();

    //you create do while loop like this..

    do {
     
    System.out.println("Add more? (y/n)");
    Scanner input1=new Scanner(System.in);
    if (input1.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(input1.next());
    } else {
    break;
    }
    } while (true);
     
    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
     
     
    System.out.println("List is " + list);
     arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }

    I hope this will be help to you...
    Regards
    Android developer
    Trinay Technology Solutions
    http://www.trinaytech.com
    5705750475

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    it`s not working
    Please explain what "not working" means. There are many ways for a program to not work.


    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: want to know whats wrong with my code. i want it to go back to the start enter name student but it wont work.

    THANK YOU FOR THE ANSWER



    import java.util.*;
    class Array
    {
    public static void main(String[] args)
    {

    Scanner input=new Scanner(System.in);



    System.out.println("Enter Students names: ");
    String Studentnames[]=new String[1];


    for(int i=0;i<Studentnames.length;i++){
    Studentnames[i]=input.next();
    }


    System.out.println("Enter number, How many are you in your family?");
    int num = input.nextInt();

    int array[] = new int[num];
    String name[] = new String[num];
    int age[] = new int[num];



    System.out.println("The number you entered is " + num + " as your family members.");

    for (int i = 0 ; i < array.length; i++ ) {

    System.out.print("Enter name: ");
    String Fname=input.next();
    System.out.print("Enter age: ");
    int Ages=input.nextInt();


    }


    do {

    System.out.println("Add more? (y/n)");
    if (stdin.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(stdin.next());
    } else {
    break;
    }
    } while (true);

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }












    }
    }


    that is my code what I mean is what are the possible code to go back from the start "Enter student name: " IF I asked do you what to enter another student account[yes/no] if YES it will go back from the start then if No you will enter sentinental value.

    I think this is the wrong code for that

    do {

    System.out.println("Add more? (y/n)");
    if (stdin.next().startsWith("y")) {
    System.out.println("Enter : ");
    list.add(stdin.next());
    } else {
    break;
    }
    } while (true);

    System.out.println("List is " + list);
    String[] arr = list.toArray(new String[0]);
    System.out.println("Array is " + Arrays.toString(arr));
    }


    so what should I replace for that?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    Create a java program that would
    (1) use arrays and looping;
    (2)Instruction: [ When the program is run]
    (a)Enter the name of the student;
    (b)Enter the name of each family member(s);
    (c)Enter the age of each family member(s);
    (d) when through or done with one student date, Enter


    a sentinel value to end the loop;
    (e)Output: Name of student and No. of family members;
    (f)Make an option: Do you want to enter another student`s Date [ Y/N]
    (g)If yes, you must loop again from (A) to (F);

    the thing that I did so far a,b and c


        import java.util.*;
        class Array
        {
         public static void main(String[] args) 
        {   
     
            Scanner input=new Scanner(System.in);
     
     
     
            System.out.println("Enter Students names: ");
            String Studentnames[]=new String[1];
     
     
            for(int i=0;i<Studentnames.length;i++){
            Studentnames[i]=input.next();
            }
     
     
            System.out.println("Enter number, How many are you in your family?");
            int num = input.nextInt();
     
            int array[] = new int[num];
            String name[] = new String[num];
            int age[]   = new int[num];
     
     
     
            System.out.println("The number you entered is " + num + " as your family members.");
     
            for (int i = 0 ; i < array.length; i++ ) {
     
            System.out.print("Enter name: ");
            String Fname=input.next();
            System.out.print("Enter age: ");
            int Ages=input.nextInt();
            }
     
     
     
     
     
     
           }        
           }

    so I need to do (d) (e) (f) and (g)

    please help me!

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Enter a sentinel value to end the loop;
    That requests that the user enter a SPECIAL value that the program recognizes to tell the program to exit the loop.
    Use an if statement to test for the special value
    use a break statement to exit the loop

    Where is the loop that the above code is supposed to exit?

    A suggestion: Try making a smaller simpler program first.
    Make a loop that will execute forever: while(true)
    In the loop ask the user to enter a number , tell him 99 will exit the loop
    print the number the user entered
    test if the number is 99
    exit the loop with a break if the number is 99
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    I have here a sample loop but I dont know how to apply this on my code

     
    do {
     
                System.out.println("Add more? (y/n)");
                Scanner input1=new Scanner(System.in);
                if (input1.next().startsWith("y")) {
                System.out.println("Enter : ");
                list.add(input1.next());
                } else {
                break;
                }
                } while (true);
     
                System.out.println("List is " + list);
                String[] arr = list.toArray(new String[0]);
                System.out.println("Array is " + Arrays.toString(arr));
     
     
                System.out.println("List is " + list);
                arr = list.toArray(new String[0]);
                System.out.println("Array is " + Arrays.toString(arr));
                }

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    Put the code you want to be repeated inside the loop.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: I want to make a sample program!

    Hi hirohashimoto,

    I think you want you will get the student detail when you select the option "n"..

    Try this:

    code removed
    Last edited by copeg; March 19th, 2013 at 07:09 PM. Reason: removed spoonfed code
    Regards
    Android developer
    Trinay Technology Solutions
    http://www.trinaytech.com
    5705750475

  24. #24
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to make a sample program!

    how to stop looping? and how to declare sentinel value? :/

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I want to make a sample program!

    A suggestion: Try making a smaller simpler program first.
    Make a loop that will execute forever: while(true)
    In the loop ask the user to enter a number , tell him 99 will exit the loop
    print the number the user entered
    test if the number is 99
    exit the loop with a break if the number is 99

    how to declare sentinel value
    In the above suggestion, 99 would be the sentinel.
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Please can you help with my program? How to make it
    By heythisgreg in forum Java Theory & Questions
    Replies: 12
    Last Post: December 1st, 2012, 10:18 PM
  2. can anyone help me make this program
    By amin45 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 16th, 2012, 06:41 PM
  3. how do i make my program to do......
    By andys in forum Object Oriented Programming
    Replies: 6
    Last Post: November 29th, 2010, 07:44 AM
  4. how do i make my program to....
    By andys in forum Object Oriented Programming
    Replies: 2
    Last Post: November 26th, 2010, 10:31 AM
  5. how to make a program take time...
    By DLH112 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2010, 07:09 PM