sotvisal -4 Newbie Poster
import javax.swing.*;
class Customer
{
    int id,rate,pre,cur;
    String name,sex;

    String read(String n)
    {   return JOptionPane.showInputDialog(n);  }

    int readInt(String n)
    {   return Integer.parseInt(read(n));   }

    void out(String n)
    {   JOptionPane.showMessageDialog(null,n);  }

    public Customer()
    {
        id=1;
        name="Visal";
        sex="Male";
        pre=13214;
        cur=13362;
        rate=720;
    }

    int consumption(int pre,int cur)
    {   return(cur-pre);    }

    int payment(int rate)
    {   return(rate*consumption(pre,cur));  }

    void input()
    {
        read("Enter ID: ");
        read("Enter Name: ");
        read("Enter Sex: ");
        read("Previous: ");
        read("Current: ");
        read("Rate: ");
    }

    void output()
    {
        out("ID: " +id);
        out("Name: " +name);
        out("Sex: " +sex);
        out("Previous: " +pre);
        out("Current: " +cur);
        out("Rate: " +rate);
        out("Consumption: " +consumption(pre,cur));
        out("Payment: " +payment(rate)+ " Riels or " +payment(rate)/4100+ " $.");
    }
}

class Light
{
    Customer cus[]=new Customer[20];
    public Light()
    {
        long total=0;
        int n=Integer.parseInt(JOptionPane.showInputDialog("Enter Value N: "));
        for(int i=1;i<=n;i++)
            cus[i].input();
        for(int i=1;i<=n;i++)
            cus[i].output();
    }
    public static void main(String[] args)
    {   new Light();    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.