Introduction to Computer Science I
Introduction to Computer Science I COMPSCI 125
Popular in Course
Popular in ComputerScienence
This 6 page Class Notes was uploaded by Eli Torp on Saturday October 3, 2015. The Class Notes belongs to COMPSCI 125 at Boise State University taught by Mason Vail in Fall. Since its upload, it has received 10 views. For similar materials see /class/218017/compsci-125-boise-state-university in ComputerScienence at Boise State University.
Reviews for Introduction to Computer Science I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/03/15
1 Java Syntax Explain what the error in each of the following statements is and how you would x it a println quotThis is a test Println needs to be quali ed with the name of an object Systemoutprintln quotThis is a testquot b Random d new Random The constructor needs parentheses Random d new Random c int area MathPI 2 2 A double value can t be stored in an int variable Declare area to be a double double area MathPI 2 2 or convert to INT int area intMathroundMathPI 2 2 d int value 10 final int MAX 50 MAX 100 You cannot change the value of a nal variable If it needs to change leave the nal off the declaration 2 Variable types Write declarations for variables to serve the following purposes a to store the interest rate on a mortgage double interestRate b a constant to hold the maximum number of passengers on a plane with 150 seats final int MAXiPASSENGERS 150 c to store the letter grade of a student for a course char grade d to store the title of a movie String title 3 Evaluation Order Show the order of evaluation in the following expressions a a b c d 3 l 2 babcde 3 1 2 4 4 Java Output What is output by the following code SystemoutprintlnquotHere we go quot Systemoutprintlnquot1234 SystemoutprintquotTest this if ntyou aren t surequot SystemoutprintquotAnotherquot Systemoutprintln SystemoutprintlnquotAll done quot vspace2eX quotHere we goquot Test this if you aren t sureAnother All done 5 Arithmetic expressions Show the result of evaluating of the following expressions Show the value and type of the result for each operation in addition to the final value a 19 4 3 int b 168 02 double c 71 3 2 11 double d int78 5 1 int 6 Strings Given the following declarations and initializations show what would be printed String prompt quotWhat is quot String incantation quotPetri cus Totalisquot a Systemoutprintln promptlength 8 b What will be displayed by Systemoutprintln prompt 5 quot quot 4 3 quot7quot What is 5 7 c Systemoutprintln incantationsubstring ll l6toUpperCase quotLYquot TOTALLY 7 ShortAnswer Questions a circle the valididenti ers in the followinglist price Jer Jomd and ehoieel Flightii and 2ndMate are not valid b n pagedrawLine o o zoo 200 e How many hits are needed to represent 16 colors 2A4 16 so ittakes 4 hits M31quot PWE 8 Containers Draw a sketch and v III I lllllll explalnhowyouwould use lllllllll D M PW J39Labels and nested panels to create E s E smsxmsa n11 mm III1111111111114 Images hel ow the text The min was sunpanel 2pmel for the application should have two panels in it In the top one put a J39label with the text In the bottom one put two panels each with a JLa e 39 I L 39 39 l l I I i images sidebyside l llll W392 PW a window with some text across I a 9 9 Using Math Convert the following equa oninto proper Java code mm sinaxx 2a2a 3cosax 2 xMaLhsinaxa a x x aZ Mathpowa3 Matheos v x 10 Writing eode quot 4quot L4quot For mu 1hquot convertedto 35 hours irithours minutes seconds double totalHours Scanner ir new Scanner Systemih hours irrext1ut rhiriutes irrext1uto seconds irrext1uto totalHours hours minutes 600 seconds 36000 DecimalFormat df new DecimalFormat quot00quot Systyemoutprintn dfformat totalHours 1 points Short Answer Questions a 5 points Convertthe following equation into properJava code mll 2Vn sinqo D d mlambda2Mathsqrtn1Mathsinphi b 4 points Show the output of the following groups of statements Systemoutprintln quot25 4 quot 25 4 Systemoutprintln quot25 4 quot 25 4 254 6 and 25 4 254 c 5 points List some attributes for a class to represent a street in a city String name String directionboolean oneWay boolean isGravel int lanes int startingAddress d 5 points What does thefollowing code draw You may draw a pictureto illustrate public void paint Graphics page pagedrawLine0 0 getWidth getHeight pagedrawLinegetWidth2 0 getV dth2 getHeight pagedrawLine0 getHeight getWidthO 0 Box with diagonal line at 00 line 2 is centered vertical line 2 12 points Java Syntax Explain what the error in each ofthe following statements is and how you wouldfix it You can assumethat class names are valid and that variables to the right of an assignment operator have been declared and initialized a Cat 7dinnerSid Cat sevenDinnerSid b int y kbdnextDouble double y kbdnextDouble 0 double 2 sqrt 45 double 2 Mathsqrt45 d Date today new Date Date today new Date 3 12 points Variable types Write declarations for variables to serve the following purposes a To represent the numberof homework assignments given out during the semester int numHW b To represent the weight of a cut of meat at the grocery store double weight 0 To represent the name of a city String city 4 15 points Arithmetic expressions Show the steps needed for the evaluation ofthe following expressions Show the value and type of the result for each operation in addition to the final value a 10 17 3 17 is 2 int 102 is 12 int b 3 4 5 8 34 is 12 int 125 is2 int 28 is 16int c 20 14 4 2014 is 280 double 2804 is 70 double d 14 4 20 144 is 3 int 320 is 60 double e int57 21 int57 is 5 int 521 is 71 double 5 12 points Strings Given the following declarations and initializations show what would be printed by each of the statements below String caffeine quotmochachai lattequot int i 3 a Systemoutprintln caffeinelength 16 b Systemoutprintln caffeineindexOf quotttquot 13 c Systemoutprintln caffeinesubstring 2 5 quot quot caffeinesubstring6 9charcha 6 10 points Objects Consider a class called Course which has a constructor public Course String department int courseNum and a methodto add a student to the Course public void addStudent long id a Show how to declare and instantiate a Course object to represent COMPSCI 125 Course cs125 new Course COMPSCIquot 125 b Show how to add a student whose id is 1234567890123 to the Course that was created in part a cs125addStudent1234567890123L 20 points Writing code Consider writing a programto to calculate the force in dynes between the earth and some body using M F G 2 where G 399 gtlt1020 dynecm2gram d where M is the mass of the body in grams and dis the distance in cm a Declare variables to hold the mass distance and force double m d f b Declare a constant to hold the value of G final double G 399Mathpow10 20 0 Write code to calculate the force Assume that values have been assigned to mass and distance f GmMathpowd 2 d Write code to print out the mass distance andforce formatted to two digits after the decimal point on three separate lines Show the units for each quantity DecimalFormat fmt newDecimalFormat 0quot Systemoutprintln Mass fmtformatm quot9quot same thing for other two distance and force
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'