![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS206 Data Structures / 2017-Spring / Notebooks |
void countdown(int n) {
for (int i = n; i > 0; i--) {
printf("%s\n", i);
}
printf("Liftoff!");
}
countdown(10)
countdown(3)
Write a function volume()
that takes an height, width, and length dimensions and returns the volume of a cube with those dimensions.
One possible answer:
double volume(double width, double height, double length) {
return (width * height * length);
}
volume(3, 4, 6)
Define a class to hold students. The constructor should take a name and a year of graduation. Add a method "status" that when called, says: "You are a junior" (or whatever). Assume that the year is 2016.
Student student1 = new Student("Milley Cyrus", 2018);
Student student2 = new Student("Taylor Swift", 2012);
The status is one of:
The beginning of a solution:
class Student {
String name;
int year;
Student(String name, int year) {
this.name = name;
this.year = year;
}
void status() {
printf("You are crazy!");
}
}
Student miley = new Student("Miley Cyrus", 2015);
miley.status()