AP Computer Science Unit 3 Progress Check: FRQ

studied byStudied by 5 people
5.0(1)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 4

5 Terms

1

Assume that the following variables have been properly declared and initialized.
a boolean variable named rsvp
an int variable named selection, where 1 represents "beef", 2 represents "chicken", 3 represents "pasta", and all other values represent "fish"
a String variable named option1
a String variable named option2

Go to the next one for answers.

New cards
2

(a) Write a code segment that prints "attending" if rsvp is true and prints "not attending" otherwise.
Write the code segment below.

if(rsvp == true)
{
System.out.println("Attending");

{
else
{
System.out.println("Not Attending");
}

New cards
3

(b) Write a code segment that prints the food item associated with selection. For example, if selection is 3, the code segment should print "pasta".
Write the code segment below. Your code segment should meet all specifications and conform to the example.

if (selection == 1)
{
System.out.println("beef");
}
else if (selection == 2)
{
System.out.println("chicken");
}
else if (selection == 3)
{
System.out.println("pasta");
}
else
{
System.out.println("fish");
}

New cards
4

(c) Write a code segment that will store a dinner selection in option1 based on the values of rsvp and selection. The intended behavior of the code segment is described below.
If rsvp is true, the code segment should store in option1 a string indicating the person's attendance and food choice. For example, if rsvp is true and selection is 1, the following string should be stored in option1.
"Thanks for attending. You will be served beef."
If rsvp is false, the following string should be stored in option1, regardless of the value of selection.
"Sorry you can't make it."
Write the code segment below. Your code segment should meet all specifications and conform to the examples.

if(rsvp == true)
{
if(selection == 1)

{
option1 = "Thanks for attending. You will be served beef.";
System.out.println(option1);
}

if(selection == 2)

{
option1 = "Thanks for attending. You will be served chicken.";
System.out.println(option1);
}

if(selection == 3)

{
option1 = "Thanks for attending. You will be served pasta.";
System.out.println(option1);
}

if(selection == 4)

{
option1 = "Thanks for attending. You will be served fish.";
System.out.println(option1);
}
else

{
option1 = "Sorry you can't make it.";
System.out.println(option1);
}

New cards
5

(d) Write a code segment that will print true if the strings option1 and option2 contain the same values and will print false otherwise.
Write the code segment below.

if(option1.equals(option2))

{
System.out.println("True");

}
else

{
System.out.println("False");
}

New cards

Explore top notes

note Note
studied byStudied by 47 people
650 days ago
5.0(1)
note Note
studied byStudied by 36 people
99 days ago
5.0(1)
note Note
studied byStudied by 61 people
743 days ago
5.0(2)
note Note
studied byStudied by 48 people
631 days ago
5.0(1)
note Note
studied byStudied by 19 people
211 days ago
5.0(1)
note Note
studied byStudied by 18 people
853 days ago
5.0(1)
note Note
studied byStudied by 440 people
938 days ago
5.0(5)
note Note
studied byStudied by 30 people
629 days ago
5.0(1)

Explore top flashcards

flashcards Flashcard (97)
studied byStudied by 10 people
614 days ago
5.0(1)
flashcards Flashcard (64)
studied byStudied by 11 people
832 days ago
5.0(1)
flashcards Flashcard (33)
studied byStudied by 34 people
280 days ago
5.0(1)
flashcards Flashcard (25)
studied byStudied by 5 people
706 days ago
5.0(1)
flashcards Flashcard (123)
studied byStudied by 168 people
40 days ago
5.0(1)
flashcards Flashcard (53)
studied byStudied by 3 people
708 days ago
5.0(1)
flashcards Flashcard (63)
studied byStudied by 10 people
636 days ago
5.0(2)
flashcards Flashcard (28)
studied byStudied by 81 people
437 days ago
5.0(3)
robot