CSEN 104: Programming I Winter Semester 2024: Quiz/Assignment 1
CSEN 104: Programming I Winter Semester 2024: Quiz/Assignment 1
Version 2
Name: ............................................................................................
ID: ................................................................................................
TA Name: .........................................................................................
1) Write your name, ID number, TA name, and group number in the provided space above.
Good Luck!
Exercise 1 2
Possible Marks 10 10 20
Final Marks
CSEN 104: Programming I, Quiz/Assignment 1, Page 1
• int weight = 4;
int deliveryCharge;
switch (weight) {
case 1, 2:
deliveryCharge = 5;
break;
case 3, 4, 5: deliveryCharge
= 10;
case 6, 7, 8, 9, 10:
deliveryCharge = 15;
default: deliveryCharge =-1;
}
if (deliveryCharge == -1)
System.out.println("Package weight not accepted");
else
• int x = 9;
int y = 3;
30 //2 marks
CSEN 104: Programming I, Quiz/Assignment 1, Page 3
• The sum of the first and last digits should be even. If it is, proceed to the next condition.
Otherwise, display a message indicating the number does not meet the even sum requirement.
• The difference between the second and third digits must be odd. If it is, proceed to the final
condition. Otherwise, display a message indicating the number does not meet the odd difference
requirement.
• The first digit must be greater than or equal to the last digit. If it is, display a message saying the
number meets all conditions. Otherwise, display a message indicating the number does not meet
the final requirement.
Examples:
Input: 4826
Output: The number does not meet the odd difference requirement.
Input: 9452
Output: The number does not meet the even sum requirement.
Input: 8412
Output: The number meets all conditions.
Input: 328
Output: Invalid input. The number is not a 4-digit number.
}
}