160 likes | 174 Views
Engage in a unique programming quiz with your partner, followed by hands-on practice with a fun coding challenge. Enhance your coding skills in an interactive setting. Get ready to dive deep into coding concepts!
E N D
Seating “chart” Front 4 rows 5 rows 5 rows 4 rows 2 rows 2 rows 5 rows 5 rows 4 rows Back
Quiz You will work with your partner (Lab partner not full team). You will have 20 minutes.
Quiz Grading • Pass your quiz to another team in a different section than you. • As we go over each question, grade it based on the points and result.
Question 1 • Which of the following is not a valid assignment statement, assuming all variables have been declared and initialized with an appropriate data type? • total = sum + next; • keyboard.nextInt() = value; • count = count + flag; • rate = 10.2;
Question 2 • WhichCar.java:44: possible loss of precision • found : doublerequired: intcost = totalCost; • What is the possible cause of this error? • cost has not been declared • cost has not been initialized • totalCost has not been initialized • cost is an int and totalCost is a double
Question 3 • WhichCar.java:44: possible loss of precision • found : double required: int cost = totalCost; • On what line number in the source file does this error occur? • Line 0 • Line 15 • Line 44 • It is impossible to tell from the error message provided
Question 5 • Declare a String variable named state. Then initialize the variable so it references an object with the string “Virginia”. • String state; • state = “Virginia”; • OR • state = new String (“Virginia”);
Question 6 • Does the following statement compute the average of double variables a, b, and c? Why or why not? Explain double average = a + b + c / 3.0; 1pt – NO 1pt – The c will be divided by 3 first and then that result will be added to a + b.
Question 7 • Which of the following assignments are valid, given that the following variables are declared: • int cost, double taxRate, float interestRate, long count • interestRate = taxRate; • cost = taxRate; • count = cost; • cost = count;
Question 8 Enclosing a group of statements inside a set of braces creates a • block of statements • boolean expression • loop • Nothing, it is just for readability
Practice - Solve a problem in pieces. • In your teams, work on the following problem: • The distance between any two points, (x1y1 and x2y2) can be computed by the formula: Write a program to read in from the user the point values and then compute and print the distance in the form of: The distance between (x1y1) and (x2y2) is XXXX.XX.
Think about this problem as a problem in 3 parts. • Part 1 – Reading in the input. • Think about the variables you will need. (At least one variable for each individual component of the points and a Scanner) and declare them. • Think about how you will prompt the user. • Perform the read operations to load the variables. • Note: if you are writing the program, you could stop here and test by “echoing” the input via a temporary println to show that the variables hold the correct values.
Part 2 • Calculating the result • Think about any additional variables you will need and declare them up top. • Create the calculation. Note that while this is a single formula, you might do better by breaking it down. Two Math class methods that might be useful are Math.pow() and Math.sqrt. • At this point you can test to see that the calculation is working correctly. If you are using sub calculations, you can also test them by putting in additional print statements.
Part 3 – Making the format pretty • Now that you have the program producing the correct result, add in print statements to display the result. Use the DecimalFormat class (another variable) if you wish or printf. • If this is working correctly, you can then remove all of the unnecessary print statements that you used for testing.
Homework • Finish up the work on this algorithm. You will be writing this program as one part of the work of Tuesday’s lab. • There will be a weekly quiz and the focus will be on arithmetic operations.