Song Lyrics - Debt Consolidation - Debt Consolidation - Rome hotels - Health 2007

PDA

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


gder01
Feb 12th 2007, 1:06 am
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 :o

Thanks for the help.

nico_swd
Feb 12th 2007, 1:24 am
Java is NOT Javascript.