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

Recommended Answers

All 5 Replies

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

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 .

Will you post source code? Use bb code tags. I will not reply if code tags are not used.

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

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

Read post #2
or
How to use code tags?
You must read this : Homework policy at daniweb

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.