Member Avatar for mehnihma

When I print out values form the array List I get double space between
outputs:

ϧÏPrint all boats:
ÏϧÏColour=blue Lenght=22 Engine Size=60 Price=$12,800.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=white Lenght=18 Num Sails= 1 Price= $20,000.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=red Lenght=42 Num Sails= 3 Price= $48,000.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=yellow Lenght=35 Engine Size=80 Price=$17,100.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=red Lenght=50 Engine Size=120 Price=$22,400.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=blue Lenght=33 Num Sails= 2 Price= $37,000.00
ÏϧÏ
ÏϧÏ
ÏϧÏColour=white Lenght=14 Engine Size=10 Price=$9,400.00

How to print them without that lines, just one below another?

You need to show the statement(s) you are using to make the print out.
Extra blank lines are usually from extra '\n' (line end)characters in the output String.

Member Avatar for mehnihma

Yes you were right but sill I get one line in between?

What do you think is causing it?

Member Avatar for mehnihma

Yes I figured it out, I had extra println line :D

Thanks, I am doing 3 assaigments this past few days and I do not see much anymore.

Thanks

Ok, good luck

Member Avatar for mehnihma

I have one more question,
can you direc me in the right way to find a specific (most expensive) vvalue in the array list and pring out whole toString of it and to calculate all of the cost ?

way to find a specific (most expensive) value in the array list

Sounds like you need a search in a loop. Get each object out of the array list and compare its value to find the desired value.

print out whole toString of it and to calculate all of the cost

I don't understand your question about printing or calculating the cost.
You need to have an expression for calculating values like cost: A + b - c *.02
That expression would be determined by your application.

Member Avatar for mehnihma


I don't understand your question about printing or calculating the cost.
You need to have an expression for calculating values like cost: A + b - c *.02
That expression would be determined by your application.

I Need to calculate values that are calculated for each boat but now sure how to do it

Member Avatar for mehnihma

I now how to calculate them when there are only numbers but here i have a lot of inputs so I am not sure what to do

Do you have the equation or formula for calculating those values? You will need that before you can write any code.

Member Avatar for mehnihma

Yes I have done that , you can see them in class Sailboat and PowerBoat on page 2.
Now I need to take calculated values and sum them and also find most expensive boat an print out whole toString, if I explained it right?

Can you explain your problem with summing the calculated values?

Member Avatar for mehnihma

I need to take calculated value for each boat and sum them together and I am not sure how to do that

I need to take calculated value for each boat

Do you have the equation or formula for calculating those values?
I can not tell you how to compute those values. It must be given in the assignment description.

Member Avatar for mehnihma

this is from the assignment:

After the code in the previous step, add the code to calculate the total price of all of the sail boats and power boats in the collection.
Also, add code that will find the most expensive boat in the collection and print out the toString information about that boat.

I just need to sum outputted values and find the most expensive one

code to calculate the total price of all

Sorry, that sounds so simple I must be missing something. If you have a list of items with costs, you calculate the total cost by adding up the individual costs of the items in the list.

You find the largest by comparing them against each other as you go through the list.

Member Avatar for mehnihma

The problem is that that cost is calculated from the input values and I need to take it now and sum it, but how , how can I find it in the array?

Perhaps you need to go back and change your design so that the values are stored with the other data in the objects and the objects are in a list that you can go through to get the individual costs for this calculation and search for the most expensive.

Member Avatar for mehnihma

I do not understand that?

How I can do it when I need to calculate cost which deepens ont that inpust which are given.

You need to save any data that is needed to compute the costs in the class object with all the other data that was read in for that item.

Member Avatar for mehnihma

how to do that?

I don't know what data is entered or what variables you have in the class.

How is the cost computed? What data is used? Is that data in the class?

If it is not in the class, you need to add it to the class.

Member Avatar for mehnihma

calculation

// Calculates the price of the PowerBoat as follows: $5000 + length of boat x $300 + size of engine x $20
      public double calcPrice()
      {
         return 5000 + lengthBoat * 300 + sizeofEngine * 20;
      }

input

// A 50 ft. red power boat with a 120 horsepower engine
         powerboat3.setLengthBoat(50);
         powerboat3.setColour("red");
         powerboat3.setSizeOfEngine(120);
      
         boat.add(powerboat3);	//adds fifth powerboat

output:

Print all boats:
Colour=blue Lenght=22 Engine Size=60 Price=$12,800.00
Colour=white Lenght=18 Num Sails= 1 Price= $20,000.00
Colour=red Lenght=42 Num Sails= 3 Price= $48,000.00
Colour=yellow Lenght=35 Engine Size=80 Price=$17,100.00
Colour=red Lenght=50 Engine Size=120 Price=$22,400.00
Colour=blue Lenght=33 Num Sails= 2 Price= $37,000.00
Colour=white Lenght=14 Engine Size=10 Price=$9,400.00

calcPrice()
Does that method return what you need for the cost of an item?

Member Avatar for mehnihma

yes it does
but i have it in two classes, sailboat and powerboat

That's ok. Do they have the same methods?
Where are the objects for the two classes saved?

Member Avatar for mehnihma

sailbot:

// Calculates the price of the SailBoat as follows: length of boat x $1000 + number of sails x $2000.
   
      public double calcPrice()
      {
         return (lengthBoat * 1000) + (numberOfSails * 2000);
      }

powerboat

// Calculates the price of the PowerBoat as follows: $5000 + length of boat x $300 + size of engine x $20
      public double calcPrice()
      {
         return 5000 + lengthBoat * 300 + sizeofEngine * 20;
      }

for objects:

PowerBoat powerboat = new PowerBoat(); //create an object of the PowerBoat class
		SailBoat sailboat = new SailBoat(); //create an object of the SailBoat class
		SailBoat sailboat1 = new SailBoat(); //create an object of the SailBoat class
		PowerBoat powerboat2 = new PowerBoat(); //create an object of the PowerBoat class
		PowerBoat powerboat3 = new PowerBoat(); //create an object of the PowerBoat class
		SailBoat sailboat2 = new SailBoat(); //create an object of the SailBoat class
		PowerBoat powerboat4 = new PowerBoat(); //create an object of the PowerBoat class

You need to put all the boat objects into a list so you can use a loop to sum their costs and search for the largest cost.

This was described several times in earlier posts.
In a loop:
Use only ONE variable to create an object.
Fill that object with its data
When the object has all its data, put that object into the array list.
loop back to top of loop

When you are done, the array list will contain all the objects you have created in the loop.

Member Avatar for mehnihma

problem is that this data i put myself in the code so I dont understand how to do it this way and with a loop
I know hot to do it when user input is required but like this I am confused....

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.