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();    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

sotvisal,

Use bb code tags. Your source code must be surrounded with bb code tags.

For example,

[CODE=Java]
... statements
...
[/CODE]

You have an array of 20 student object variables. Now, you have to create 20 objects of student class.

class Light
{
      Customer cus[];
      public Light() {
           long total=0;
                      int n=Integer.parseInt(JOptionPane.showInputDialog 
                                   ("Enter Value N: "));
          // Create an array of n size - where n must be > 1
          cus=new Customer[n];
          for(int i=0;i<n;i++) {
                    cus[i]=new Customer(); // an object of student
                    cus[i].input();
          }
         for(int i=0;i<n;i++)
                   cus[i].output();
     }
public static void main(String[] args) { 
     new Light(); 
 }
} 

Edited 3 Years Ago by happygeek: fixed formatting

Thanks but it didn't work at all and when i inputed 2 customer it just shew only 1 customer could you give me another way friend .

Sorry, my bad friend but i wish too and i don't even know bb code tags
and i don't know how to use it, i only wrote my code in Textpad so please give me another tip friend

This article has been dead for over six months. Start a new discussion instead.