Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

EXCERCISE3

public class BankAccount {

string accountNumber;

double balance;

public BankAccount(string accountNumber,double balance) {

this.accountNumber = accountNumber;

this.balance = balance;

public double getBalance() {

return balance;

public void deposit(double amount) {

double newBalance = balance + amount;

newBalance = balance;

System.out.println(“the new balance is” +getBalance());

public void withdraw(double amount) {

balance - = amount;

System.out.println(“the current balance is” + getBalance());

Public static void main(String[] args) {

BankAccount BA1 = new BankAccount(abcd,50.10);

BA1.deposit();

BA1.withdraw();

System.out.println(“the balance is” + BA1.getBalance());

BankAccount BA2 = new BankAccount(efgh,100.00);


BA2.deposit();

BA2.withdraw();

System.out.println(“the balance is” + BA2.getBalance());

public class Circle {

Double radius;

Public Circle(double radius) {

this.radius = radius;

public double getArea() {

return radius * radius * Math.PI;

Public double getCircumfrence() {

return 2 * radius * Math.PI;

Public static void main(String[] args) {

Circle circle1 = new Circle(2.0);

Circle1.getArea();

Circle1.getPerimeter();
Circle circle2 = new Circle(3.0);

Circle2.getArea();

Circle2.getPerimeter();

public class Person {

string name;

int age;

string address;

public Person(string name,int age,string address) {

this.name = name;

this.age = age;

this.address = address;

public string getName() {

return name;

public int getAge() {

return age;

public string getAddress() {

return address;

Public void setAddress(string address) {

this.address = address;

}
Public static void main(String[] args) {

Person person1 = new Person(Hamza,22,Legonstreet);

Person1.getName();

Person1.getAge();

Person1.getAddress();

Person1.setAddress(Opkonglo);

Person person2 = new Person(Baaba,20,Opkonglo);

Person2.getName();

Person2.getAge();

Person2.getAddress();

Person2.setAddress(Legonstreet);

Public class Car {

string make;

string model;

int year;

double speed;

public Car(string make,string model,int year,double speed) {

this.make = make;

this.model = model;

this.year = year;
this.speed = speed;

public string getMake() {

return make;

Public string getModel() {

Return model;

public int getYear() {

return year;

public double getSpeed() {

return speed;

public` double accelerate() {

speed += 10;

public double break() {

speed - = 7;

Public static void main(String[] args) {

Car car1 = new Car(metal,Chinese,2023,5000.00);

car1.getMake();

car1.getModel();

car1.getYear();

car1.getSpeed();

car1.accelerate();
car1.break();

Car car2 = new Car(plastic,Ghanaian,2023,8000.00);

car2.getMake();

car2.getModel();

car2.getYear();

car2.getSpeed();

car2.accelerate();

car2.break();

You might also like