Velocity Reviews > Java > mod calculation

# mod calculation

Guest
Posts: n/a

 11-13-2011
I'm working on a school project. Part of the requirement is to read in
the following data file

37259 9819
46363 22666
46161 79934
5693 31416
91459 8272
72792 9493
83603 8372
77842 64629
84792 747
1299 178

And then calculate anyNewArrival and serviceTime based on the
following formulas...

//read data1 and data2 from the file
anyNewArrival = (((data1%100)+1) <=50);
serviceTime = (data2%5)+1);

where data1 and data2 are read from the file

I get the following by calculating anyNewArrival

37259 ----> 60 false
46363 -----> 64 false
46161 -----> 62 false
5693 ------>94 false
91459 ----> 60 false
72792 ----->93 false
83603 ----->04 true
77842 ----->43 true
84792 ----->93 false
1299 178 ----> 1000 false

That means the only two arrivals should be

83603 ----->04 true
77842 ----->43 true

However, according to the output he gave us in the class, the number
of arrivals are 4. Ideas?

Roedy Green
Guest
Posts: n/a

 11-13-2011
On Sun, 13 Nov 2011 08:20:12 -0800 (PST), Chad <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>//read data1 and data2 from the file
>anyNewArrival = (((data1%100)+1) <=50);
>serviceTime = (data2%5)+1);

For the usual mod gotchas, see http://mindprod.com/jgloss/modulus.html

Most of the trouble comes when there are negative numbers involved.
You also might like to brush up on precedence.

http://mindprod.com/jgloss/precedence.html

The question I would ask myself is, "Which results do I agree with, my
prof's or my program's?". If "my program's", consider the
possibility you could have misunderstood the question, heard the prof
incorrectly or failed to take accurate notes during the class.

--
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.

Guest
Posts: n/a

 11-13-2011
On Nov 13, 9:02*am, Patricia Shanahan <(E-Mail Removed)> wrote:
> On 11/13/2011 8:20 AM, Chad wrote:
>
>
>
>
>
> > I'm working on a school project. Part of the requirement is to read in
> > the following data file

>
> > 37259 9819
> > 46363 22666
> > 46161 79934
> > 5693 31416
> > 91459 8272
> > 72792 9493
> > 83603 8372
> > 77842 64629
> > 84792 747
> > 1299 178

>
> > And then calculate anyNewArrival and serviceTime based on the
> > following formulas...

>
> > //read data1 and data2 from the file
> > anyNewArrival = (((data1%100)+1)<=50);
> > serviceTime = (data2%5)+1);

>
> > where data1 and data2 are read from the file

>
> > I get the following by calculating anyNewArrival

>
> > 37259 ----> *60 false
> > 46363 -----> *64 false
> > 46161 -----> *62 false
> > 5693 ------>94 false
> > 91459 ----> *60 false
> > 72792 ----->93 false
> > 83603 ----->04 true
> > 77842 ----->43 true
> > 84792 ----->93 false
> > 1299 178 ----> *1000 false

>
> > That means the only two arrivals should be

>
> > 83603 ----->04 true
> > 77842 ----->43 true

>
> > However, according to the output he gave us in the class, the number
> > of arrivals are 4. Ideas?

>
> This is the sort of thing you really need to discuss with your
> instructor or TA. You may be misunderstanding something in the
> assignment, or have the wrong data file, or ...
>

the numbers are the same.

> There is something wrong with the last line of your output.
> ((data1%100)+1) is not 1000, regardless of the value of data1.
>
>

I was copying the results from the paper. that last line should be
100 false

Guest
Posts: n/a

 11-13-2011
On Nov 13, 8:56*am, Roedy Green <(E-Mail Removed)>
wrote:
> On Sun, 13 Nov 2011 08:20:12 -0800 (PST), Chad <(E-Mail Removed)>
> wrote, quoted or indirectly quoted someone who said :
>
> >//read data1 and data2 from the file
> >anyNewArrival = (((data1%100)+1) <=50);
> >serviceTime = (data2%5)+1);

>
> For the usual mod gotchas, seehttp://mindprod.com/jgloss/modulus.html
>
> Most of the trouble comes when there are negative numbers involved.
> You also might like to brush up on precedence.
>
> http://mindprod.com/jgloss/precedence.html
>
> The question I would ask myself is, "Which results do I agree with, my
> prof's or my program's?". *If "my program's", *consider the
> possibility you could have misunderstood the question, heard the prof
> incorrectly or failed to take accurate notes during the class.
>

Would it help if I took a picture of the handouts and then post a url
with these images to this group?

Andreas Leitgeb
Guest
Posts: n/a

 11-13-2011
> On Nov 13, 9:02Â*am, Patricia Shanahan <(E-Mail Removed)> wrote:
>> On 11/13/2011 8:20 AM, Chad wrote:
>> > 37259 9819
>> > 46363 22666
>> > 46161 79934
>> > 5693 31416
>> > 91459 8272
>> > 72792 9493
>> > 83603 8372
>> > 77842 64629
>> > 84792 747
>> > 1299 178
>> > And then calculate anyNewArrival and serviceTime based on the
>> > following formulas...
>> > //read data1 and data2 from the file
>> > anyNewArrival = (((data1%100)+1)<=50);
>> > serviceTime = (data2%5)+1);

If you got your assignment on paper, have another close look on
the paper, whether the "50" could have been really "60". If that's
the case, that might explain it.

Guest
Posts: n/a

 11-13-2011
On Nov 13, 1:08*pm, Steve Sobol <(E-Mail Removed)> wrote:
> In article <3e57b4fa-fa05-42a5-af9f-fbeb93190590
>
> > Would it help if I took a picture of the handouts and then post a url
> > with these images to this group?

>
> Why are you asking us to do your homework for you?
>

Because I made a reasonable attempt at a solution? Besides, my
solution doesn't match the professor's.

Roedy Green
Guest
Posts: n/a

 11-14-2011
On Sun, 13 Nov 2011 09:09:23 -0800 (PST), Chad <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>the numbers are the same.

I repeat. You have to PARTITION the problem.

Is your program giving you wrong answers relative to what you expect
or are you in agreement the program and you both disagree with the
instructor? To answer that question you must manually solve the
problem using your understanding of what the question is.

If the latter, then nothing you do to the program will help (except
perhaps an evolutionary algorithm to see the profs results).

The problem is in your understanding of the problem. That has nothing
to do with the computer or the computer program. You will have to
solve it with social means, e.g. my asking fellow student, or the TA
how they interpreted the problem, or tell them what you thought and
wait for the irresistible urge to overtake them to correct you.

I know as I student I would have sooner cut off my arm than visit a
prof or TA to ask a favour, so try a fellow student.
--
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.

Gene Wirchenko
Guest
Posts: n/a

 11-15-2011
On Tue, 15 Nov 2011 13:05:32 -0800, Patricia Shanahan <(E-Mail Removed)>
wrote:

>On 11/14/2011 9:55 AM, Roedy Green wrote:
>...
>> I know as I student I would have sooner cut off my arm than visit a
>> prof or TA to ask a favour, so try a fellow student.

Why? Often, the fellow student does not know either.

>Answering course-relevant questions from students is not a favor (or
>favour) on the part of a professor or TA. It is part of their job.
>
>One odd effect I noticed when I was a TA was that often the students who
>were doing quite well on the course would ask questions, and the
>students who were in trouble would not.

I have seen this, too. I graduated at the top of my class. I
frequently spoke with my instructors.

>I don't know whether it was cause-and-effect, and if so in which
>direction. However, there is at least a possibility that willingness to
>ask the professor and/or TA causes good results.

It is also an opportunity to do something about it. Sometimes,
instructors make mistakes in assignments. Bringing something
suspicious to an instructor's attention may result in a correction to
the assignment.

>As a result, I strongly advise asking them questions, even for things
>that other people might be able to resolve.
>
>In this particular case, if there is a mismatch between the results the
>student thinks should be produced given the input, and the sample
>output, I don't see how anyone other than the professor or TA can
>resolve it reliably.

Quite.

Sincerely,

Gene Wirchenko

Roedy Green
Guest
Posts: n/a

 11-17-2011
On Tue, 15 Nov 2011 14:17:17 -0800, Gene Wirchenko <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

> Why? Often, the fellow student does not know either.

True, but if he has a mental block against visiting a TA as I did,
what else can he do? There is apparently something stopping him from

Children who have been abused, as I was, will take extreme measures to
avoid asking permission or approaching authority figures, even when
they know that logically the odds of something horrible happening as a
result are low.

Both those activities are dangerous for the child, and the child
hardwires in avoidance.
--
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.

Lew
Guest
Posts: n/a

 11-17-2011
On Thursday, November 17, 2011 7:23:41 AM UTC-8, Roedy Green wrote:
> On Tue, 15 Nov 2011 14:17:17 -0800, Gene Wirchenko <(E-Mail Removed)>
> wrote, quoted or indirectly quoted someone who said :
>
> > Why? Often, the fellow student does not know either.

>
> True, but if he has a mental block against visiting a TA as I did,
> what else can he do? There is apparently something stopping him from
>
> Children who have been abused, as I was, will take extreme measures to
> avoid asking permission or approaching authority figures, even when
> they know that logically the odds of something horrible happening as a
> result are low.

The converse doesn't follow. Not everyone too foolish to ask the appropriate persons can claim it's because of a bad childhood. And not everyone whowas abused as a child hesitates to ask a T.A. for help with a school assignment.

Rationality is a hallmark of engineering behavior. Sometimes the rational act is to go to a person with the answers and ask your question. If you can't stand the heat, get out of the kitchen.

> Both those activities are dangerous for the child, and the child
> hardwires in avoidance.

If you want to succeed in life, you cannot live as a prisoner of your past.When a syndrome, obsession, addiction or phobia interferes with your ability to function, get professional help. The good news is that you can achieve satisfaction and happiness even with such handicaps.

I care, Roedy.

--
Lew