Hi;
See the code below;

import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Data dt = new Data("Name", "Last", "Somewhere on earth", "Student");
        dt.setUnitPrice(10.96);
        dt.setQuantity(69);
        dt.calculateTotal(0.75);
        System.out.println(dt.toString());
        return;
    }

}

class Data {
    private String f_name, l_name, address, job;
    private int quantity;
    private double single_price, total ,discount;

    public Data(String f_name, String l_name, String address, String job) {
        this.f_name = f_name;
        this.l_name = l_name;
        this.address = address;
        this.job = job;
        this.single_price = this.total = this.quantity = 0;
    }

    public Data(String f_name, String l_name) {
        this(f_name, l_name, "", "");
    }

    public void setUnitPrice(double price) {
        this.single_price = price;
    }

    public void setQuantity(int qt) {
        this.quantity = qt;
    }

    public double calculateTotal() {
        return this.calculateTotal(0);
    }

    public double calculateTotal(double discount) {
        this.discount = discount;
        this.total = this.single_price * this.quantity * ( 1 - discount );
        return this.total;
    }

    public String toString() {
        return this.l_name + ", "  + this.f_name + "\n" + this.address +
"\n" +
            this.job + "\n" + this.quantity + " each at " +
/*Double.formatDouble(*/this.single_price/*, 2)*/ +
            "$" + " costs " + this.total + "$. " + ((this.discount != 0) ?
("(Discount of " + this.discount * 100 + "%.)\n") : (""));
    }
}

With the hope of rising of Mahdi;
Ali Shakiba
Shahid Bahonar University of Kerman
Iran - Kerman


On Sun, Jan 24, 2010 at 8:38 AM, Craig Jensen <[email protected]>wrote:

> This makes sense now, but I still have difficulty understanding the correct
> method of then getting the information from the array to print or whatever
> so each Identification item can display as a whole (i.e. with all variables
> from the class displayed for an instance of object 'Identification'.
>
> The array understanding that does not follow is that of the indices for the
> objects shich is why I don't understand how you would correctly code a
> method to get an instance of the array...?
>
> BTW thank you for the reference to creation of an array of Objects. My
> study had not made rererence to this as an option, only that arrays had to
> hold instances of the same type.
>
> Craig
>
>
> On Fri, Jan 22, 2010 at 11:26 PM, Ali Shakiba <[email protected]>wrote:
>
>> Hi;
>> Sure; it is possible;
>> Just define your data type as this; code written in gmail editor
>>
>> class Identification {
>> public String
>> first, last, address, city, state;
>> public double singlePrice, total;
>> public int number;
>> }
>>
>> then in your main class; or code;
>>
>> Identification[] ids = new Identification[50];
>>
>> With the hope of rising of Mahdi;
>> Ali Shakiba
>> Shahid Bahonar University of Kerman
>> Iran - Kerman
>>
>>
>> On Sat, Jan 23, 2010 at 7:34 AM, Craig Jensen 
>> <[email protected]>wrote:
>>
>>> Is it possible?
>>>
>>> Sample:
>>>
>>> My app prompts the user for input of first name, last name, address,
>>> city, state, etc plus two double elements. Each of these groups equal on
>>> element to display
>>> (i.e.
>>> {
>>> Joe Blow
>>> 123 S Main st.
>>> Somewhere, Tx 83999
>>> number of widgets = 33
>>> price per widget = 22
>>> total spent on widgets = $726.00
>>> }
>>>
>>> All elements are of typs String except the number of widgets (float) and
>>> total spent per widget (double).
>>> I collect this information for a set number of people, then terminate
>>> with a summary of total spent per person.
>>>
>>>
>>> Can this dataset be stored in an array to allow it to be retrieved as a
>>> single array element (the data {between the curly braces} above), for each
>>> person entered?
>>>
>>> Possible?
>>>
>>> --
>>> To post to this group, send email to
>>> [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]<javaprogrammingwithpassion%[email protected]>
>>> For more options, visit this group at
>>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>>>
>>
>>  --
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<javaprogrammingwithpassion%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>>
>
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to