7 Pages

Data Expressions(1)

Course: CPSC 1301, Spring 2010
School: Columbus State University
Rating:
 
 
 
 
 

Word Count: 1616

Document Preview

Expressions(1) Data Java Programming Lab Exercises Topics Variables Constants Assignment Lab Exercises Prelab Exercises Area and Circumference of a Circle Painting a Room Submitting your assignment in WebCT Vista Your task is to submit your assignment under the supervision of your instructor: o Upload this file (DataExpressions(1).rtf) with your answers to the assignment box in WebCT for this lab class. o Upload...

Register Now

Unformatted Document Excerpt

Coursehero >> Georgia >> Columbus State University >> CPSC 1301

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Expressions(1) Data Java Programming Lab Exercises Topics Variables Constants Assignment Lab Exercises Prelab Exercises Area and Circumference of a Circle Painting a Room Submitting your assignment in WebCT Vista Your task is to submit your assignment under the supervision of your instructor: o Upload this file (DataExpressions(1).rtf) with your answers to the assignment box in WebCT for this lab class. o Upload your programs (Errors.java, Circle.java, Circle2.java, Circle3.java, and Paint.java) to the assignment box in WebCT for this lab class. Data Expressions(1) 1 Prelab Exercises 1. 2. What is the difference between a variable and a constant? Explain what each of the lines below does. Be sure to indicate how each is different from the others. a. int x; b. c. int x = 3; x = 3; 3. The following program reads three integers and prints the average. Fill in the blanks so that it will work correctly. // ******************************************************************* // Average.java // // Read three integers from the user and print their average // ******************************************************************* import java.util.Scanner; public class Average { public static void main(String[] args) { int val1, val2, val3; double average; Scanner scan = new Scanner(System.in) ; // get three values from user System.out.println("Please enter three integers and " + "I will compute their average"); ____________________________________ ____________________________________ ____________________________________ //compute the average ____________________________________ //print the average ____________________________________ } } 2 Data Expressions(1) 4. Given the declarations below, find the result of each expression. int a = 3, b = 10, c = 7; double w = 12.9, y = 3.2; a. b. c. d. e. f. g. h. i. j. k. a+b*c a-b-c a/b b/a a-b/c w/y y/w a+w/b a%b/y b%a w% y 5. Carefully study the following program and find and correct all of the syntax errors. // File: // Purpose: // Errors.java A program with lots of syntax errors Correct all of the errors (STUDY the program carefully!!) #import java.util.Scanner; public class errors { public static void main (String[] args) { String Name; / Name of the user int number; int numSq; Scanner scan = new Scanner(System.in); System.out.print ("Enter your name, please: ") Name = scan.nextInt(); System.out.print ("What is your favorite number?); number = scan.nextInt(); numSq = number * number; System.out.println (Name ", the square of your number is " numSquared); } Data Expressions(1) 3 6. Trace the execution of the following program assuming the input stream contains the numbers 10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the output (exactly as it would be printed). // FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; double what; Scanner scan = new Scanner(System.in); System.out.print ("Enter two integers: "); one = scan.nextInt(); two = scan.nextInt(); System.out.print("Enter a floating point number: "); what = scan.nextDouble(); three = 4 * one + 5 * two; two = 2 * one; System.out.println ("one " + two + ":" + three); one = 46 / 5 * 2 + 19 % 4; three = one + two; what = (what + 2.5) / 2; System.out.println (what + " is what!"); } } 4 Data Expressions(1) Area and Circumference of a Circle Study the program below, which uses both variables and constants: //********************************************************** // Circle.java // // Print the area of a circle with two different radii //********************************************************** public class Circle { public static void main(String[] args) { final double PI = 3.14159; int radius = 10; double area = PI * radius * radius; System.out.println("The area of a circle with radius " + radius + " is " + area); radius = 20; area = PI * radius * radius; System.out.println("The area of a circle with radius " + radius + " is " + area); } } Some things to notice: V V V V V V The first three lines inside main are declarations for PI, radius, and area. Note that the type for each is given in these lines: final double for PI, since it is a floating point constant; int for radius, since it is an integer variable, and double for area, since it will hold the product of the radius and PI, resulting in a floating point value. These first three lines also hold initializations for PI, radius, and area. These could have been done separately, but it is often convenient to assign an initial value when a variable is declared. The next line is simply a print statement that shows the area for a circle of a given radius. The next line is an assignment statement, giving variable radius the value 20. Note that this is not a declaration, so the int that was in the previous radius line does not appear here. The same memory location that used to hold the value now 10 holds the value 20we are not setting up a new memory location. Similar for the next lineno double because area was already declared. The final print statement prints the newly computed area of the circle with the new radius. Save this program, which is in file Circle.java, into your directory and modify it as follows: 1. The circumference of a circle is two times the product of Pi and the radius. Add statements to this program so that it computes the circumference in addition to the area for both circles. You will need to do the following: V Declare a new variable to store the circumference. V Store the circumference in that variable each time you compute it. V Add two additional print statements to print your results. Be sure your results are clearly labeled. 2. When the radius of a circle doubles, what happens to its circumference and area? Do they double as well? You can determine this by dividing the second area by the first area. Unfortunately, as it is now the program overwrites the first area with the second area (same for the circumference). You need to save the first area and circumference you compute instead of overwriting them with the second set of Data Expressions(1) 5 computations. So you'll need two area variables and two circumference variables, which means they'll have to have different names (e.g., area1 and area2). Remember that each variable will have to be declared. Save this program, which is in file Circle2.java, into your directory and modify it as follows: Change the names of the area and circumference variables so that they are different in the first and second calculations. Be sure that you print out whatever you just computed. V At the end of the program, compute the area change by dividing the second area by the first area. This gives you the factor by which the area grew. Store this value in an appropriately named variable (which you will have to declare). V Add a println statement to print the change in area that you just computed. V Now repeat the last two steps for the circumference. Look at the results. Is this what you expected? 3. In the program above, you showed what happened to the circumference and area of a circle when the radius went from 10 to 20. Does the same thing happen whenever the radius doubles, or were those answers just for those particular values? To figure this out, you can write a program that reads in values for the radius from the user instead of having it written into the program ("hardcoded"). Save this program, which is in file Circle3.java, into your directory and modify it as follows: V At the very top of the file, add the line import java.util.Scanner; This tells the compiler that you will be using methods from the Scanner class. In the main method create a Scanner object called scan to read from System.in. Instead of initializing the radius in the declaration, just declare it without giving it a value. Now add two statements to read in the radius from the user: V A prompt, that is, a print statement that tells the user what they are supposed to do (e.g., "Please enter a value for the radius."); V A read statement that actually reads in the value. Since we are assuming that the radius is an integer, this will use the nextInt() method of the Scanner class. When the radius gets it second value, make it be twice the original value. Compile and run your program. Does your result from above hold? V V V 6 Data Expressions(1) Painting a Room File Paint.java contains the partial program below, which when complete will calculate the amount of paint needed to paint the walls of a room of the given length and width. It assumes that the paint covers 350 square feet per gallon. //*************************************************************** //File: Paint.java // //Purpose: Determine how much paint is needed to paint the walls //of a room given its length, width, and height //*************************************************************** import java.util.Scanner; public class Paint { public static void main(String[] args) { final int COVERAGE = 350; //paint covers 350 sq ft/gal //declare integers length, width, and height; //declare double totalSqFt; //declare double paintNeeded; //declare and initialize Scanner object //Prompt for and read in the length of the room //Prompt for and read in the width of the room //Prompt for and read in the height of the room //Compute the total square feet to be painted--think //about the dimensions of each wall //Compute the amount of paint needed //Print the length, width, and height of the room and the //number of gallons of paint needed. } } Save this file to your directory and do the following: 1. 2. Fill in the missing statements (the comments tell you where to fill in) so that the program does what it is supposed to. Compile and run the program and correct any errors. Suppose the room has doors and windows that don't need painting. Ask the user to enter the number of doors and number of windows in the room, and adjust the total square feet to be painted accordingly. Assume that each door is 20 square feet and each window is 15 square feet. Data Expressions(1) 7
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Columbus State University - CPSC - 1301
Chapter 2: Data and Expressions (2) Lab ExercisesTopicsHTML Applets ColorsLab ExercisesIntroduction to HTML Drawing Shapes Drawing a FaceChapter 2: Data and Expressions1Introduction to HTMLHTML is the HyperText Markup Language. It is used to descr
Columbus State University - CPSC - 1301
Introduction to Java Programming Lab ExercisesTopicsPrinting strings Syntax errorsLab ExercisesPrelab Exercises Poem Recognizing Syntax Errors Correcting Syntax ErrorsIntroduction1Prelab ExercisesYour task is to write a Java program that will prin
Columbus State University - CPSC - 1301
CPSC 1301 Computer Science 1 lecture November 16 (lab) o Answer student questions about last weeks lab assignments o Review the two programs for this weeks lab November 17 o Briefly introduce Arrays from Chapter 7 [20 minutes] o 7.1 Array Elements discuss
Columbus State University - CPSC - 1301
CPSC 1301 Computer Science 1 lecture October 9 o Review Midterm Exam o Answer student questions about Midterm, etc. o Introduce Chapter 5 Conditionals and Loops o 5.1 Boolean Expressions Define flow of control Define conditional statement (selection state
Columbus State University - CPSC - 1301
Chapter 6: Object-Oriented Design (1) Lab ExercisesTopicsParameter Passing Method Decomposition Overloading Static Variables and MethodsLab ExercisesChanging People (submit) A Modified MiniQuiz Class (submit) A Flexible Account Class (submit) Opening
Columbus State University - CPSC - 1301
Chapter 6: Object-Oriented Design (2) Lab ExercisesTopicsOverall class design GUI LayoutsLab ExercisesRandom Walks Telephone KeypadChapter 6: Object-Oriented Design1Random WalksIn this lab you will develop a class that models a random walk and wri
Columbus State University - CPSC - 1301
Orientation Lab ExercisesTopicsFamiliarization with labLab ExercisesComputer Hardware Logging onto CSU Network Logging into WebCT Vista Locating Java Write a simple program Write a simple program Compile and run a program in DOSIntroduction to Crimso
Columbus State University - CPSC - 1301
Chapter 3: Using Classes and Objects Lab ExercisesTopicsString Class Random ClassLab ExercisesPrelab Exercises Working with Strings Rolling DiceChapter 3: Using Classes and Objects1Prelab Exercises Sections 3.2-3.5These exercises focus on the Stri
Columbus State University - CPSC - 1301
Chapter 3: Using Classes and Objects (2) Lab ExercisesTopicsEnumerated Types Panels Wrapper Classes Formatting ClassesLab ExercisesPlaying with Cards (required) Nested Panels (required) Experimenting with the Integer Class (extra credit) Formatting Ou
American River - ENG - Math320
Indiana - BUS-A - 5290
EbyCompanyleasedequipmenttotheMillsCompanyonJuly1,2008,foratenyearperiodexpiringJune30, 2018.Equalannualpaymentsundertheleaseare$80,000andaredueonJuly1ofeachyear.Thefirst paymentwasmadeonJuly1,2008.TherateofinterestcontemplatedbyEbyandMillsis9%.Thecashsel
Indiana - BUS-A - 5290
OnJanuary1,2008,Dexter,Inc.signsa10yearnoncancelableleaseagreementtoleaseastoragebuilding fromGarrWarehouseCompany.Collectibilityofleasepaymentsisreasonablypredictableandnoimportant uncertaintiessurroundtheamountofcostsyettobeincurredbythelessor.Thefollow
Indiana - BUS-A - 5290
OnJanuary1,2008,Dexter,Inc.signsa10yearnoncancelableleaseagreementtoleaseastoragebuilding fromGarrWarehouseCompany.Collectibilityofleasepaymentsisreasonablypredictableandnoimportant uncertaintiessurroundtheamountofcostsyettobeincurredbythelessor.Thefollow
Indiana - BUS-A - 5290
Incomputingdepreciationofaleasedasset,thelesseeshouldsubtract a.aguaranteedresidualvalueanddepreciateoverthetermofthelease. b.anunguaranteedresidualvalueanddepreciateoverthetermofthelease. c.aguaranteedresidualvalueanddepreciateoverthelifeoftheasset. d.an
Indiana - BUS-A - 5290
OnDecember31,2007,PoolCorporationleasedashipfromRennCompanyforaneightyearperiodexpiring December30,2015.Equalannualpaymentsof$200,000aredueonDecember31ofeachyear,beginningwith December31,2007.TheleaseisproperlyclassifiedasacapitalleaseonPool'sbooks.Thepre
Indiana - BUS-A - 5290
Incomputingthepresentvalueoftheminimumleasepayments,thelesseeshould a.useitsincrementalborrowingrateinallcases. b.useeitheritsincrementalborrowingrateortheimplicitrateofthelessor,whicheverishigher,assumingthat theimplicitrateisknowntothelessee. c.useeithe
Indiana - BUS-A - 5290
AmstopCompanyissues$20,000,000of10year,9'ondsonMarch1,2007at97plusaccruedinterest.The bondsaredatedJanuary1,2007,andpayinterestonJune30andDecember31.Whatisthetotalcash receivedontheissuedate? a.$19,400,000 b.$20,450,000 c.$19,700,000 d.$19,100,000
Indiana - BUS-A - 5290
The10'ondspayableofKleinCompanyhadanetcarryingamountof$570,000onDecember31,2006.The bonds,whichhadafacevalueof$600,000,wereissuedatadiscounttoyield12%.Theamortizationofthe bonddiscountwasrecordedundertheeffectiveinterestmethod.InterestwaspaidonJanuary1and
Indiana - BUS-A - 5290
Ifbondsareissuedinitiallyatapremiumandtheeffectiveinterestmethodofamortizationisused,interest expenseintheearlieryearswillbe a.greaterthanifthestraightlinemethodwereused. b.greaterthantheamountoftheinterestpayments. cthesameasifthestraightlinemethodwereus
Indiana - BUS-A - 5290
1b)Therateofinterestactuallyearnedbybondholdersiscalledthe a.statedrate. b.yieldrate. c.effectiverate. d.effective,yield,ormarketrate.
Indiana - BUS-A - 5290
1a)Theinterestratewritteninthetermsofthebondindentureisknownasthe a.couponrate. b.nominalrate. c.statedrate. d.couponrate,nominalrate,orstatedrate.
Indiana - BUS-A - 5290
CromwellCompanyhasthefollowingcumulativetaxabletemporarydifferences: 12/31/0812/31/07 $1,350,000$960,000 Thetaxrateenactedfor2008is40%,whilethetaxrateenactedforfutureyearsis30%.Taxableincomefor 2008is$2,400,000andtherearenopermanentdifferences.Cromwell'sp
Indiana - BUS-A - 5290
In2007,AdmireCompanyaccrued,forfinancialstatementreporting,estimatedlossesondisposalofunused plantfacilitiesof$1,500,000.ThefacilitiesweresoldinMarch2008anda$1,500,000losswasrecognizedfor taxpurposes.Alsoin2007,Admirepaid$100,000inpremiumsforatwoyearlifei
Indiana - BUS-A - 5290
MarkesCorporation'spartialincomestatementafteritsfirstyearofoperationsisasfollows: Incomebeforeincometaxes$3,750,000 Incometaxexpense Current$1,035,000 Deferred 90,0001,125,000 Netincome$2,625,000 Markesusesthestraightlinemethodofdepreciationforfinancialr
Indiana - BUS-A - 5290
Equipment which cost $213,000 and had accumulated depreciation of $114,000 was sold for $111,000. This transaction should be shown on the statement of cash flows (indirect method) as a(n)a. b. c. d. additiontonetincomeof$12,000anda$111,000cashinflowfromf
Indiana - BUS-A - 325
Stylish Sitting is a retailer of office chairs located in San Francisco, California. Due to increased market competition, the CFO of financial information provided below. Sales price Per unit variable costs Invoice cost Sales commissions Total per unit va
Indiana - BUS-A - 325
The difference between the total actual overhead cost incurred during a period and budgeted total factory overhead for the actual quantity of the cost driver used to apply overhead is equal to the: A) Factory overhead production-volume variance. B) Total
Indiana - BUS-A - 325
In a standard cost system, when production is greater than the denominator volume level, there will be: A) A favorable production-volume variance. B) An unfavorable total spending variance. C) A favorable sales-volume variance. D) A favorable overhead bud
Indiana - BUS-A - 325
A deviation from standard because of the failure to include one or more relevant variables, or the inclusion of the wrong or irrelevant variables in the standard-setting process is an example of a(n): A) Modeling error. B) Random error. C) Measurement err
Indiana - BUS-A - 325
A deviation from standard that occurs because of an incorrect number resulting from improper or inaccurate accounting systems or procedures is an example of a(n): A) Implementation error. B) Modeling error. C) Random error. D) Accounting error E) Predicti
Indiana - BUS-A - 325
A deviation from standard that occurs during operations as a result of operator errors is an example of a(n): A) Random error. B) Accounting error C) Implementation error. D) Modeling error. E) Prediction error.
Indiana - BUS-A - 325
In regard to the investigation of variances under uncertainty, which of the following is not a positive (i.e., desirable) combination of courses of action and states of nature? A) Investigate; a nonrandom fluctuation has occurred. B) Do not investigate; a
Indiana - BUS-A - 325
For product-costing purposes, which of the following statements is true? A) Only standard variable overhead costs are included since these costs change in response to cost drivers. B) It is necessary to "unitize" fixed overhead costs, under the absorption
Indiana - BUS-A - 325
All of the following choices exist for defining the denominator volume (denominator activity level) for assigning fixed overhead costs in a standard cost system, except: A) Theoretical capacity. B) Normal capacity. C) Budgeted capacity utilization. D) Pra
Indiana - BUS-A - 325
In terms of allocating fixed overhead cost to products, generally accepted accounting principles: A) Allow for the use of either practical capacity or theoretical capacity. B) Don't apply since the resulting data are used only internally (for control purp
Indiana - BUS-A - 325
For internal reporting purposes, it is recommended that fixed overhead allocation rates in a standard costing system be based on: A) Practical capacity. B) Theoretical capacity since this is the level required under generally accepted accounting principle
Indiana - BUS-A - 325
Which one of the following journal entries in a standard cost system would be used to apply factory overhead costs to production? A) A credit to Finished Goods Inventory, at standard cost. B) A credit to the factory overhead account, at standard cost. C)
Indiana - BUS-A - 325
Which one of the following journal entries in a standard cost system is needed at the end of the period to close out to Cost of Goods Sold an unfavorable production-volume variance? A) A credit to Cost of Goods sold, at actual cost. B) A credit to Cost of
Indiana - BUS-A - 325
Some accountants would argue that any variances from standard costs, when such standards are current, should be written off to cost of goods sold. The principal rationale for this treatment is: A) Consistency with current income tax provisions. B) The neg
Indiana - BUS-A - 325
If standard cost variances are allocated (i.e., prorated) to inventory and cost of goods sold (CGS) accounts at the end of a period, which of the following is correct? A) The amount allocated to inventories is generally larger than the amount allocated to
Indiana - BUS-A - 325
For which one of the following reasons is the calculation of overhead variances in conjunction with an activity-based cost (ABC) system desirable from the standpoint of management? A) Such a system is likely to be less costly to design and implement. B) T
Indiana - BUS-A - 325
When there is a standard batch size for production activity: A) The variable portion of the total flexible-budget variance for batch-related costs can be further decomposed into a spending and a volume variance, which leads to better cost control. B) Stan
Indiana - BUS-A - 325
Which of the following is not a cost system proposed as an extension to ABC systems, with the overall goal of more accurately allocating manufacturing overhead costs to outputs? A) Flexible standard costing. B) GPK (Grenzplankostenregnung). C) Variable co
Indiana - BUS-A - 325
Which one of the following standard cost variances is not available when analyzing batch-related manufacturing overhead costs using an activity-based cost (ABC) system? A) Fixed spending variance. B) Variable setup spending variance. C) Fixed flexible-bud
Indiana - BUS-A - 325
A payoff table for variance investigation that measures the cost of two states of nature and possible alternative actions by management will have: A) Only idealistic combinations. B) Only two realistic combinations. C) Three combinations.D) Four combinat
Indiana - BUS-A - 325
Causes of random variances are beyond the control of management, and are most often found in:A) Commodity products exchanged in open markets.B) Wages and salaries. C) Fixed costs. D) Specialized industries. E) Depreciation charges.
Indiana - BUS-A - 325
Which of the following statements about the standard variable factory overhead application rate is true? A) The rate is a function of the denominator volume chosen. B) Generally speaking, the rate will be independent of the allocation base chosen to apply
Indiana - BUS-A - 325
BUS-A 325 #4The difference between total factory overhead cost incurred during a period and the total standard factory overhead cost assigned to production of the period is the _: A) Flexible-budget variance. B) Production-volume variance. C) Overhead ef
Indiana - BUS-A - 325
BUS-A 325 #3Which one of the following characteristics is associated with standard cost variance analysis for manufacturing overhead under a traditional versus an activity-based cost (ABC) system? A) The traditional cost system does not meet the current
Indiana - BUS-A - 325
Among characteristics that distinguish service and manufacturing firms are the:A) Absence of output inventory in service firms.B) Capital intensiveness of service firms. C) Organizational structure of service firms. D) Rendering of identical services in
Indiana - BUS-A - 325
A payoff table for variance investigation that measures the cost of two states of nature and possible alternative actions by management will have: A) Only idealistic combinations.B) Only two realistic combinations. C) Three combinations.D) Four combinat
McGill - ANTH - ANTH 212
Friday, January 8thDevelopment as a term has won out over its competitors:civilization, westernization, modernization even liberation.Principles of Biological Development:Directionality: you know where a seed and seedling are headed. Cumulative: Each
McGill - ENGL - 202
Epic Conventions in PL Epic convention: Invocation of the Muses In medias res: in the middle of things (usually A-B-C, epic: B-A-C) Phrase that describes the hero without naming him: one big characteristic Ex. Achilles rage: Epic argument/subject Song/sin
McGill - ENGL - 202
English Final Review Questions 1. Describe the central conceit in Donnes A Valediction, Forbidding Mourning. The central conceit is that love is like a religion, illuminating lovers far more than any other human being, providing them with a sense of encom
McGill - ENGL - 202
Marvell Was involved, like Milton, in the government and the overthrow of the Loyalists and Charles I.To His Coy Mistress Classic example of carpe diem. Characterization by particular themes that writers tend to write on. Urging the speakers beloved to s
McGill - ENGL - 202
Paradise Lost Book II Line 21: vocabulary to disguise other ends 466- after they say that they will invade earth (Satan takes the lead). His throne is not safe, and he has to think a lot about politics and protecting his position. This is not through cons
McGill - ENGL - 202
#20. Nature is very capricious For a woman = as Subversive. Nature was inexorable, set patterns and standards of gender, but nature is random and capricious and can transform people in the womb. Goes against the conventions of nature. People had to adhere
Academy of Design Chicago - ART - 125987
HW #1: Introduction and Symmetric Key Encryption CS 6903: Modern Cryptography Spring 2010 [100pts] DUE 03/05/2010 (11am)Problem 1 [10pts]What are the fundamental goals in information security? Give a practical scenario each where each of these goals are
Incarnate Word - ART - 950
drawing help - examples of brick patterns
Incarnate Word - ART - 950
Incarnate Word - ART - 950