0

I would like to make a subclass of FilterInputStream that will overload some of the methods of FilterInputStream. It will filter the input stream, which is a sequence of numbers given by the user (we don't know how long this sequence is) in which every number that is given consecutively will be written only once.

For example, given the input

1,2,3,3,3,4,5,5,6,7,10,10,15,16,16

the output should be

1,2,3,4,5,6,7,10,15,16

Can you tell me which classes should be overloaded and which not? I don't know if I need instance variables or just a constructor? I have to use ByteArryInputStream also--not Reader or Writer.

David Harkness
  • 35,992
  • 10
  • 112
  • 134
ZelelB
  • 1,836
  • 7
  • 45
  • 71
  • 1
    If you `I have to use ByteArryInputStream` that makes it sound like `[homework]` which should add as a tag. – Peter Lawrey Apr 10 '12 at 18:24
  • Are the input numbers always sorted as you show in your example? Are they in text format ('0'–'9') or binary? Using `ByteArrayInputStream` seems wrong; did you mean `FilterInputStream`? – erickson Apr 10 '12 at 18:39
  • They should be sorted as shown in the example.. but we have to use "ByteArrayInputStream" to read the entered sequence of numbers.. right? – ZelelB Apr 11 '12 at 10:34

1 Answers1

0

I would use a Scanner to read each number. However, if its homework you are likely to be expected to parse the numbers yourself.

You should start with the simplest program you can e.g. read some numbers and prints them out

When you have tested this works, make it more complicated by checking for consecutive numbers.

Can you tell me which classes should be overloaded and which not?

I would start by having a program which doesn't override anything or create any custom objects or define any new constructors. i.e. keep it as simple as possible.

When this works you can look at sub-classing FilterInputStream, but this is more complicated so unless you can get the simple example working, there is no point starting this.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130