






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various concepts in object-oriented programming, including composition and inheritance relationships, the stringtokenizer class, awt, abstract classes, and writing a class definition in java. It also includes good practices for writing a class definition and examples of using the graphics class to draw lines, shapes, and text.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Practice Test Name:_CIS121 vest______________________ Part 1 : Fill in the blank (1 point each) with the best word to complete the thought.
Part 2 : Discussion
5. When would you use the StringBuffer class as opposed to the String class and why? When given the choice between using a String object to represent a string versus a StringBuffer object to represent that string, always use a String object if indeed the object will not change; this improved performance. String objects are constant strings and StringBuffer objects are modifiable strings., Java distinguishes constant strings and modifiable strings for optimization purposes; in particular, Java can perform certain optimizations involving String objects (such as sharing one String object among multiple references) because it knows these objects will not change.
Part 3 : Programming Note: In the programming section of the real test, you should know how to set up a class definition, write main and instance methods, construct a class diagram, draw using the Graphics object, use the basic JOptionPane dialog boxes, and how to add JLabels, JTextFields, and JButtons to a JFrame object.
draw an orange square with a height of 40 pixels in the upper left hand side of the window, draw a filled circle with a diameter of 100 pixels in the center of the window, draw 10 evenly spaced red vertical lines in the lower half of the window. // Java core packages import java.awt.; import java.awt.event.; // Java extension packages import javax.swing.*; public class LinesRectsOvals extends JFrame { // set window's title bar String and dimensions public LinesRectsOvals() { super( "Practice Test Graphics Demo" ); setBackground(Color.blue); setSize( 400, 300 ); show(); } // display various lines, rectangles and ovals public void paint( Graphics g ) { // call superclass's paint method super.paint( g ); g.setColor( Color.orange ); g.drawRect( 35, 50, 40, 40 ); g.setColor( Color.magenta ); g.drawOval( 150, 100, 100, 100 ); g.setColor( Color.red ); for(int I = 200; I <= 300; I+=10) g.drawLine( 5, I, 350, I ); } // execute application public static void main( String args[] ) { LinesRectsOvals application = new LinesRectsOvals(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } } // end class LinesRectsOvals
Character isDigit isLetterOrDigit toUpperCase toLowerCase isUpperCase isLowerCase StringTokenizer nextToken countTokens moreTokens
Assume g is an object of the Graphics class. Write the statement(s) to do the following: a. Assign the color blue to g. b. Draw a rectangle at the top right corner of the window that is 50 pixels wide and 100 pixels high. c. Using g, write the String “CIS 121 Test 1” in Dialog font, in bold, italic style. d. Output the size of the font currently assigned to g. e. Output the size of the font currently assigned to g. KEY::Assume g is an object of the Graphics class. Write the statement(s) to do the following: a. Assign the color blue to g. g.setColor(Color.blue); b. Draw a rectangle at the top right corner of the window that is 50 pixels wide and 100 pixels high. g.drawRect(20,20,50,100); c. Using g, write the String “CIS 121 Test 1” in Dialog font, in bold, italic style, size 36 pixels. g.setFont(new Font(“Dialog”), Font.BOLD + Font.ITALIC, 36)); g.drawString(“CIS 121 Test 1”); d. Output the size of the font currently assigned to g. g.drawString(g.getFont().getSize()); e. Output the size of the font currently assigned to g. g.drawString(g.getFont().getName()); 11