Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > mod calculation

Reply
Thread Tools

mod calculation

 
 
Chad
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?

Chad
 
Reply With Quote
 
 
 
 
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.

--
Roedy Green Canadian Mind Products
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.
 
Reply With Quote
 
 
 
 
Chad
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 ...
>


I thought I had the wrong data file, so I downloaded again. However,
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
 
Reply With Quote
 
Chad
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?
 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      11-13-2011
Chad <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
Chad
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
> @i4g2000prd.googlegroups.com>, Chad says...
>
> > 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.
 
Reply With Quote
 
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 :

>I thought I had the wrong data file, so I downloaded again. However,
>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.
--
Roedy Green Canadian Mind Products
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.
 
Reply With Quote
 
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
 
Reply With Quote
 
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
asking the TA.

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.
--
Roedy Green Canadian Mind Products
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet.
 
Reply With Quote
 
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
> asking the TA.
>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't `from pkg import mod' work after `del pkg.mod'? ryles Python 3 07-26-2009 04:13 PM
difference between import from mod.func() and x=mod.func() Hari Sekhon Python 0 06-20-2006 08:07 AM
How to: How NOT to Mod a Case! Silverstrand Reviews & How-To's 15 07-17-2005 02:26 AM
How to: Mod a PSU (Power Supply) Silverstrand Reviews & How-To's 17 07-06-2005 06:41 AM
append_features(mod) -- mod.kind_of? makes absolutely no sense T. Onoma Ruby 9 12-15-2003 03:34 AM



Advertisments