Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Calculator {

public static double add(double a, double b) {
return a + b;
}

public static double subtract(double a, double b) {
return a - b;
}

public static double multiply(double a, double b) {
return a * b;
}
public static double divide(double a, double b) {
if (b == 0) {
// final agreed behavior
throw new ArithmeticException("Cannot divide by zero");
}
// keep rounding from master (or remove if you prefer)
return Math.round((a / b) * 100.0) / 100.0;
}

}
16 changes: 13 additions & 3 deletions HelloWorld.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
public static void main(String[] args) {
Student s = new Student("Alice", 20);
System.out.println("Student Name: " + s.getName());
System.out.println("Student Age: " + s.getAge());

System.out.println("2 + 3 = " + Calculator.add(2, 3));
System.out.println("7 - 4 = " + Calculator.subtract(7, 4));
System.out.println("6 * 5 = " + Calculator.multiply(6, 5));
System.out.println("8 / 2 = " + Calculator.divide(8, 2));



}
}
30 changes: 30 additions & 0 deletions Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Student {
private String name;
private int age;

// Constructor
public Student(String name, int age) {
this.name = name;
this.age = age;
}

// Getter for name
public String getName() {
return name;
}

// Setter for name
public void setName(String name) {
this.name = name;
}

// Getter for age
public int getAge() {
return age;
}

// Setter for age
public void setAge(int age) {
this.age = age;
}
}