You have received some excellent, specific advice here.
If you want to graduate at the top of your class, that also includes scoring well in other grades categories than academic, such as military aptitude, honor, conduct, physical fitness, etc. You cannot afford to ignore those areas. You will be among a group of classmates who have similar, better, or far better records and backgrounds than you. Do your best, be prepared to adjust your goals as you go.
You are there to learn other things and develop other skills than just a narrow academic achievement list.
I cannot echo enough the advice about the minute you start to struggle, you seek out EI (extra instruction) with the professor, participate in informal peer tutoring in company, take advantage of the academic center’s many offerings. Be sure to explore the hamburger menu in the upper left.
Good study habits boil down to differentiating between needs vs. wants - what do you need to do, what would you like to do. Self-discipline. Good sleep hygiene. Organization. Use of time. Most midshipmen spend a chunk of time on the weekend working on assignments. Prudent participation in ECAs, but don’t interfere unduly with “needs.” Balance with your other graded areas.
There is plenty of time to choose a major. You’ll get briefs, talk to upperclass in the major, have an academic advisor. Be open to all the opportunities and paths - good life advice too.
Do you have an offer of appointment to Class of 2027? Or are you starting application? If the latter, you have a few near-term hurdles to maneuver. Be sure to develop alternate plans.