How arrange? Pls come help...thx

i want ask is how to arrange the diferent string in sequnece?

Example:

me store in array

type[0] = new Service("Cut",8.00,15);

type[1] = new Service("Shampoo",4.00,10);

type[2] = new Service("Manicure",18.00,30);

type[3] = new Service("Style",48.00,55);

type[4] = new Service("Permament",18.00,35);

type[5] = new Service("Trim",6.00,5);

i want that output like this(String only) :

Cut

Manicure

Permament

Shampoo

Style

Trim

*If possible pls teach me how to code it...^^ thx

[575 byte] By [Suqina] at [2007-11-27 11:20:17]
# 1

What have you tried so far?

If these were not in an array then how would print the String value? What is a service Object? Where does the String passed into the constructor get set?

Message was edited by:

_helloWorld_

_helloWorld_a at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 2

that service store all this:

String Service;

double Price;

int AvgMin;

AlignmentService align = new AlignmentService();

public Service()

{

}

public Service(String s, double p, int a)

{

Service = s;

Price = p;

AvgMin = a;

}

public void setSERVICE(String s)

{

Service = s;

}

public void setPRICE(double p)

{

Price = p;

}

public void setAVGMIN(int a)

{

AvgMin = a;

}

public String getSERVICE()

{

return Service;

}

public double getPRICE()

{

return Price;

}

public int getAVGMIN()

{

return AvgMin;

}

public String toString()

{

return getSERVICE()+"\t\t"+align.right(getPRICE(),6)+"\t\t\t"+align.a(getAVGMIN(),8);

}

Message was edited by:

Suqin

Suqina at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 3

> i want that output like this(String only) :

> *If possible pls teach me how to code it...^^ thx

just correction .. you should have type .. fix my code, not teach me...

because like that you'll be just doing the hardest part copying and pasting and then run, and the easy part was done by someone else..

show some code and where is your problem, and am ready to help...

QussayNajjara at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 4

Try this:

type[0].getSERVICE() // in a print statement.

This will print your service value for the element at [0]. You then need to iterate over a loop to do it for all.

And you should be using getService() instead.

_helloWorld_a at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 5

okok...

i will try 1st after just ask agian...^^

Suqina at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 6

consider having Service implement the interface Comparable. Look that interface up. You may find that it has what you need as far as sorting your array.

Message was edited by:

petes1234

petes1234a at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...
# 7

This is my TestService.java:

import java.io.*;

class TestService

{

public static void main(String args[]) throws IOException

{

Service type[] = new Service[6];

AlignmentService align = new AlignmentService();

for (int i=0;i<type.length;i++)

{

type = new Service();

}

type[0] = new Service("Cut",8.00,15);

type[1] = new Service("Shampoo",4.00,10);

type[2] = new Service("Manicure",18.00,30);

type[3] = new Service("Style",48.00,55);

type[4] = new Service("Permament",18.00,35);

type[5] = new Service("Trim",6.00,5);

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int select;

System.out.println("Print the report by :");

System.out.println("1. Service");

System.out.println("2. Price");

System.out.println("3. Time");

System.out.println("4. Exit");

System.out.print("\n");

System.out.print("Enter the selection : ");

select = Integer.parseInt(br.readLine());

if (select==1)

{

System.out.println("Service\t\t\tPrice($)\t\tTime (Minute)");

System.out.println("=======\t\t\t========\t\t=============");

// At here me stuck dont know how to contineu..^^

}

This is my Test.java:

class Service

{

String Service;

double Price;

int Min;

AlignmentService align = new AlignmentService();

public Service()

{

}

public Service(String s, double p, int a)

{

Service = s;

Price = p;

Min = a;

}

public void setSERVICE(String s)

{

Service = s;

}

public void setPRICE(double p)

{

Price = p;

}

public void setAVGMIN(int a)

{

Min = a;

}

public String getSERVICE()

{

return Service;

}

public double getPRICE()

{

return Price;

}

public int getMIN()

{

return Min;

}

public String toString()

{

return getSERVICE()+"\t\t\t"+align.right(getPRICE(),6)+"\t\t\t"+align.a(getMIN(),8);

}

}

Message was edited by:

Suqin>

Suqina at 2007-7-29 14:41:46 > top of Java-index,Java Essentials,Java Programming...