MAT 2170: Laboratory 3



Similar documents
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Chapter 2: Elements of Java

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Negative Integral Exponents. If x is nonzero, the reciprocal of x is written as 1 x. For example, the reciprocal of 23 is written as 2

APPLICATIONS AND MODELING WITH QUADRATIC EQUATIONS

Algebra 1: Basic Skills Packet Page 1 Name: Integers ( 30) ( 4)

MBA Jump Start Program

MAT116 Project 2 Chapters 8 & 9

ALGEBRA 2/TRIGONOMETRY

MATH 110 Landscape Horticulture Worksheet #4

Moving from CS 61A Scheme to CS 61B Java

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

7.2 Quadratic Equations

Chapter One Introduction to Programming

Free Pre-Algebra Lesson 55! page 1

ALGEBRA 2/TRIGONOMETRY

Calculating Area, Perimeter and Volume

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

COMPETENCY TEST SAMPLE TEST. A scientific, non-graphing calculator is required for this test. C = pd or. A = pr 2. A = 1 2 bh

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

Percent, Sales Tax, & Discounts

Perimeter, Area, and Volume

MTH 092 College Algebra Essex County College Division of Mathematics Sample Review Questions 1 Created January 17, 2006

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Section 7.1 Solving Right Triangles

YOU CAN COUNT ON NUMBER LINES

Postulate 17 The area of a square is the square of the length of a. Postulate 18 If two figures are congruent, then they have the same.

CP Lab 2: Writing programs for simple arithmetic problems

Perimeter is the length of the boundary of a two dimensional figure.

A. The answer as per this document is No, it cannot exist keeping all distances rational.

ALGEBRA I (Common Core) Wednesday, August 13, :30 to 11:30 a.m., only

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

MATHCOUNTS TOOLBOX Facts, Formulas and Tricks

Perimeter. 14ft. 5ft. 11ft.

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Introduction to Python

Solutions to Exercises, Section 5.1

Review of Scientific Notation and Significant Figures

SECTION P.5 Factoring Polynomials

GEOMETRIC SEQUENCES AND SERIES

FACTORING OUT COMMON FACTORS

Formulas STEM 11. Two mathematical formulas that students at this level of mathematics are familiar with are:

Law of Cosines. If the included angle is a right angle then the Law of Cosines is the same as the Pythagorean Theorem.

10.2 Series and Convergence

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions

History of U.S. Measurement

Student Involvement: Middle / Secondary Laboratory Safety Activities

Introduction to Java. CS 3: Computer Programming in Java

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION INTEGRATED ALGEBRA. Thursday, August 16, :30 to 11:30 a.m.

7.4A/7.4B STUDENT ACTIVITY #1

4. How many integers between 2004 and 4002 are perfect squares?

Logarithmic and Exponential Equations

Characteristics of the Four Main Geometrical Figures

Example of a Java program

Geometric Series and Annuities

of surface, , , of triangle, 548 Associative Property of addition, 12, 331 of multiplication, 18, 433

2nd Semester Geometry Final Exam Review

Circles: Circumference and Area Lesson Plans

Advanced GMAT Math Questions

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

Chapter 2 Factors: How Time and Interest Affect Money

Chapter 2 Elementary Programming

MAT12X Intermediate Algebra

16 21 Linear vs. Exponential.notebook May 14, LT 1c: I can compare linear vs. exponential change.

Interest Rates. Countrywide Building Society. Savings Growth Data Sheet. Gross (% per annum)

MATH REVIEW SHEETS BEGINNING ALGEBRA MATH 60

43 Perimeter and Area

5.1 FACTORING OUT COMMON FACTORS

Common Core Unit Summary Grades 6 to 8

Chapter 3. Input and output. 3.1 The System class

Area and Circumference

Computer Science 1 CSci 1100 Lecture 3 Python Functions

Rational Exponents. Squaring both sides of the equation yields. and to be consistent, we must have

How To Solve Factoring Problems

Informatica e Sistemi in Tempo Reale

Scales of the Universe

Florida Math Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Pizza! Pizza! Assessment

Dimensional Analysis and Exponential Models

first complete "prior knowlegde" -- to refresh knowledge of Simple and Compound Interest.

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION MATHEMATICS B. Thursday, January 29, :15 a.m. to 12:15 p.m.

WORK SCHEDULE: MATHEMATICS 2007

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Friday, January 29, :15 a.m. to 12:15 p.m., only

a. all of the above b. none of the above c. B, C, D, and F d. C, D, F e. C only f. C and F

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Java Basics: Data Types, Variables, and Loops

9.2 Summation Notation

Keystone National High School Placement Exam Math Level 1. Find the seventh term in the following sequence: 2, 6, 18, 54

Geometry - Calculating Area and Perimeter

Rules of Exponents. Math at Work: Motorcycle Customization OUTLINE CHAPTER

SECTION 1-6 Quadratic Equations and Applications

TEST A CHAPTER 6, EQUATIONS, INEQUALITIES, PROBLEM SOLVING. 1. Factor x 2-5x Factor x 2-4x - 5.

SAT Math Facts & Formulas Review Quiz

INTRODUCTION TO EXCEL

Factoring Polynomials

Transcription:

MAT 2170: Laboratory 3 Key Concepts The purpose of this lab is to familiarize you with arithmetic expressions in Java. 1. Primitive Data Types int and double 2. Operations involving primitive data types, especially integer division 3. Constant declaration and usage 4. Variable declaration and usage 5. Valid identifiers Exercises 1. Complete the Prelab exercises to show me at the beginning of lab 3. 2. Create the Lab exercises in the directory lab3 under your user account (not in any other directory). This can be done at the time you create each project. 3. (Exer. 3, Pg 91) Design and implement a Java dialog program, Savings, that reads in two numbers: an account balance and an annual interest rate expressed as a percentage. Display the balance at the end of one and two years, assuming no deposits or withdrawals just the interest payment. Note that the interest should be compounded annually, i.e., added to the bank balance at the end of each year. Use print to display multiple lines of output in a single dialog box, followed by a println. 4. (Exer. 4, Pg 92) Design and implement a Java dialog program, CircleArea, which asks the user for the radius of a circle, then computes the area of that circle using the formula: Area = π radius 2 There is no raise to a power operator in Java, so you will need to explicitly square the radius. Use 3.14159 as the value for π, created as a constant. 5. Design and implement a Java dialog program, DistanceSum, that will compute the sum of two distances, in yards, feet, and inches. The two distances will be entered by the user (also in yards, feet, and inches). When you report the total distance, be sure that the number of feet is less than three and the number of inches less than twelve. The answer should be displayed in a single dialog box. Keep in mind the following guidelines: Be sure to include your name and the purpose of your program in the opening comments, and use line comments and appropriate constants. Prompt the user separately for the yards, feet, and inches for each of the distances you need. Your program should convert both distances into inches, add, and then display the sum in the correct format. Declare constant int objects which are used to assist with the distance conversions. For example, InchesPerFoot, FeetPerYard, and InchesPerYard would be three useful constants. If the user enters 2 yards, 2 feet, and 8 inches, followed by 5 yards, 1 foot, and 6 inches, the total distance is 8 yards, 1 feet and 2 inches.

MAT 2170: Laboratory 3 2 6. Design and implement a Java dialog program, SpiralCoords, which calculates the coordinates of a spiral based on the initial length and scaling percentage entered by the user. Even though external documentation isn t required for this project, creating at least a few test cases would be beneficial to helping you solve this problem and ensure your program is correct. The diagram below shows a spiral. Each leg of the spiral gets shorter by a fixed percentage as you move toward the center. In the example shown, the length of BC is 90% of AB, the length of CD is 90% of BC, and so on. A E D B F C The point A appears at the origin of an arbitrarily large window. Given the length of the initial side, AB, and the scaling percentage, we wish to determine the coordinates of points B through F. Your Java program should: prompt for and obtain the length of the initial side prompt for and obtain the scaling percentage calculate and display the coordinates of the six points (use print rather than println, so all coordinates show up neatly in one dialog box) 7. When you have completed all exercises: (a) Submit an electronic copy of your work for this lab. To do this, open a terminal window and give the commands: cd 2170submit lab3 sectionx where X is either 1 (11:00), or 2 (3:00), depending on your section. (b) Publish all of these programs to your web page, listed under Lab 3 as Savings, CircleArea, DistanceSum, and SpiralCoords. (c) Complete the Postlab worksheet. (d) Staple all the program printouts (in order assigned) to the Postlab worksheet, and hand them in at the beginning of Lab 4.

Lab 3 Prelab Name: 1. Complete the test suite for the external documentation for the Savings program. Select amounts and interest rates that will test the correctness of your program. Determine the correct answers using a calculator. Problem Statement: Given a dollar amount and annual interest rate from the user, determine the balance of the account at the end of one and two years, assuming annual compounding of interest. Specifications: (a) INPUT: Amount double, non negative; InterestRate double, non negative (b) OUTPUT: Balance 1 double, non negative; Balance 2 double, non negative Test Suite: Amount Interest Rate Year 1 Year 2 6000 4.25 6255.0 6520.8375 10000 6.75 General Algorithm: Prompt for and get data Calculate and display balance for first year Calculate and display balance for second year Detailed Algorithm: Prompt for and get data Prompt for and get Amount Prompt for and get Interest Rate Change Interest Rate into decimal equivalent Calculate and display balance for first year Determine Interest for first year, add to Amount Display balance after first year Calculate and display balance for second year Determine Interest for second year (based on updated value), add to Amount Display balance after second year Continued on back

2. Complete the external documentation for the CircleArea program by filling in the Problem Statement, Test Suite table, and Detailed Algorithm. Select various radii to test the correctness of your program. Use a calculator to determine the areas in the test suite. (a) Problem Statement: (b) Specifications: i. INPUT: Radius double, non negative ii. OUTPUT: Area double, non negative (c) Test Suite: Radius Area 10 314.159265 (d) General Algorithm: Prompt for and get Radius Calculate Area Display Area (e) Detailed Algorithm: (Since this is a very simple program, just give the Java statements you plan to use.) Prompt for and get Radius Calculate Area Display Area

Lab 3 Postlab Name: Staple printouts for all projects from Lab 3 to this sheet and hand in at the beginning of Lab 4 1. What are the two attributes that define a data type? (a) (b) 2. Circle each of the following which are legal constants in Java. For the ones that are legal, indicate whether they are integers (i) or floating point (f ) constants on the line provided. a) 42 d) -2.3 g) 1,000,000 j) 0.000001 b) 17 e) 20 h) 3.1415926 k) 1.1E+11 c) 2+3 f) 2.0 i) 123456789 l) 1.1X+11 3. Rewrite the following floating point constants in Java s scientific notation form: (a) 6.02252 10 23 (b) 29979250000.0 (c) 0.00000000529167 (d) 3.1415926535 4. Circle each of the following which represent legal Java variable names: a) x e) short i) 12MonthTotal b) formula1 f) tiny j) margin-cost c) average rainfall g) total output k) b4hand d) %correct h) areasonablylongname l) stk depth 5. Indicate the value and type (i or f ) of each of the following expressions: a) 2 + 3, c) 19.0 / 5, e) 19 % 5, b) 19 / 5, d) 3 * 6.0, f) 2 % 7, 6. By applying the appropriate precedence rules, evaluate the following expressions: (a) 6 + 5 / 4-3 (b) 2 + 2 * (2 * 2-2) % 2 / 2 (c) 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 * 2 + 1 (d) 1 + 2 + (3 + 4) * ((5 * 6 % 7 * 8) - 9) - 10 Continued on back

7. Complete the following table. The object MyNumber is of type int. MyNumber (MyNumber + 5)/6 1 2 5 6 7 MyNumber (MyNumber + 5)/6 11 12 16 18 28 8. Suppose you are putting empty beverage bottles into six-packs in order to return them to the local recycling center. If you have MyNumber bottles to recycle, what does the quantity (MyNumber + 5)/6 represent? Write your answer as a simple English statement involving the number of bottles and the number of six-pack containers involved. 9. Determine the number of yards, feet, and inches we can obtain from the total inches given: Total Inches Yards Feet Inches 302 8 1 2 10 72 23 24 729 348