Java method query


Joined
Mar 16, 2021
Messages
1
Reaction score
0
Please anybody help me to find out the error?

import java.util.*;

public class Customer {
public String customerId;
public String customerName;
public long contactNumber;
public String address;
public void displayCustomerDetails() {
System.out.println("Displaying customer details \n***********");
System.out.println("Customer Id : " + customerId);
System.out.println("Customer Name : " + customerName);
System.out.println("Contact Number : " + contactNumber);
System.out.println("Address : " + address);
System.out.println();
}

public void payBill(double totalPrice, double discountPercentage) {
System.out.println("Calculating final amount to be paid......");
double priceAfterDiscount = totalPrice * (1 - (discountPercentage / 100));
System.out.println("Hi " + customerName + ", your final bill amount after discount is: " + (int) (priceAfterDiscount * 100) / 100.0);
}

class Test{
public static void main(String args[]) {
Customer customer = new Customer();
customer.customerId = "C101";
customer.customerName = "Stephen Abram";
customer.contactNumber = 7856341287L;
customer.address = "D089, St. Louis Street, Springfield, 62729";
customer.displayCustomerDetails();
}
customer.payBill(500, 10);
}
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
28
Reaction score
6
Check your curly braces. Customer is missing one between payBill and class Test. Also, customer.payBill is outside of the main method.
 
Ad

Advertisements

Joined
Apr 27, 2021
Messages
1
Reaction score
0
Java:
public class Customer {

    public String customerId;
    public String customerName;
    public long contactNumber;
    public String address;

    public void displayCustomerDetails() {
        System.out.println("Displaying customer details \n***********");
        System.out.println("Customer Id : " + customerId);
        System.out.println("Customer Name : " + customerName);
        System.out.println("Contact Number : " + contactNumber);
        System.out.println("Address : " + address);
        System.out.println();
    }

    public void payBill(double totalPrice, double discountPercentage) {
        System.out.println("Calculating final amount to be paid......");
        double priceAfterDiscount = totalPrice * (1 - (discountPercentage / 100));
        System.out.println("Hi " + customerName + ", your final bill amount after discount is: " + (int) (priceAfterDiscount * 100) / 100.0);
    }
}
    class Test {

        public static void main(String args[]) {
            Customer customer = new Customer();
            customer.customerId = "C101";
            customer.customerName = "Stephen Abram";
            customer.contactNumber = 7856341287L;
            customer.address = "D089, St. Louis Street, Springfield, 62729";
            customer.displayCustomerDetails();
            customer.payBill(500, 10);
        }
    }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top