Anyone for a small Java challenge?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr. Mercury

    Anyone for a small Java challenge?


    Greetings to all -

    Someone suggested that Java might be the answer for a little
    conversion program I need. It's pretty simple, really. Just take a
    column of numbers:

    139
    259
    433
    637
    799
    1053
    1185

    and multiply them all by the same number, and spit out a new column.
    I'm multipilying by "29.97" in this case. I'm trying to convert a
    column of video times to frames.

    That would end up looking like:

    4165.83
    7762.23
    12977.01
    (etc)

    although I'd like the decimal dropped, so it ends up looking like:

    4165
    7762
    12977
    (etc)

    Can anyone help me out?

    Thanks much,
    Dr. Merc


  • Hugh Bothwell

    #2
    Re: Anyone for a small Java challenge?

    > Someone suggested that Java might be the answer for a little[color=blue]
    > conversion program I need. It's pretty simple, really. Just take a
    > column of numbers:
    >
    > 139
    > 259
    > 433
    > 637
    > 799
    > 1053
    > 1185
    >
    > and multiply them all by the same number, and spit out a new column.
    > I'm multipilying by "29.97" in this case. I'm trying to convert a
    > column of video times to frames.
    >
    > That would end up looking like:
    >
    > 4165.83
    > 7762.23
    > 12977.01
    > (etc)
    >
    > although I'd like the decimal dropped, so it ends up looking like:
    >
    > 4165
    > 7762
    > 12977
    > (etc)[/color]


    Sounds like a job for Excel...

    how often do you plan to do this?
    Where do you get the column of numbers, and how
    do you use them? In what way would writing a
    program be easier than using a calculator?


    For starts, see below - this is about
    as simple as it gets:


    import java.io.*;
    import java.lang.Math;
    import java.lang.Doubl e;

    public class Convertor {
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamRead er( System.in ) );

    public static void main(String[] args) {
    double d;
    System.out.prin tln("Enter your list of values:");

    while (true) {
    d = Double.parseDou ble(stdin.readL ine());
    System.out.prin tln( Math.floor( d * 29.97) );
    }
    }
    }


    Comment

    • Dr. Mercury

      #3
      Re: Anyone for a small Java challenge?

      On Fri, 20 Feb 2004 01:41:43 -0500, "Hugh Bothwell" wrote:

      <sniplet>
      [color=blue][color=green]
      >> although I'd like the decimal dropped, so it ends up looking like:
      >>
      >> 4165
      >> 7762
      >> 12977
      >> (etc)[/color]
      >[/color]
      [color=blue]
      >Sounds like a job for Excel...[/color]

      Howdy, Hugh, thanks for the reply.

      It works fine in Excel, but I need this as part of a video procedure
      on my Web site, so it should be something freeware.
      [color=blue]
      >how often do you plan to do this?
      >Where do you get the column of numbers, and how
      >do you use them? In what way would writing a
      >program be easier than using a calculator?[/color]

      It's a matter of retaining the chapter points in an SVCD when
      converting to another format. The chapter points can be extracted as
      times, but the conversion program wants them as frames. Ergo, I need
      to be able to multiply a column of numbers by either 23.976 or 29.97
      (frame rate of the movie depending) to convert the times to frames. A
      calculator would work, certainly, but it'd be a tad laborious for 20
      or so entries.
      [color=blue]
      >For starts, see below - this is about
      >as simple as it gets:[/color]

      Note the small font mismatch below:
      [color=blue]
      > public static void main(String[] args) {[/color]

      If you could fix that, and let me know how to use the script, it'd be
      appreciated. I honestly don't know anything about Javascripts except
      that occasionally I use a chunk of them in my Web pages, like to
      pre-load dynamic icons. I don't have any idea how to run an
      independent script like this one.

      Thanks for the help,
      Doc

      --

      For all of your DVD/SVCD/DIVX/OGM needs: www.svcd.cc
      New to DVD recording? www.svcd.cc/dvdrinfo.htm

      VCD FAQ: http://abvcd.home.comcast.net/FAQ/abvcdfaq5.01.htm
      SVCD Charter: www.svcd.cc/charter.htm

      Comment

      • nos

        #4
        Re: Anyone for a small Java challenge?

        awk '{print int($1 * 29.97);}' < numbers.txt


        "Dr. Mercury" <wh@ts.up.doc > wrote in message
        news:67aa30d4rl j27focifjvco22o 5j5u24mso@4ax.c om...[color=blue]
        >
        > Greetings to all -
        >
        > Someone suggested that Java might be the answer for a little
        > conversion program I need. It's pretty simple, really. Just take a
        > column of numbers:
        >
        > 139
        > 259
        > 433
        > 637
        > 799
        > 1053
        > 1185
        >
        > and multiply them all by the same number, and spit out a new column.
        > I'm multipilying by "29.97" in this case. I'm trying to convert a
        > column of video times to frames.
        >
        > That would end up looking like:
        >
        > 4165.83
        > 7762.23
        > 12977.01
        > (etc)
        >
        > although I'd like the decimal dropped, so it ends up looking like:
        >
        > 4165
        > 7762
        > 12977
        > (etc)
        >
        > Can anyone help me out?
        >
        > Thanks much,
        > Dr. Merc
        >
        >[/color]


        Comment

        • Ryan Stewart

          #5
          Re: Anyone for a small Java challenge?

          "Dr. Mercury" <wh@ts.up.doc > wrote in message
          news:appc30hc22 3nrh1c85ufgpmpv ha5efkeja@4ax.c om...[color=blue]
          > On Fri, 20 Feb 2004 01:41:43 -0500, "Hugh Bothwell" wrote:
          >
          > <sniplet>
          >[color=green][color=darkred]
          > >> although I'd like the decimal dropped, so it ends up looking like:
          > >>
          > >> 4165
          > >> 7762
          > >> 12977
          > >> (etc)[/color]
          > >[/color]
          >[color=green]
          > >Sounds like a job for Excel...[/color]
          >
          > Howdy, Hugh, thanks for the reply.
          >
          > It works fine in Excel, but I need this as part of a video procedure
          > on my Web site, so it should be something freeware.
          >[color=green]
          > >how often do you plan to do this?
          > >Where do you get the column of numbers, and how
          > >do you use them? In what way would writing a
          > >program be easier than using a calculator?[/color]
          >
          > It's a matter of retaining the chapter points in an SVCD when
          > converting to another format. The chapter points can be extracted as
          > times, but the conversion program wants them as frames. Ergo, I need
          > to be able to multiply a column of numbers by either 23.976 or 29.97
          > (frame rate of the movie depending) to convert the times to frames. A
          > calculator would work, certainly, but it'd be a tad laborious for 20
          > or so entries.
          >[color=green]
          > >For starts, see below - this is about
          > >as simple as it gets:[/color]
          >
          > Note the small font mismatch below:
          >[color=green]
          > > public static void main(String[] args) {[/color]
          >
          > If you could fix that, and let me know how to use the script, it'd be
          > appreciated. I honestly don't know anything about Javascripts except
          > that occasionally I use a chunk of them in my Web pages, like to
          > pre-load dynamic icons. I don't have any idea how to run an
          > independent script like this one.
          >
          > Thanks for the help,
          > Doc
          >[/color]
          That's Java. It's what you asked for. It's not javascript or "a script" at
          all. It's a Java program. See the Java Tutorial:
          java programming, learn java, java examples, java sample code, getting started with java


          Specifically, pay attention to "Your First Cup of Java".


          Comment

          • Aaron

            #6
            Re: Anyone for a small Java challenge?

            "Hugh Bothwell" <hugh_bothwell@ hotmail.com> wrote in message news:<qVhZb.394 53$986.16131@nn tp-post.primus.ca> ...[color=blue][color=green]
            > > Someone suggested that Java might be the answer for a little
            > > conversion program I need. It's pretty simple, really. Just take a
            > > column of numbers:
            > >
            > > 139
            > > 259
            > > 433
            > > 637
            > > 799
            > > 1053
            > > 1185
            > >
            > > and multiply them all by the same number, and spit out a new column.
            > > I'm multipilying by "29.97" in this case. I'm trying to convert a
            > > column of video times to frames.
            > >
            > > That would end up looking like:
            > >
            > > 4165.83
            > > 7762.23
            > > 12977.01
            > > (etc)
            > >
            > > although I'd like the decimal dropped, so it ends up looking like:
            > >
            > > 4165
            > > 7762
            > > 12977
            > > (etc)[/color]
            >
            >
            > Sounds like a job for Excel...
            >
            > how often do you plan to do this?
            > Where do you get the column of numbers, and how
            > do you use them? In what way would writing a
            > program be easier than using a calculator?
            >
            >
            > For starts, see below - this is about
            > as simple as it gets:
            >
            >
            > import java.io.*;
            > import java.lang.Math;
            > import java.lang.Doubl e;
            >
            > public class Convertor {
            > private static BufferedReader stdin =
            > new BufferedReader( new InputStreamRead er( System.in ) );
            >
            > public static void main(String[] args) {
            > double d;
            > System.out.prin tln("Enter your list of values:");
            >
            > while (true) {
            > d = Double.parseDou ble(stdin.readL ine());
            > System.out.prin tln( Math.floor( d * 29.97) );
            > }
            > }
            > }[/color]

            Are you going to have a text file to input these numbers, and then
            output them in another text file?

            I could write that, just let me know.

            Aaron

            Comment

            • Dr. Mercury

              #7
              Re: Anyone for a small Java challenge?

              On 20 Feb 2004 18:01:57 -0800, aaron.axvig@sen dit.nodak.edu (Aaron)
              wrote:

              <sniplet>
              [color=blue]
              >Are you going to have a text file to input these numbers, and then
              >output them in another text file?
              >
              >I could write that, just let me know.[/color]

              Yep, that's the idea. "chapters.t xt" would be converted to
              "chapters2.txt" . Any help with this, and how to run it, would
              certainly be appreciated.

              Doc

              Comment

              • SPC

                #8
                Re: Anyone for a small Java challenge?

                something like this:

                Input numberes in a File1
                -Open File1
                - Input numbers.
                -Close File1
                And
                -Open File2
                - Open File1
                - Copy File1 into File2
                - Close File1
                -Close File2

                Sorry, if I misunderstand.
                S.P.C

                Code:
                package Chapters;

                import java.io.*;

                public class Chapter {

                private static String sLine;
                private static PrintWriter FileCopy;
                private static BufferedReader stdin = new BufferedReader( new
                InputStreamRead er( System.in ) );

                public static void main (String[] args) throws IOException {

                Convert() ;
                File();

                }//fin Main

                private static void Convert() throws IOException {

                int n=3; //Take 3 inputs
                double d;
                System.out.prin t("Enter your list of values:");

                FileCopy = new PrintWriter(new FileOutputStrea m("Test.txt") );

                for (int i= 0; i < n ; i++ ){
                d = Double.parseDou ble(stdin.readL ine());
                d = (short)(d * 29.97); // 4165.83 --> 4165.0

                System.out.prin tln((int)d); //4165.0 --> 4165
                FileCopy.printl n((int)d);

                }
                FileCopy.close( ); //Close Write File : Copy.txt

                }//Fin Convert()

                private static void File() throws IOException {

                BufferedReader FileRead;

                FileCopy = new PrintWriter(new FileOutputStrea m("Copy.txt") );
                FileRead = new BufferedReader( new FileReader("Tes t.txt"));

                //Read file "Text.txt" and Copy it in "Copy.tx"t
                while ( (sLine = FileRead.readLi ne()) != null) {
                FileCopy.printl n(sLine);

                } //Fin while

                FileRead.close( ); //Close Read File : Test.txt
                FileCopy.close( ); //Close Write File : Copy.txt

                } // Fin File()

                }//Fin Class







                "Dr. Mercury" <wh@ts.up.doc > a écrit dans le message de
                news:lg9f30p781 qemseie7jrumicq vgn9espho@4ax.c om...[color=blue]
                > On 20 Feb 2004 18:01:57 -0800, aaron.axvig@sen dit.nodak.edu (Aaron)
                > wrote:
                >
                > <sniplet>
                >[color=green]
                > >Are you going to have a text file to input these numbers, and then
                > >output them in another text file?
                > >
                > >I could write that, just let me know.[/color]
                >
                > Yep, that's the idea. "chapters.t xt" would be converted to
                > "chapters2.txt" . Any help with this, and how to run it, would
                > certainly be appreciated.
                >
                > Doc
                >[/color]


                Comment

                • Dr. Mercury

                  #9
                  Re: Anyone for a small Java challenge?

                  On Sun, 22 Feb 2004 19:46:54 -0500, "SPC" <help@sayimposs ible.ca.tc>
                  wrote:
                  [color=blue]
                  >something like this:[/color]
                  [color=blue]
                  >Input numbers in a File1[/color]

                  <snip>

                  Thanks very much for the interesting script. Can you give me a brief
                  rundown on how to use it? I have the general idea, but I could use
                  some specifics.

                  Thanks much,
                  Doc

                  Comment

                  • SPC

                    #10
                    Re: Anyone for a small Java challenge?

                    Are you talking about" Input numbers" by ?? Math.random() ?? and multi
                    with 29.97 .
                    And you want the result in Integer (decimal dropped).
                    You see the example below,

                    SPC.


                    //*************
                    Ex:
                    int d ;

                    d = (int)( Math.random()*2 9.97 ); // (int) : (decimal dropped).
                    //this give you ONE number by Random, multi it with 29.97 and convert it in
                    Integer.

                    //**********
                    PS: Sorry, English is not my 1st lan.


                    "Dr. Mercury" <wh@ts.up.doc > a écrit dans le message de
                    news:nlak30h5a3 a436gbd139flr8r auod47uss@4ax.c om...[color=blue]
                    > On Sun, 22 Feb 2004 19:46:54 -0500, "SPC" <help@sayimposs ible.ca.tc>
                    > wrote:
                    >[color=green]
                    > >something like this:[/color]
                    >[color=green]
                    > >Input numbers in a File1[/color]
                    >
                    > <snip>
                    >
                    > Thanks very much for the interesting script. Can you give me a brief
                    > rundown on how to use it? I have the general idea, but I could use
                    > some specifics.
                    >
                    > Thanks much,
                    > Doc
                    >[/color]


                    Comment

                    • Dr. Mercury

                      #11
                      Re: Anyone for a small Java challenge?

                      On Mon, 23 Feb 2004 20:21:13 -0500, "SPC" <help@sayimposs ible.ca.tc>
                      wrote:
                      [color=blue]
                      >Are you talking about" Input numbers" by ?? Math.random() ?? and multi
                      >with 29.97 .
                      >And you want the result in Integer (decimal dropped).[/color]

                      Actually, the decimal doesn't have to be dropped. The program the
                      numbers go into is very 'sensitive' and I didn't want to confuse it
                      with decimals places, but it seems to just ignore them. So all I want
                      is something to multiply a list of numbers and produce a new list. If
                      you could write up a script and tell me how to use it, it would
                      certainly be appreciated.

                      Thanks,
                      Doc

                      Comment

                      Working...