Computer Science Canada

----Time---

Author:  xX_MayDay_Xx [ Mon Feb 13, 2006 9:00 am ]
Post subject:  ----Time---

yes and hello everyone...i am new to progamming and have come across something that bothers the hell out of me.

im trying to make a game were the user input's a time, in hours....(example-38.50=38 hours, and 30 mins)
but i cant get the code right to change the 38.50 into the time....i know the hours are given, and i don't really like math all that much so any help would be greatly aprrciated.

Author:  Andy [ Mon Feb 13, 2006 10:43 am ]
Post subject: 

sounds pretty much do-able to me.. post up the code you so far, and I'll see if i could be of any help Wink

Author:  MysticVegeta [ Mon Feb 13, 2006 2:46 pm ]
Post subject: 

1) Convert double into string
2) Check if the index of "." in the string >= 0, if it is split it else let the string stay the same.
3) Convert the first and second element of the splitArray into ints, multiply the second one by 60.

Note: Step 3 is if String.indexOf(".") >= 0;
otherwise just convert the string into int Smile

Author:  wtd [ Mon Feb 13, 2006 2:47 pm ]
Post subject: 

Convert the string to a float, then grab the decimal part and multiply by 60.

Author:  xX_MayDay_Xx [ Tue Feb 14, 2006 8:42 am ]
Post subject: 

public class Time
{
public static void main (String[]args)
{
double num, hours, min, sec;
System.out.println("Please enter a length of time");
System.out.println("Example '36.50= 36hours and 30minutes'");
num=In.getDouble();
}
}


--------------------------------------------------------------------------------------This is all i have, so far. Any help with it would be geatly apreciated....also, i have to write a progam that would take a letter, and then but the postion of the alphabit. (Example, A=1. B=2)

Author:  Andy [ Tue Feb 14, 2006 8:45 am ]
Post subject: 

well, all you have there is inputting the number, why dont you read what the nice people up there posted, and try to play around with it a bit before asking for help?

Author:  xX_MayDay_Xx [ Tue Feb 14, 2006 4:33 pm ]
Post subject: 

arrg....that envoles math.....i hate math,...with a passion...(Yes i know the irony, a computer coder who hates math)

and i have tried other things, but for some reason i cant get them to work properlly...i don't have them any more becuase i recently formatted my computer.

Author:  [Gandalf] [ Tue Feb 14, 2006 4:48 pm ]
Post subject: 

You don't know how to multiply?... wtd's solution shouldn't be a problem at all.

Author:  Andy [ Tue Feb 14, 2006 6:16 pm ]
Post subject: 

xX_MayDay_Xx wrote:
arrg....that envoles math.....i hate math,...with a passion...(Yes i know the irony, a computer coder who hates math)

and i have tried other things, but for some reason i cant get them to work properlly...i don't have them any more becuase i recently formatted my computer.


so basicly, let me get this straight... you're too lazy to do your own homework, fine, you ask for help, then you're too lazy to read the help people give you and wants one of us to do it for you? wth do you think u are

Author:  MysticVegeta [ Tue Feb 14, 2006 7:30 pm ]
Post subject: 

Wth? Converting decimal into minutes isnt that hard.. Shocked

Author:  Andy [ Tue Feb 14, 2006 8:56 pm ]
Post subject: 

its not hard.. he's just too lazy to think

Author:  xX_MayDay_Xx [ Wed Feb 15, 2006 8:08 am ]
Post subject: 

yes....i am lazy, and i like i said....i am very new to JAVA programming, turing i have no problem with....i don't even know what a float is.....don't you see my rank on this fourm...i belive it states "newbie" , so please stop giving me a hard time....i know im lazy, i know im a noob, but i learn by seeing, not figuring it all out by myself. and besides im a hardware guy....i don't like dealing with software.............

Author:  rizzix [ Wed Feb 15, 2006 12:36 pm ]
Post subject: 

That IS not his point! LOOK at the help your received! Don't expect us to give you the answer.

Author:  Andy [ Wed Feb 15, 2006 1:49 pm ]
Post subject: 

what makes you think that we're here to do your homework for you? the point of the forum is to provide people help with specific programming roadblocks, and help those who are helping you to get better through explaining. I dont see how doing your homework serves either purpose.

But, since you're an hardware guy, i guess we could get this arranged... tell me the number of different packets in the ATI's R600 PM4 stream, and i'll do this for you.

Author:  Andy [ Wed Feb 15, 2006 1:52 pm ]
Post subject: 

But, just so i dont sound like a total jerk.. a float is basicly a real number in turing, its not really, but since ur a hardware guy, you should know what flops is.

oh, and if you're master turing, post your turing solution to this problem, and we could help you translate that into java.

Author:  MysticVegeta [ Wed Feb 15, 2006 3:04 pm ]
Post subject: 

I smell flamage.

Anyways, didnt your teacher teach you what a float is before giving you an assignment in it?

Author:  xX_MayDay_Xx [ Thu Feb 16, 2006 8:06 am ]
Post subject: 

ok.....i cant post my turing example, because i don't have turing because if formatted. No the answer to your tech question varies, an i think you ment the MP4 stream......it can differ from system to system depending on how much current is ran through the device, but i could be entierly wrong becuase i don't like ATI or Radeon, also. could you give me an example of a float being used in code.....i learn by seeing, not having to think..it's been this way since i was 6...i couldn't sound out words in kindergaden, but if i was told the word...i would know it instantly.

Author:  xX_MayDay_Xx [ Thu Feb 16, 2006 8:08 am ]
Post subject: 

oh and to the teacher refence....im taking an idependent course...i don't have a teacher, i just get e-mails from a guy at another school qualified to teach it.

Author:  xX_MayDay_Xx [ Thu Feb 16, 2006 8:29 am ]
Post subject: 

ok....i have gotten, alot farther with my code, without using your precious "Float's"...however, i still don't know how to get the seconds, so plz....plz...PLZ help, with out any harassment.

code:

public class Time
{
        public static void main (String[]args)
        {
                final double PRECISION=1;
                double num, hours, min, sec;
                System.out.println("Please enter a length of time");
                System.out.println("Example '36.50= 36hours and 30minutes'");
                num=In.getDouble();
                hours = (int) (num);
                min = (num-hours)*60;
                hours= Math.abs(num/PRECISION)*PRECISION;
                System.out.println((int)hours+"hours");
                System.out.println((int)min+"minutes");

        }
}

Author:  Andy [ Thu Feb 16, 2006 9:03 am ]
Post subject: 

xX_MayDay_Xx wrote:
ok.....i cant post my turing example, because i don't have turing because if formatted. No the answer to your tech question varies, an i think you ment the MP4 stream......


No i meant PM4 stream, the commands parsed from the csq to the asic ring. For one, i didnt say it was a radeon. it's an R600 asic, and the asics dont use MP4 packets. if you were a "hardware" guy, you'd know that

anywho, since you actually made an effort, i guess i could help you out a bit.

you're working too hard with the PRECISION thing, make you hour, min, and sec integers, and you wont have any trouble. and as for your "seconds" problem, just do what you did with the hour and minutes again, and u're set

Author:  xX_MayDay_Xx [ Thu Feb 16, 2006 9:11 am ]
Post subject: 

allright thx, and it worked........
OK, i have done a lot of work on this next, question, i have the Mathimatical formula down....but for some reasonthe code dosen't work...
plz, help me again...im a newb.,,,al newb's need help.
i have to figure out the date of easter.
code:
public class Easter
{
        public static void main (String[]args)
        {
                int p,q,r,s,t,u,m,d,y;
                System.out.println("Welcome to the Easter Calculator");
                System.out.println("Enter which year you would like to find Easter on");
                y = In.getInt();
                p = (y/100);
                q = (y-19(y/19));
                r = ((p-17)/25);
                s = (p-(p/4)-((p-r)/3)+19q+15);
                s = (s-30(s/30));
                s = (s-(s/28)[1-(s/28)(29/(s+1))(21-q)/11]);
                t = (y+(y/4)+s+2-p+(p/a));
                t = (t-7(t/7);
                u = (s-t);
                m = (3+((u+44)/44);
                d = (u+28-31(m/4);
                System.out.println("The date of Easter will be"+d);
        }
}

Author:  Andy [ Thu Feb 16, 2006 10:35 am ]
Post subject: 

in java, you cant have (a)(b) and expect that to be mutiplication. you'll have to do (a)*(b).. and you never commented about the PM4 streams

Author:  xX_MayDay_Xx [ Thu Feb 16, 2006 5:56 pm ]
Post subject: 

allright...thx for the help....again...
and as for the PM4 Stream thing....im gunna be honest, i know a lot about tech...but not that much, i was taking a logical guess, considering that most stremed current's have a lot to do with the amount of power put through them.....so plz...plz....plz...stop picking on the noob

My comp rox;
Twisted Evil Twisted Evil Twisted Evil Twisted Evil
Foxconn, Socket 940 NVIDIA nForce Pro 2200 ATX AMD

BFG nividia 7800 gtx OC...512mb (Can't afford dual....yet)

AMD Athlon 64 FX60 Toledo 1GHz FSB 2 x 1MB L2 Cache Socket 939 Dual Core Processor

CORSAIR XMS 2GB (2 x 1GB) 184-Pin,Dual Channel

along with 3 disc's drives
watercooling and a kick ass case from cooler master...

i am a geek who spends all his money on his computer...i have had to put in at least 3-g into it

Author:  Andy [ Fri Feb 17, 2006 8:45 am ]
Post subject: 

all i see is a bunch of expensive parts.. what did you do go on tigerdirect and buy the most expensive component? that doesnt tell me you know what youre doing. just means you have money. For 1k less, you could've got a system slightly subpar to ur current one.. only slightly.

Author:  xX_MayDay_Xx [ Fri Feb 17, 2006 8:52 am ]
Post subject: 

i know i could of...but i buy all my parts at a local store, not of the net. and these were the best they had there...

and im having a problem out putting a char value, i need to assign a char a value and then display that char's value.
code:

public class Alphabit
{
        public static void main (String[]args)
        {
                char A=1;
                char B=2;
                char C=3;
                char D=4;
                char E=5;
                char F=6;
                char G=7;
                char H=8;
                char I=9;
                char J=10;
                char K=11;
                char L=12;
                char M=13;
                char N=14;
                char O=15;
                char P=16;
                char Q=17;
                char R=18;
                char S=19;
                char T=20;
                char U=21;
                char V=22;
                char W=23;
                char X=24;
                char Y=25;
                char Z=26;
                System.out.println("please input a Capitol Letter");
                In.getChar();
                System.out.println("wow...its working");
        }
}

Author:  Andy [ Fri Feb 17, 2006 9:59 am ]
Post subject: 

ok i have no idea what you're asking.. can u rephraise the question

Author:  xX_MayDay_Xx [ Fri Feb 17, 2006 2:17 pm ]
Post subject: 

assining a chracter a value and the calling up that value
example A=1......B=2
get it now?

Author:  Andy [ Fri Feb 17, 2006 2:48 pm ]
Post subject: 

oh.. take the character, subtract 'A' from it and add 1

Author:  xX_MayDay_Xx [ Mon Feb 27, 2006 8:41 am ]
Post subject: 

ok....i don't understand...you want me to subtract A from A and then add 1.....

Author:  Andy [ Mon Feb 27, 2006 10:17 am ]
Post subject: 

try it, output 'A'-'A'+1, then try 'B'-'A'+1 then try 'C'-'A'+1

Author:  xX_MayDay_Xx [ Tue Feb 28, 2006 8:08 am ]
Post subject: 

ok....well that does give me the value, but that dosnt solve my problem

im trying to get the user to input a capitol letter..

"Plz enter a capitol letter"

and then it gives the user the value of it

"You enter 'A'--the value of A=1"

but it most be able to do this for all numbers

"You entered 'Z'--the value of Z=26"

Author:  xX_MayDay_Xx [ Tue Feb 28, 2006 8:20 am ]
Post subject: 

like this is what i have so far and it wont work

code:
public class Alphabit
{
        public static void main (String[]args)
        {
                int A=('A'-'A'+1);
                int B=('B'-'A'+1);
                int C=('C'-'A'+1);
                int D=('D'-'A'+1);
                int E=('E'-'A'+1);
                int F=('F'-'A'+1);
                int G=('G'-'A'+1);
                int H=('H'-'A'+1);
                int I=('I'-'A'+1);
                int J=('J'-'A'+1);
                int K=('K'-'A'+1);
                int L=('L'-'A'+1);
                int M=('M'-'A'+1);
                int N=('N'-'A'+1);
                int O=('O'-'A'+1);
                int P=('P'-'A'+1);
                int Q=('Q'-'A'+1);
                int R=('R'-'A'+1);
                int S=('S'-'A'+1);
                int T=('T'-'A'+1);
                int U=('U'-'A'+1);
                int V=('V'-'A'+1);
                int W=('W'-'A'+1);
                int X=('X'-'A'+1);
                int Y=('Y'-'A'+1);
                int Z=('Z'-'A'+1);
                System.out.println("please input a Capitol Letter");
                B=In.getInt();
                System.out.println("wow...its working"+(B));
        }
}

Author:  Andy [ Tue Feb 28, 2006 8:43 am ]
Post subject: 

wow.. that is really really sad...

ask the user to input a character, and store it in a variable, then take that variable and subtract 'A' then add 1

Author:  xX_MayDay_Xx [ Tue Feb 28, 2006 9:14 am ]
Post subject: 

ok...well that didn't work as well...but this did



code:
public class Alpha
{
        public static void main (String[]args)
        {
                char letter;
                int value;

                System.out.println("Plz enter a capitol letter");
                letter=In.getChar();
                value = (int)(letter);
                System.out.println("the value of that letter is");
                System.out.println("the value of that letter is "+value - 64);
        }
}

Author:  Andy [ Tue Feb 28, 2006 9:33 am ]
Post subject: 

that's essentially what i told you to do.. 'A' == 65, so basicly by subtracting that and adding 1 you're subtracting 64.. w.e as long as you got it

Author:  xX_MayDay_Xx [ Thu Mar 02, 2006 8:24 am ]
Post subject: 

um ok...this program works for the most part, im just having trouble finalizing it, The math is correct, i tripled checked it on paper...but for some reason it just wont calculate properly...

code:

public class Easter
{
        public static void main (String[]args)
        {
                int p,q,r,s,t,u,m,d,y;
                System.out.println("Welcome to the Easter Calculator");
                System.out.println("Enter which year you would like "
                                                                                + "to find Easter on");
                y = In.getInt();
                p = (y/100);
                q = (y-19)*(y/19);
                r = ((p-17)/25);
                s = (p-(p/4))-((p-r)/3)+(19*q)+(15);
                s = (s-30)*(s/30);
                s = (s-(s/28))*(1-(s/28)*(29/(s+1))*((21-q)/11));
                t = (y+(y/4)+s+2-p+(p/4));
                t = (t-7)*(t/7);
                u = (s-t);
                m = 3+((u+40)/44);
                d = (u+28-31*(m/4));
                System.out.println("easter will be on");
            System.out.println("Month "+m);
                System.out.println("day "+d);
                System.out.println("in the year "+y);
        }
}

Author:  MysticVegeta [ Thu Mar 02, 2006 2:38 pm ]
Post subject: 

What the hell? I cant even understand a thing going on with that code. Messy var names, messy calcs.. but I do see one thing, when you are dividing something you are not casting it.

Anyways, why not just look for any years easter and then use loops to solve the problem. Ex: if you know that on day x easter falls, in 2006, and user enters 2007 or anything, just use loops..

Author:  xX_MayDay_Xx [ Fri Mar 03, 2006 8:17 am ]
Post subject: 

um....i know im not the best a programing...in fact i down right suck...but your method is completly messed up, if i used "If" statments and loop's..the code would be ten times as long as it is now...this has to be able to calulate easter in any year..from the year 200 to 567893043974987343987263498........yeah so pretty much your code would run forever...and second, i already fiqured out the problem, it was that i had to many brakets that screwed up 'BEDMAS'

Author:  MysticVegeta [ Fri Mar 03, 2006 3:42 pm ]
Post subject: 

I guarantee you, the code wont be 10 times longer, not even 2 times longer, a loop is made to "save" code length not increase it by 10X, I suggested loops because anyone looking at your code would simply go "What is this mess?" Whereas if you actually count the # of days and then mod(ulos) by 7, you will get after how many days / before how many days, will the year appear.

But if you want to stick to the confusing method, you should go right ahead. Because quite frankly if a teacher will look at this:

code:
      p = (y/100);
      q = (y-19)*(y/19);
      r = ((p-17)/25);
      s = (p-(p/4))-((p-r)/3)+(19*q)+(15);
      s = (s-30)*(s/30);
      s = (s-(s/28))*(1-(s/28)*(29/(s+1))*((21-q)/11));
      t = (y+(y/4)+s+2-p+(p/4));
      t = (t-7)*(t/7);
      u = (s-t);
      m = 3+((u+40)/44);


I am sure a mark of 0 for organization will be given.

Author:  [Gandalf] [ Sat Mar 04, 2006 9:05 am ]
Post subject: 

xX_MayDay_Xx wrote:
this has to be able to calulate easter in any year..from the year 200 to 567893043974987343987263498.

Then you'd better be changing your type from 'int' to something more appropriate. As it stands, you're limited to the year 2147483647. Good luck!


: