-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class Balloon { | ||
private double radius; | ||
|
||
public Balloon() { | ||
radius = 0; | ||
} | ||
|
||
public void inflate(double amount) { | ||
radius += amount; | ||
} | ||
|
||
public double getVolume() { | ||
return 4.0 / 3.0 * Math.PI * Math.pow(radius, 3); | ||
} | ||
|
||
|
||
public static void main(String... args) { | ||
Balloon balloon = new Balloon(); | ||
balloon.inflate(10); | ||
System.out.println("Balloon volume: " + balloon.getVolume()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class Student { | ||
private String name; | ||
private int totalQuizScore; | ||
private int numberOfQuizzes; | ||
|
||
public Student(String name) { | ||
this.name = name; | ||
this.totalQuizScore = 0; | ||
this.numberOfQuizzes = 0; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void addQuiz(int score) { | ||
totalQuizScore += score; | ||
numberOfQuizzes++; | ||
} | ||
|
||
public int getTotalScore() { | ||
return totalQuizScore; | ||
} | ||
|
||
public int getAverageScore() { | ||
return totalQuizScore / numberOfQuizzes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class StudentTester { | ||
public static void main(String... args) { | ||
Student student = new Student("John Doe"); | ||
student.addQuiz(10); | ||
student.addQuiz(20); | ||
student.addQuiz(30); | ||
System.out.println("Student name: " + student.getName()); | ||
System.out.println("Student total score: " + student.getTotalScore()); | ||
System.out.println("Student average score: " + student.getAverageScore()); | ||
} | ||
} |