[PDF] ComS 207: Programming I Midterm 1 SAMPLE SOLUTIONS





Previous PDF Next PDF



ComS 207: Programming I Midterm 1 SAMPLE SOLUTIONS

(c) A constructor method must have the same name as its class. TRUE. (d) A class can have only one constructor method. FALSE.



Solutions to Exercises

A subclass can have only one superclass because Java doesn't support The answer is false: a class cannot inherit constructors.



Java Foundations Certified Junior Associate ? ?

The Math class methods can be called without creating an instance of a Math object. (A) True. (B) False. Answer (A). 27. You need to generate random integer 



Package data.table

If is a matrix or data.frame TRUE will retain the rownames of that object ... FALSE prevents joins that would result in more than nrow(x)+nrow(i) rows.



True/False Review Questions

constructors but not private members such as implementation fields. A programmer-defined class can have any name except a Java keyword.



Haskell Cheat Sheet

'a' – Single character. Multi-line Strings. Normally it is a syntax error if a string has any actual newline characters. That is 



Apex Developer Guide

27 Aug 2021 A value that can only be assigned true false



OOPT1Q1 Every class has at least one constructor function even

OOPT1Q2 Can constructors be overloaded? TRUE # FALSE OOPT1Q8 Which type of class has only one ... OOPT1Q92 State true of false. i) We cannot make the ...



Solutions to Exercises

Write printdots in an accumulative recursive style. This will require more than one function. The accumulator will hold the growing sequence of dots; 



Review 2: Many True/False

There is a vector field F such that ? × F?x y

ComS207:ProgrammingI

Midterm1,SAMPLESOLUTIONS

StudentName:Mr.Perfect

StudentIDNumber:555-55-555

RecitationSection:1

1.True/FalseQuestions(10x1peach=10p)

andasetofbehaviorsdefinedbyitsmethods. 1

2.ShortAnswerQuestions(5x2peach=10p)

(a)Whatisanenumeratedtype? areidentifiers,andcanbeanythingdesired. (b)Whatisanobject? owndataspaceandthereforeitsownstate. (d)Whatisautoboxing? anobjectofthattypeusingthenewoperator. 2 -i.25to49 intiNum=rand.nextInt(25)+25; -ii.-5to6 intiNum=rand.nextInt(12)-5; -iii.Generatearandomoddintegerfrom1to100 intiNum=rand.nextInt(50)*2+1; (b)Thisisthesameas(a)butwith casehowever. -i.1.5to1.7 doubledNum=rand.nextDouble()*0.2+1.5; -ii.-1.2to-0.2 doubledNum=rand.nextDouble()-1.2; 3

4.BugChase(5p+10p=15p)

withthecodeatthatlocation. (a)(5p) =======File:Buggy1.java======== publicclassBuggy1 publicstaticvoidmain(String[]args){

Strings=newString("John");

System.out.println("Mynameis"+s);

return; (b)(10p) =======File:Account.java======== publicclassAccount privateStringaccName;

Account(Stringname){

accName=name; publicvoidprintInfo(){ =========File:Bank.java========== publicclassBank publicstaticvoidmain(String[]s){

Accountaccount=newAccount("JohnSmith");

account.printInfo(); return; 4 doubleresult; intnum1=5,num2=12,num3=2; doubleval1=5.0,val2=12.0,val3=2.0; (a)result=num2/num1;2.0 (b)result=val3+num2/num1;4.0 (c)result=num3+val2/num1;4.4 (d)result=num2/num3/num1;1.0 (e)result=val2*num1+num2/num3;66.0 (g)result=(val2*(num1+num2))/num3;102.0 (h)result=val2*((num1+num2)/num3);96.0 (i)result=num1*num3*4%num2/val3;2.0 (j)result=num1+++++num2;18.0 5 (a)Rectangles(15p) oatingpointnumbers publicclassRectangles publicstaticvoidmain(String[]args) doublex1,y1,x2,y2;

Scannerscan=newScanner(System.in);

x1=scan.nextDouble(); y1=scan.nextDouble(); x2=scan.nextDouble(); y2=scan.nextDouble(); //enteredthecornersinthewrongorder. doublehSide=Math.abs(x2-x1); doublevSide=Math.abs(y2-y1); doubleperimeter=hSide*2.0+vSide*2.0; doublearea=hSide*vSide;

System.out.println("Area="+area);

6 (b)PasswordGenerator(15p)

System.out.printf("%c",'A'+num);

importjava.util.Random; publicclassPasswordGenerator publicstaticvoidmain(String[]args)

Randomrand=newRandom();

//Getthetwoletters(1stand4-thcaracters) intfirstChar=rand.nextInt(26);//0to25 intfourthChar=rand.nextInt(26);//0to25 //Getthetwonumbers(2ndand5-thcaracters) intsecondChar=rand.nextInt(10);//0to9 intfifthChar=rand.nextInt(10);//0to9 //Printthepassword

System.out.print("Yourpasswordis:[");

System.out.printf("%c",'A'+firstChar);

System.out.print(secondChar);

System.out.print("-");

System.out.printf("%c",'A'+fourthChar);

System.out.print(fifthChar);

System.out.print("]\n");

7 (c)RadianstoDegrees(15p) oating-

Sampleinput:2.0

Hint1:degrees=(radians/Math.PI)*180.0;

importjava.util.Scanner; publicclassRadians2Degrees publicstaticvoidmain(String[]args)

Scannerscan=newScanner(System.in);

doubleradians=scan.nextDouble(); //Calculatethedegrees doubledegrees=(radians/Math.PI)*180.0; intdeg=(int)Math.floor(degrees); //Calcualatetheminutes doubleminutes=60.0*(degrees-deg); intmin=(int)minutes; //CalculateSeconds doubleseconds=60.0*(minutes-min); intsec=(int)seconds;

System.out.print(radians+"radians=");

System.out.print(deg+"degrees,");

System.out.print(min+"minutes,");

System.out.print(sec+"seconds.\n");

8 (d)FormattingNames(20p) followedbyaperiod. importjava.util.Scanner; publicclassFormattingNames publicstaticvoidmain(String[]args)

Scannerscan=newScanner(System.in);

StringallNames=scan.nextLine();

//Extractthefirstname intfirstSpaceIdx=allNames.indexOf(''); //ExtracttheSecondName 9 //Extractthethirdname //Printthenameintheformat:LAST,FirstM.

System.out.print(",");

System.out.print(firstName);

System.out.print("");

System.out.print(secondName.charAt(0));

System.out.print(".");

System.out.print("\n");

10quotesdbs_dbs6.pdfusesText_12
[PDF] a class can have only one destructor

[PDF] a class can have only one private constructor

[PDF] a class can implement multiple interfaces java

[PDF] a class of language that is closed under

[PDF] a class that is used as the basis for inheritance is known as what type of class?

[PDF] a class's constructor usually defines

[PDF] a class's private helper methods may be called only by the class's other methods

[PDF] a climate of change manufacturing must rise to the risks and opportunities of climate change

[PDF] a clinician's guide to artificial intelligence

[PDF] a comparison of programming languages in economics

[PDF] a comprehensive french grammar pdf

[PDF] a computer science lab answers

[PDF] a concise introduction to logic 13th edition answer key chapter 1

[PDF] a concise introduction to logic 13th edition answer key pdf

[PDF] a concise introduction to logic answers