Why cant i call method to main

–1 vote
asked Apr 7 by Santino (110 points)
import java.util.Scanner;
package lab.pkg3.q2;

public class PropertyCost {
double RATE = 1.1;
double UNITPRICE = 1.4;
double GST = 0.1;
    
    public static void main(String[] args) {
        Scanner fetch = new Scanner(System.in);
        double area, propCost;
        System.out.print("Porperty cost: ");
        area = fetch.nextInt();
        calcTotalCharge();
        
        
    }
    
    
    public double calcTotalCharges(double area){
    double actualArea = area * RATE;
    double propertyCharge = actualArea * UNITPRICE;
    double propertyCost = propertyCharge + propertyCharge * GST;
    System.out.print(propertyCost);
        return propertyCost;
    }
    
}

1 Answer

0 votes
answered Jul 27 by Sushma (160 points)

In main method call calcTotalCharge() method with parameter and return type of  calcTotalCharge() assign to a variable and better to use static keyword in function defination or you can create an object for that class and with that help you can call that function.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...