Beginner Trying to get Started in Java: Need some help w/ simple Code

Discussion in 'JavaScript' started by gder01, Feb 12, 2007.

  1. #1
    Hi, I have some programs I'v been trying to create, as practice, but am having trouble. If anyone could point out some mistakes, I would be greatfull.

    1. constructs rectangle, and prints its circumference:

    import static java.lang.system.out;
    class PerimeterTester {

    Public static void main (Strings args[]){


    int Width;
    int Height;
    int Perimeter;


    Width = 4;
    Height = 3;
    Perimeter = 2*Width + 2*Height;

    System.out.print("Perimeter: ");
    System.out.println(Perimeter);
    System.out.println("Expected: 90");
    }
    }

    2. Creates 2 rectangles(r1,r2), and determines the rectangle(r3) caused by the intersection of the two rectangles. Prints them.

    import static java.lang.system.out;
    class PerimeterTester {

    Public static void main (Strings args[]){

    public r1(int x,int y,int width,int height)
    public r2(int x1,int y1,int width1,int height1)

    int x=;
    int y=;
    int width=;
    int height=;

    int x1=;
    int y1=;
    int width1=;
    int height1=;

    public r1 intersection(r2)


    Rectangle r3 = r1.intersection(r2);



    System.out.print("Rectangle 1: ");
    System.out.println(public r1);
    System.out.println("Rectangle 2:");
    System.out.println(public r2);
    System.out.println("Intersection:");
    System.out.println(Rectangle r3);
    }
    }

    3. Creates a random lottery number that consists of 6 values. (each value is a number between 1 and 49). Prints message, and the random number.


    import static java.lang.system.out;
    import java.util.Random;
    class LotteryPrinter {

    class Lottery {
    public static void main (Strings args[]){

    out.print(“Play this combination—it’ll make you rich!”);

    int randomNumber1 = new Random(49)
    out.println(randomNumber1)

    int randomNumber2 = new Random(49)
    out.println(randomNumber2)

    int randomNumber3 = new Random(49)
    out.println(randomNumber3)

    int randomNumber4 = new Random(49)
    out.println(randomNumber4)

    int randomNumber5 = new Random(49)
    out.println(randomNumber5)

    int randomNumber6 = new Random(49)
    out.println(randomNumber6)

    }
    }


    I have been reading Java 2 for dummies, as well as some stuff on the internet, and figured the best way to learn would be to work on some easy programs hands on. But it seeme I cant even do that :eek:

    Thanks for the help.
     
    gder01, Feb 12, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Java is NOT Javascript.
     
    nico_swd, Feb 12, 2007 IP