System.out.println(3 + 4);
System.out.print("00");
System.out.println(3 + 4);
System.out.println("Hello, "World"!");
System.out.println("Hello, \"World\"!");
System.out.println("C:\\courses\\cs1063");
using a single statement:* ** ***
System.out.print("*\n**\n***\n");
use the statement:* ** ***
System.out.println("*\t**\t***");
public class DrawMain {
public static void main(String[] args) {
}
}
Add code to print this staircase:+----------+ | Bylander | +----------+
+---+
| |
+---+---+
| | |
+---+---+
Constructor:Methods:
- Rectangle(int x, int y, int width, int height)
This constructs a rectangle with given top left corner and size.
Parameters:
x,y - The upper left corner
width - The width
height - The height
- void setLocation(int x, int y)
This method moves this rectangle to a new location.
Parameters:
x,y - The new top left corner
- void setSize(int width, int height)
This method changes the size of this rectangle.
Parameters:
width - The new width
height - The new height
- void translate(int dx, int dy)
This method moves the rectangle.
Parameters:
dx - The distance to move along the x-axis (horizontal)
dy - The distance to move along the y-axis (vertical)
import java.awt.Rectangle;
public class RectangleMain {
public static void main(String[] args) {
}
}
Objects are entities in your program that you manipulate by invoking methods. To construct any object, you do the following:
Construct a Rectangle object with top left corner at (5,10), width 20, and height 30. Add the following line to your main and run the program. You should see java.awt.Rectangle[x=5,y=10,width=20,height=30]
System.out.println( new Rectangle(5, 10, 20, 30) ); System.out.println(); // Prints a blank line
Usually you want to do something more to an object than just create it, print it and forget it. To remember an object, you need to hold it in an object variable. A variable is an item of information in memory whose location is identified by a symbolic name. You can choose any variable names you like, provided you follow a few simple rules.
An object variable is a container that stores the location of an object. All object variables must be initialized before you access them. Construct a Rectangle object named room whose top left corner is at (10,20), width 30 and height 40. Add the following code to your program and run.
// Declare a variable named room
Rectangle room;
// Initialize room
room = new Rectangle(10,20,30,40);
// Print room and a double space
System.out.println("room = " + room + "\n");
This is a picture of what is happening in memory after the assignment statement is executed. Locate the object reference and the object.
Object Object
Variable Reference Object
+---------+ +----------------+
| | | Rectangle |
| room = ---------------> | |
| | | x = 10 |
+---------+ | y = 20 |
| width = 30 |
| height = 40 |
| |
+----------------+
Move the rectangle to coordinates (15,25). Add the code to your project and run.
Your program uses objects in the following way:
// Set x = 15 and y = 25 using the setLocation method
room.setLocation(15,25);
// Print room
System.out.println("room = " + room + "\n");
// Set width = 35 and height = 45 using the setSize method
room.setSize(35,45);
// Print room
System.out.println("room = " + room + "\n");
// Set coordinates to (30,40) using the translate method
room.translate(15,15);
// Print room
System.out.println("room = " + room + "\n");
All 10 quizzes will be available on Thursday, Friday, and Saturday of each week. (Always check your calendar.) That means you will have 3 days to complete the quiz. The first quiz will be taken together in class but from then on the student is responsible for taking the quiz on their own.
WebCt can be entered using the following link: http://webct.utsa.edu
Login to your account (from the WebCT FAQ)
Your WebCT ID (or user login name) is the last 8 digits of your Banner ID.
| UTSA ID Number | Banner ID | WebCT ID |
|---|---|---|
| 000087211 | @00087211 | 00087211 |
| 000693300 | @00693300 | 00693300 |
| 000097470 | @00097470 | 00097470 |
Your initial password is set to your birth date entered as MMDDYYYY where MM is the 2-digit month, DD is the 2-digit day of month, and YYYY is the 4-digit year.
For example, if your birth date is January 3, 1972, then your password is 01031972.
Note: If you had a WebCT account in a previous semester, your username and password have not changed. If you forgot your password or have other problems logging in, see the WebCT FAQ.