Students


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Students

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Students

    Hi,

    I am trying to write a program that prompts for a number of students in a class and the size of teams to be formed, and displays how many teams can be formed and how many students are left without a team.
    I have this so far, but am not really sure what to do next?

    public class Students2_4
    {
    public static void main(String[]args)
    {
    int class, teams;

    System.out.print("How many student in class")
    class = Easyin.getInt();
    System.out.print("How many teams to be formed")
    teams = EasyIn.getInt();

    Any suggestions would be helpful.

  2. #2
    Join Date
    Sep 2004
    Posts
    223
    i dont understand why you want this line:

    System.out.print("How many teams to be formed")
    teams = EasyIn.getInt();

    dont you want to ask the user what size the teams will be?

    I would have thought that the user enters in the number of people, then the size of the teams, then the application will spit out the appropriate info.
    Am i right in saying this?
    A kram a day keeps the doctor......guessing

  3. #3
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    Well
    at first i thought it was easy
    but it's really tricked me for while
    that's what got for you
    I'm not using the EasyIn method because i don't know what it stand for
    anyway this complil fine here



    import java.io.*;
    class Steam{
    public static BufferedReader input=
    new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] lalama)throws IOException{
    System.out.println("enter the Number students ");

    int snum=Integer.parseInt(input.readLine());
    int p=snum;

    System.out.println("enter the size of the team ");

    int steam=Integer.parseInt(input.readLine());
    int i=0;

    do{ snum/=steam;}while(snum>snum%steam);
    System.out.println("We can have "+snum%steam+" team but \n"+(p-steam*snum)+" students "
    +"would be in no team ");
    }
    }

  4. #4
    Join Date
    Dec 2004
    Posts
    46
    Kram

    Yes you are right in saying what you said.

  5. #5
    Join Date
    Sep 2004
    Posts
    223
    ok so ill give you some hints, some of these are covered by petert17's code. But here it goes:

    when you divide 2 ints together you will get the closest result without any decimals, ie.

    10/3 will give 3, and only 3, not 3.3333333etc...

    so this can be used to give the number of teams that will fit into the class.

    To get the leftovers, you need to use the mod (%) operator, this will give you the remainder after the division, ie.

    10 % 3 will give 1, so 1 left over...

    hope this hepls
    A kram a day keeps the doctor......guessing

  6. #6
    Join Date
    Dec 2004
    Posts
    46
    Thanks for hints i have now done it. Thanks.

  7. #7
    Join Date
    Dec 2004
    Posts
    46

    Student Teams

    Hi,

    I got this to work last time but
    i accidently deleted it and now
    I am having a bit of a problem with the code,

    public class Team
    {
    public static void main(String[]args)
    {
    int num,team;
    {
    System.out.println("enter the number of students ");
    num = EasyIn.getInt();
    System.out.println("enter the size of the team ");
    team = EasyIn.getInt();
    int p = num;
    do{ num/=team;}while(num>num%team);
    System.out.println("We can have "+num%team+" teams but \n"+(p-team*num)+" students "
    +"would be in no team ");
    }

    }
    }

    Its compiling ok but its not doing what I thought it would.
    something’s obviously missing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center