Class Notes (1,100,000)
US (480,000)
Rutgers (10,000)
4:18 (400)
Lecture 7

01:198:111 Lecture 7: CS 111 Buying Cake


Department
Computer Science
Course Code
01:198:111
Professor
A Centeno
Lecture
7

This preview shows half of the first page. to view the full 2 pages of the document.
Buying cake
Day old- $8
<8 inches - $10
>8 < 14 - $14
>14 - $20
Ask user whether or not the cake is fresh
- 2 inputs
- Fresh
- Inches of cake
- Output
- Cost of cake
/*
* Buying cake based on if the cake is fresh
* Also dependent on the number of inches of the cake
*
*/
public class BuyingCake {
public static void main(String[] args) {
System.out.print("Is the cake fresh? [True or false]: ");
boolean fresh = IO.readBoolean();
int cost = 0;
if (fresh == false) {
cost = 8;
} else {
System.out.print("What is the cake size in inches? ");
double size = IO.readDouble();
if (size <= 0) {
System.out.println("Error: Where is the Cake? ");
} else if (size <= 8) {
You're Reading a Preview

Unlock to view full version