• Java Array help
    4 replies, posted
Hi could someone explain how i could do this problem in an array? Jean and Joe are a rather untidy couple with a similar bogun taste in clothes. Their 2 children, Jane and James are also clothed in the style. Jean’s mother came to stay and was horrified at the untidy state of the house. She formed a pile of clothes for each of the 4 people in the house, but could only do so by looking at the size of each item. Unfortunately sometimes the size had been cut off or wasn’t readable, so these clothes she put in a separate pile. If the size is ‘M’ or ‘L’, then it is Joe’s. If the size is ‘S’ then it is James’. If it is 12 or greater then it is Jean’s. If it is smaller than 12 it is Jane’s. Jean’s mother makes frequent visits and has to go through this process every visit. Your task in this problem is to write a program that will assist her. Input consists of data for a number of visits by Jean's mother. The first line of each visit will consist of a whole number, N (0 < N <= 50), which is the total number of clothes found strewn round the house. Then follows N lines each representing the size of an item of clothing, or an ‘X’ if it is missing or unreadable. The sizes will either be a 2 digit number or a letter ‘S’, ‘M’ or ‘L’. Input is finished when the number of clothes strewn, N, is 0. Do not process this line. Output consists of one line for each visit. The line will contain five numbers, each separated by a space. The numbers represent the number of clothes belonging to Joe, Jean, Jane and James respectively in the current visit. The final number is the number of clothes unable to be assigned to anyone. If there are no clothes in a pile, the number 0 must be shown. Sample Input 8 M 12 X 14 10 L S S 0 Output for Sample Input 2 2 1 2 1 Explanation Joe has 2 (M and L) Jean has 2 (12 and 14) Jane has 1 (10) James has 2 (S and S) There is one unreadable (X)
that is so specific it looks like homework. Sorry though, looks like a complicated mess :V
yeah it is, but i dont really understand it so im looking for help
It looks like you'll need a pair of nested loops to process the file: one for each visit, and one for each clothes item within a visit. The outer loop just reads the number that says how many times the inner loop should run, and exits the loop if it's zero. The inner loop reads however many lines the file said it should, counting the different types of clothes. The inner loop needs five counters to keep track of how many clothing items have been found belonging to each person (or nobody). That's the only place I see where an array would make sense, though you don't actually need one; five variables would work just fine.
That's a rather good homework question. I like it. Not that the programming is particularly interesting, but it tests your problem solving and interpretation. VERY important for programming. I'd suggest you really sit down, and work out what the problem is, print it out and get a red pen or a highlighter and highlight all the key words. Boil it down to just those and understand the problem. THEN you work out how to solve it. The problem itself is simple, and you'll get better at working these out as you go. Noone should be telling you how to solve it (Even though Wyzard seems to have).
Sorry, you need to Log In to post a reply to this thread.