Answer to Question #320552 in Java | JSP | JSF for Kochu

Question #320552

Program to check the addition result is divisible by 10



Class 1 - Return addition result of two numbers



Class 2 -Check the addition result is divisible by 10(use super keyword)

1
Expert's answer
2022-03-29T16:48:07-0400
public class Class1 {
    private double number1;
    private double number2;
    private double sum;

    Class1(double num1, double num2){
        this.number1 = num1;
        this.number2 = num2;
        setSum();
    }
    public void setSum(){
        this.sum = this.number1 + this.number2;
    }
    public double getSum(){
        return this.sum;
    }
}
import java.util.Scanner;

public class Class2 extends Class1{
    private boolean isDivisibleBy10;

    Class2(double num1, double num2){
        super(num1, num2);
        isDivisibleBy10(super.getSum());
    }
    public boolean getIsDivisibleBy10(){
        return this.isDivisibleBy10;
    }
    public void isDivisibleBy10(double sum){
        this.isDivisibleBy10 = false;
        if (sum % 10 == 0){
            this.isDivisibleBy10 = true;
        }
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter first number: ");
        double number1 = scanner.nextDouble();
        System.out.print("Enter second number: ");
        double number2 = scanner.nextDouble();
        Class2 class2 = new Class2(number1, number2);
        if (class2.getIsDivisibleBy10()){
            System.out.println("The addition result is divisible by 10");
        }
        else {
            System.out.println("The result of the addition is not divisible by 10");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS