2
2
int sum = 0;
num /= 10;
3.23-Point in a rectangle
import java.util.Scanner;
double x = input.nextDouble();
double y = input.nextDouble();
else {
3.26-Divisibility Check
import java.util.Scanner;
public class DivisibilityCheck {
System.out.println("Is " + num + " divisible by 5 or 6, but not both? " + divBy5or6NotBoth); } }
import java.util.Scanner;
return; }
return; }
4.22-Check substring
import java.util.Scanner;
String s1 = input.nextLine();
String s2 = input.nextLine();
if (s1.contains(s2)) {
else {
import java.util.Date;
id = 0;
balance = 0;
annualInterestRate = 0;
this.id = id;
this.balance = balance;
annualInterestRate = 0;
return id; }
this.id = id; }
return balance; }
this.balance = balance; }
return annualInterestRate; }
this.annualInterestRate = annualInterestRate; }
return dateCreated; }
System.out.println("Insufficient balance."); }
acc.setAnnualInterestRate(4.5);
acc.withdraw(2500);
acc.deposit(3000);
public class Fan { public static final int SLOW = 1; public static final int MEDIUM = 2; public static final int
FAST = 3; private int speed; private boolean on; private double radius; private String color; public Fan() {
speed = SLOW; on = false; radius = 5; color = "blue"; } public int getSpeed() { return speed; } public void
setSpeed(int speed) { this.speed = speed; } public boolean isOn() { return on; } public void setOn(boolean
on) { this.on = on; } public double getRadius() { return radius; } public void setRadius(double radius) {
this.radius = radius; } public String getColor() { return color; } public void setColor(String color) { this.color
= color; } public String toString() { if (on) { return "Fan speed: " + speed + ", color: " + color + ", radius: " +
radius; } else { return "Fan is off, color: " + color + ", radius: " + radius; } } public static void main(String[]
args) { Fan fan1 = new Fan(); fan1.setSpeed(FAST); fan1.setRadius(10); fan1.setColor("yellow");
fan1.setOn(true); Fan fan2 = new Fan(); fan2.setSpeed(MEDIUM); fan2.setRadius(5);
fan2.setColor("blue"); fan2.setOn(false); System.out.println(fan1.toString());
System.out.println(fan2.toString()); } }