Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Please. I keep getting this error. How do i fix it please. Mountain.java: 1 : error: duplicate class: Mountain public class Mountain {

In Java Please. I keep getting this error. How do i fix it please.
Mountain.java:1: error: duplicate class: Mountain
public class Mountain {
^
1 error
import java.util.ArrayList;
import java.util.List;
class Mountain {
private String name;
private String country;
private double elevation;
public Mountain(String name, String country, double elevation){
this.name = name;
this.country = country;
this.elevation = elevation;
}
public String getName(){
return name;
}
public String getCountry(){
return country;
}
public double getElevation(){
return elevation;
}
// Define a method to convert the elevation from feet to meters.
public double toMeters(){
return elevation /3.2808;
}
}
class Main {
public static void main(String[] args){
List mountains = new ArrayList<>();
mountains.add(new Mountain("Chimborazo", "Ecuador", 20549));
mountains.add(new Mountain("Matterhorn", "Switzerland", 14692));
mountains.add(new Mountain("Olympus", "Greece (Macedonia)",9573));
mountains.add(new Mountain("Everest", "Nepal", 29029));
mountains.add(new Mountain("Mount Marcy - Adirondacks", "United States", 5344));
mountains.add(new Mountain("Mount Mitchell - Blue Ridge", "United States", 6684));
mountains.add(new Mountain("Zugspitze", "Switzerland", 9719));
Mountain minElevationMountain = minElevation(mountains);
System.out.println("Mountain\tCountry\tElevation (ft)\tElevation (m)");
for (Mountain mountain : mountains){
System.out.printf("%s\t%s\t%.0f\t%.2f%n", mountain.getName(), mountain.getCountry(), mountain.getElevation(), mountain.toMeters());
}
System.out.printf("%nShortest mountain: %s with elevation %.0f ft (%.2f m)%n", minElevationMountain.getName(), minElevationMountain.getElevation(), minElevationMountain.toMeters());
}
public static Mountain minElevation(List mountains){
Mountain minElevationMountain = mountains.get(0);
for (Mountain mountain : mountains){
if (mountain.getElevation()< minElevationMountain.getElevation()){
minElevationMountain = mountain;
}
}
return minElevationMountain;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What are the purposes of strategic planning?

Answered: 1 week ago

Question

6. What qualifications are needed to perform the job?

Answered: 1 week ago