APCS final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

w=(x>0)||(y==z);

Assign to the boolean variable with the result of oring the following a test to see if x is positive a test to see if y equals z

b=p&&q;

Assume b,p, and q are booleans. Write code that will assign to b the result of And-ing p and q

all of the above

If you wanted to compare the contents of two strings s1 and s2 which of the following would be appropriate to use a.s1equals(s2) b.s2.equals(s1) c.s1.equalsIgnoreCase(s2) d.All of the above e.s1==s2

import java.util.*; public class tester { public static void main(String args[]) { Scanner kbReader=new Scanner(System.in); System.out.println("Enter a decimal number."); double x=kbReader.nextDouble(); System.out.println("The decimal you entered is"+x); } }

Show code that would prompt the use to enter a decimal, then store that value in a variable and print out the result with a phrase describing the result

int x=Math.pow(25,5); System.out.println(x);

Show how we would calculate and print 25^5.

System.out.println(Math.PI);

Show how we would print the value of pi

for(initializing exp, control exp, step exp) { code to be repeated }

What is the skeleton for the for loop

one class many objects

Which of the following is a correct association. a.One class many objects b.One object many classes

Student st[]=new Student[500]; st[123]=new student(6789);

Write code that will create an array of 500 students named st and then initialize the one with index 123 with a value of 6789. The constructor will be expecting an integer that is equivalent to the student number.

String ss[]=new String[300];

Write code that will declare a string array called ss having 300 elements

Lunch picnic=new Lunch("ham and cheese" "side salad" 5.99);

Write the appropriate code to create a Lunch object called picnic. Tell the constructor that you want a ham and cheese sandwich with a side salad that cost $5.99

public double calcCost(double pr, int tp)

Write the signature for the method named calcCost that would return a double cost and accept a double pr and int tp.

public string calcCost(String pr, string tp)

Write the signature for the method named calcCost that would return a string cost and accept a string pr and a string tp

public void calcCost(double pr,int tp)

Write the signature for the method named calcCost that would return nothing and accept a double pr and int tp.

false

at least one constructor must always be defined explicitly.

Rectangle

double length=44.0; int width=13; Rectangle myRect=new Rectangle(length width); Identify the class

myRect

double length=44.0; int width=13; Rectangle myRect=new Rectangle(length width); Identify the object

double, int

double length=44.0; int width=13; Rectangle myRect=new Rectangle(length width); What type of parameters are passed to the constructor.

string int char

in a switch statement what are the three types of variables that may be used in the area designated by

double avePass=horizon.avePass();

public class PinnacleFBGame { public string opponent; public double rushingYd; public double passingYd; public int pinnacleScore; public PinnacleFBGame(String opp, double rush, double pass, int pinnSc) {....} public double avePass(int numPass) From within the main method of the class Tester, write a line of code that uses a PinnacleFBGame object called Horizon to access the avePass method

PinnacleFBGame horizon=new PinnacleFBGame("Horizon", 120, 200, 35);

public class PinnacleFBGame { public string opponent; public double rushingYd; public double passingYd; public int pinnacleScore; public PinnacleFBGame(String opp, double rush, double pass, int pinnSc) {....} public double avePass(int numPass) Write a line of code that will instantiate the object horizon from the PinnacleFBGame class. In the arguments that you pass to its constructor, specify that the opponent is Horizon, Pinnacles score was 25, rushing yards were 120, and passing yards were 200.

double d=187.2; int j=(int)d

rewrite the following illegal code using casting to make it legal double d=187.2; int j=d;

double x=Math.sqrt(26.5); System.out.println(x);

show how we would calculate and print the square root of 26.5

if() { } else { }

show the basic skeleton of an if else structure

true false

what are the two possible values of a boolean type variable

instance fields or state variables

what do you call variables that are shared by every instance of a class

and

what has higher precedence and or or

k+=1, k++, ++K

what is another way to write k=k+1

false

what is the default value of a boolean type

0

what is the default value of a numeric type

null

what is the default value of an object type

a, c

which of the following are illegal a. 15=x; b.x=15; c.final x=12; x=15;

char chr[]={'a','b','c','d','e'};

write a single line of code that will declare a character array called chr and initialize its elements to be "a", "b", "c", "d", and "e"

p=p+10 P+=10;

write code that is equivalent to saying the new value of p is the old value of p plus 10


Ensembles d'études connexes

Physics Final Exam: Electromagnetic

View Set

Bio 302 Lecture 14 History of Eugenics

View Set

CH. 1 ~ The Exceptional Manager: What You Do, How You Do It {assignment & quiz} ~ MGMT 320 WINTER INTERSESSION 2019 ~ DR. TAMELA D. FERGUSON ~ ULL

View Set

Parathyroid Hormones and Calcitonin

View Set

Chapter 16 pre test, post test and Chapter test

View Set