Skip to main content

Section 12.13 Unit 3 Write Code for Toggle Code

These are the write code problems and mixed up code puzzles used by the Unit 3 Toggle Code Practice page. Each problem has two copies that differ only in their label: the Get Help puzzle for the copy whose label ends in -ct-static is always the mixed up code puzzle below it, while the other copyโ€™s Get Help puzzle is personalized by CodeTailor when the course has an API token. The practice page assigns each student one copy of each problem at random.

Activity 12.13.1.

Write a constructor for the Student class. It takes a name (a String), a grade (an int), and a gpa (a double), in that order, and sets the matching instance variables. Then write a toString method that returns the studentโ€™s information in the form name (grade grade): gpa, for example Ana (grade 10): 3.8.

Activity 12.13.2.

Write a constructor for the Student class. It takes a name (a String), a grade (an int), and a gpa (a double), in that order, and sets the matching instance variables. Then write a toString method that returns the studentโ€™s information in the form name (grade grade): gpa, for example Ana (grade 10): 3.8.

Activity 12.13.1.

Write a constructor for the Student class. It takes a name (a String), a grade (an int), and a gpa (a double), in that order, and sets the matching instance variables. Then write a toString method that returns the studentโ€™s information in the form name (grade grade): gpa, for example Ana (grade 10): 3.8. The blocks below are mixed up and include extra blocks that are not needed. Drag the needed blocks from the left and put them in order on the right, with the right indentation. Click Check to check your solution.

Activity 12.13.3.

Write a getPrice method for the Ticket class. It returns 5 if age is under 12, and 10 otherwise.

Activity 12.13.4.

Write a getPrice method for the Ticket class. It returns 5 if age is under 12, and 10 otherwise.

Activity 12.13.2.

Write a getPrice method for the Ticket class. It returns 5 if age is under 12, and 10 otherwise. The blocks below are mixed up and include extra blocks that are not needed. Drag the needed blocks from the left and put them in order on the right, with the right indentation. Click Check to check your solution.

Activity 12.13.5.

Write a withdraw method for the BankAccount class. It takes an int amount. If the account has at least that much money, subtract amount from balance. Otherwise, leave balance unchanged.

Activity 12.13.6.

Write a withdraw method for the BankAccount class. It takes an int amount. If the account has at least that much money, subtract amount from balance. Otherwise, leave balance unchanged.

Activity 12.13.3.

Write a withdraw method for the BankAccount class. It takes an int amount. If the account has at least that much money, subtract amount from balance. Otherwise, leave balance unchanged. The blocks below are mixed up and include extra blocks that are not needed. Drag the needed blocks from the left and put them in order on the right, with the right indentation. Click Check to check your solution.

Activity 12.13.7.

Write two methods for the Rectangle class. getArea returns width times height. isLargerThan takes another Rectangle and returns true if this rectangleโ€™s area is larger than the other rectangleโ€™s area.

Activity 12.13.8.

Write two methods for the Rectangle class. getArea returns width times height. isLargerThan takes another Rectangle and returns true if this rectangleโ€™s area is larger than the other rectangleโ€™s area.

Activity 12.13.4.

Write two methods for the Rectangle class. getArea returns width times height. isLargerThan takes another Rectangle and returns true if this rectangleโ€™s area is larger than the other rectangleโ€™s area. The blocks below are mixed up and include extra blocks that are not needed. Drag the needed blocks from the left and put them in order on the right, with the right indentation. Click Check to check your solution.

Activity 12.13.9.

Every PizzaOrder shares the same price per slice, stored in the static variable pricePerSlice. Write a static method setPricePerSlice that takes a double price and changes pricePerSlice to it. Then write a getTotal method that returns the orderโ€™s total cost: slices times pricePerSlice.

Activity 12.13.10.

Every PizzaOrder shares the same price per slice, stored in the static variable pricePerSlice. Write a static method setPricePerSlice that takes a double price and changes pricePerSlice to it. Then write a getTotal method that returns the orderโ€™s total cost: slices times pricePerSlice.

Activity 12.13.5.

Every PizzaOrder shares the same price per slice, stored in the static variable pricePerSlice. Write a static method setPricePerSlice that takes a double price and changes pricePerSlice to it. Then write a getTotal method that returns the orderโ€™s total cost: slices times pricePerSlice. The blocks below are mixed up and include extra blocks that are not needed. Drag the needed blocks from the left and put them in order on the right, with the right indentation. Click Check to check your solution.
You have attempted of activities on this page.