02_lewis_409167_labMan02

02_lewis_409167_labMan02 - Chapter 2: Data and Expressions...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 2: Data and Expressions 7 Chapter 2: Data and Expressions Lab Exercises Topics Lab Exercises Print and println String literals Names and Places String concatenation A Table of Student Grades Escape sequences Two Meanings of Plus Variables Prelab Exercises Constants Area and Circumference of a Circle Assignment Painting a Room Integers and Floating point Ideal Weight Arithmetic Expressions Lab Grades Operator Precedence Base Conversion Input using the Scanner class HTML Introduction to HTML Applets Drawing Shapes Graphics The Java Coordinate System Colors Drawing a Face Creating a Pie Chart Colors in Java 8 Chapter 2: Data and Expressions Names and Places The goal in this exercise is to develop a program that will print out a list of student names together with other information for each. The tab character (an escape sequence) is helpful in getting the list to line up nicely. A program with only two names is in the file Names.java . // *************************************************************** // Names.java // // Prints a list of student names with their hometowns // and intended major // *************************************************************** public class Names { // ------------------------ // main prints the list // ------------------------ public static void main (String args) { System.out.println (); System.out.println ("\tName\t\tHometown"); System.out.println ("\t====\t\t========"); System.out.println ("\tSally\t\tRoanoke"); System.out.println ("\tAlexander\tWashington"); System.out.println (); } } 1. Save Names.java to your directory. Compile and run it to see how it works. 2. Modify the program so that your name and hometown and the name and hometown of at least two classmates sitting near you in lab also are printed. Save, compile and run the program. Make sure the columns line up. 3. Modify the program to add a third column with the intended major of each person (assume Sally's major is Computer Science and Alexander's major is Math). Be sure to add a label at the top of the third column and be sure everything is lined up (use tab characters!). Chapter 2: Data and Expressions 9 A Table of Student Grades Write a Java program that prints a table with a list of at least 5 students together with their grades earned (lab points, bonus points, and the total) in the format below. ///////////////////\\\\\\\\\\\\\\\\\\\ == Student Points == \\\\\\\\\\\\\\\\\\\/////////////////// Name Lab Bonus Total ---- --- ----- ----- Joe 43 7 50 William 50 8 58 Mary Sue 39 10 49 The requirements for the program are as follows: 1. Print the border on the top as illustrated (using the slash and backslash characters). 2. Use tab characters to get your columns aligned and you must use the + operator both for addition and string concatenation....
View Full Document

Page1 / 27

02_lewis_409167_labMan02 - Chapter 2: Data and Expressions...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online