0% found this document useful (0 votes)
56 views

Exercise 2

1. A program that displays a 800x600 frame window titled "Welcome to Java". 2. A program that displays today's date in the format of "31 December 2020" using console output. 3. A program that accepts a string input, outputs the number of characters, first character, and last character on separate lines. For the input "I like Java", the output would be "11 I a". 4. A program that uses the Turtle class from the galapagos package to draw a triangle. The documentation should be reviewed to draw the square from the previous example in a different color and line thickness.

Uploaded by

colleeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Exercise 2

1. A program that displays a 800x600 frame window titled "Welcome to Java". 2. A program that displays today's date in the format of "31 December 2020" using console output. 3. A program that accepts a string input, outputs the number of characters, first character, and last character on separate lines. For the input "I like Java", the output would be "11 I a". 4. A program that uses the Turtle class from the galapagos package to draw a triangle. The documentation should be reviewed to draw the square from the previous example in a different color and line thickness.

Uploaded by

colleeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise 2.

1. Write a program that displays a frame window 800 pixels wide and 600
pixels high. Set the title of the frame to Welcome to Java.

2. Write a program to display today’s date in this format: 31 December 2020.


Use the console window for output.

3. Write a program that accepts a string input and outputs the number of
characters in the string and the first and last character in separate lines.
For 80 Chapter 2 Getting Started with Java example, if the input is I like
Java then the output would be 11 I a

4. At the McGraw-Hill book website, you will find a Java package called
galapagos. The galapagos package includes a Turtle class that is
modeled after Seymour Papert’s logo. This Turtle has a pen, and when
you move the Turtle, its pen will trace the movement. So by moving a
Turtle object, you can draw many different kinds of geometric shapes. For
example, this program commands a Turtle to draw a square:
import galapagos.*;
class Square {
public static void main( String[] arg ) {
Turtle turtle;
turtle = new Turtle( );
turtle.move( 50 ); //move 50 pixels
turtle.turn( 90 ); //turn 90 deg counterclockwise
turtle.move( 50 );
turtle.turn( 90 );
turtle.move( 50 );
turtle.turn( 90 );
turtle.move( 50 );
}
}
Write a program to draw a triangle. Read the documentation and see if you
can find a way to draw the square in a different color and line thickness.

5. Using the Turtle introduced in number 3, display the text Hello five times
at the approximate positions shown below:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy