Quiz 1 Correction
Quiz 1 Correction
Quiz 1 Correction
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
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);
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");
9. When determining whether a number is inside a range, it’s best to use this
operator.
1. &&
2. !
3. ||
4. ? :
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