How we know the number of stars in our galaxy and weight of stars and planets
Both answers usually depend upon Kepler's Third Law of planetary motion (see http://cseligman.com/text/history/kepler3.htm
), which relates the motions of objects in a system to its mass. Specifically, the mass times the square of an orbital period is proportional to the cube of the size of the orbit. This means that if you know how big the orbit is and how long it takes to go once around (which is the period), you can calculate the mass involved.
For a planet, you need a moon going around it to find the mass, though you can also calculate the mass of planets without moons as long as something passes by the planet. In that case you use the deflection of the passing object by the planet's gravity. The mathematics is a little more complicated, but the mass can still be determined as accurately as the deflection involved.
For stars, you need a planet or another star going around them to make a direct measurement. In the case of stars that don't have planets or companions you can usually estimate the mass by examining the nature of the star, and comparing it to similar stars that have known masses. In the case of so-called Main Sequence stars this works very well (see http://cseligman.com/text/stars/mldiagram.htm
), but for non-Main Sequence stars without companions estimates of mass are more just that -- estimates.
For galaxies, we usually use the speed of orbital motion determined from visual or radio wave studies and the size of the galaxy to calculate the time required for one rotation (about 150 million years for our galaxy), then apply Kepler's Third Law to determine the overall mass. This does not tell us the number of stars in the galaxy, but studies of the relative numbers of stars of different masses gives us an "average" mass per star, and dividing that into the total mass yields an estimate of the number of stars. Unfortunately, in this case, there is a significant problem, in that we can also estimate the mass of the galaxy (particularly other galaxies, which we see from the outside, and therefore have a better view than for our own galaxy) by seeing how bright it is. By doing a survey of the relative numbers of stars of different brightnesses we can use the overall brightness of a galaxy to estimate the number of stars inside it. It was originally presumed that the two methods of determining the number of stars (total mass divided by average mass per star, and total brightness divided by average brightness per star) would yield about the same number of stars. But the two results do NOT yield the same number. In virtually every case, the number of stars required to provide the mass measured for a galaxy is about ten times the number of stars required to provide the brightness of the galaxy. This means that 90% of the mass is not giving off as much light of normal stars, and is the reason we believe that some kind of "dark" matter makes up most of the mass of individual galaxies, and by extension, groups of galaxies and the entire Universe (see http://cseligman.com/text/galaxies/dark.htm
By referring you to several pages on my website, I am avoiding a direct discussion of many of the details involved in this answer. If all you wanted was a brief, more or less to the point answer, that is probably preferable to going over those details. But if you wanted a more detailed discussion you'll need to read this, refer to the pages in question, then re-read this discussion. If that makes this reply less than satisfactory, please feel free to send a follow-up question for anything you would like to have clarified.