Quiz 1 Correction

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

INTERNATIONAL UNIVERSITY OF GRAND-BASSAM

IUGB School
Course ID# CSC 2301 – Principles of computer programming
Quiz I, Fall 2021-2022: 1h20 min - 10/04/2022
Given By: Timite Gaoussou
1. Which of the following would be valid names for a variable in Java.
a. Ticket
b. cinema ticket
c. cinemaTicket
d. cinema_ticket
e. void
f. ticket

2. If you attempt to add a float, an int, and a byte, the result will be a(n)
_____________.
a. float
b. int
c. byte
d. error message

3. Which assignment is correct in Java?


a. int value = (float) 4.5;
b. float value = 4 (double);
c. double value = 2.12;
d. char value = 5c;

4. A decision is based on a(n) ____________ value.


a. Boolean
b. absolute
c. definitive
d. convoluted

5. Assuming the variable score has been assigned the value 9, which of the
following statements displays XXX?
a. if(score <= 9) System.out.println("XXX");
b. if(score > 9); System.out.println("XXX");
c. if(score > 0); System.out.println("XXX");
d. All of the above display XXX.

1
6. import java.util.Scanner;
public class Colours3{
public static void main(String[] args){
int x;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
x = keyboard.nextInt();
switch (x){
case 1: case 2: System.out.println("Green"); break;
case 3: case 4: case 5: System.out.println("Blue"); break;
default: System.out.println("numbers 1-5 only");
}
System.out.println("Red");
}
}
What would be the output from this program if
(a) the user entered 1 when prompted?
Green
Red
(b) the user entered 2 when prompted?
Green
Red
(c) the user entered 3 when prompted?
Blue
Red
(d) the user entered 10 when prompted?
(numbers 1-5 only");
Red

(e) the break statements were removed from the switch statement and the
user entered 3 when prompted?
Blue
(numbers 1-5 only");
Red
(f) the default were removed from the switch statement and the user
entered 10 when prompted?
(numbers 1-5 only");
Red

2
7. Which of the following statements correctly outputs the names of voters who live
in district 6 and all voters who live in district 7?
a. if(district == 6 || 7)
System.out.println("Name is " + name);

b. if(district == 6 || district == 7)
System.out.println("Name is " + name);

c. if(district = 6 && district == 7)


System.out.println("Name is " + name);

d. two of these

8. Which of the following displays Error when a student ID is less than 1000 or
more than 9999?
a. if(stuId < 1000) || if(stuId > 9999)
System.out.println("Error");

b. if(stuId < 1000 && stuId > 9999)


System.out.println("Error");

c. if(stuId < 1000)


System.out.println("Error");
else
if(stuId > 9999)
System.out.println("Error");
d. Two of these are correct.

9. When determining whether a number is inside a range, it’s best to use this
operator.
1. &&
2. !
3. ||
4. ? :

10. To create a block of statements, you enclose the statements in these.


1. parentheses()
2. square brackets []
3. angled brackets <>
4. braces {}

3
4
Programming.
Meadowdale Dairy Farm sells organic brown eggs to local
customers. It charges $10.0 for a dozen eggs, or $1.00 for
individual eggs that are not part of a dozen. Write a program that
prompts a user for the number of eggs in the order and then display
the amount owed with a full explanation. For example,
typical output might be, You ordered 27 eggs. That’s 2 dozen at
$10.0 per dozen and 3 loose eggs at $1.00 each for a total of $23.0
Save the program as Quiz1Eggs.java

Software Sales
A software company sells a package that retails for $99. Quantity
discounts are given according to the
following table:
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks the user to enter the number of packages
purchased. The program should then display the amount of the discount
(if any) and the total amount of the purchase after the discount.
Name the class SofwareSales.java

You might also like