Open vasanth0989 opened 10 months ago
package com.test.quiz;
class Employee {
private String name;
private int age;
private double salary;
private boolean fullTime;
// NoArgument Constructor
public Employee() {
}
// All Argument Constructor
public Employee (String name, int age, double salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
//getters
public String getName() {
return name;
}
//setters
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public boolean isFullTime() {
return fullTime;
}
public void setFullTime(boolean fullTime) {
this.fullTime = fullTime;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
class TestMain {
public static void main(String[] args) {
Employee employee = new Employee();
employee.name = "";
System.out.println("Age:"+employee.getAge());
System.out.println("Salary:"+employee.getSalary());
System.out.println("FullTime:"+employee.isFullTime());
System.out.println("Name:"+employee.getName());
// Instantiating or creating an Object
// You use constructor to create an Object
Employee employee1 = new Employee("Vasanth", 33, 252.2d);
System.out.println("Before"+employee1.getName());
employee1.setName("John");
System.out.println("After:"+employee1.getAge());
}
}
package com.test;
public class Calculator {
private String name;
//no-arg-constructor
public Calculator() {}
// Argument constructor
public Calculator(String name){
this.name = name;
}
//methods
public int add(int num1, int num2){
return num1 + num2;
}
//multiply
public int multiply(int num1, int num2){
return num1 * num2;
}
public int subtract(int num1, int num2){
return num1 - num2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.test;
public class TestMain {
public static void main(String[] args) {
Calculator calculator = new Calculator("Super Awesome Calculator");
calculator.setName("Simple Calculator");
int sum = calculator.add(5,5);
System.out.println("Sum:"+sum);
int sub = calculator.subtract(10, 5);
System.out.println("Sub:"+sub);
int mul = calculator.multiply(4,5);
System.out.println("multiply:"+mul);
// Methods within String
String calName = calculator.getName();
String calUpperCase = calName.toUpperCase();
System.out.println("CalUpperCase:"+calUpperCase);
String calLowerCase = calName.toLowerCase();
System.out.println("CalLowerCase:"+calLowerCase);
System.out.println("These are the results form "+calculator.getName());
}
}
Class Creation