Skip to content

Instantly share code, notes, and snippets.

@Aroueterra
Last active May 20, 2021 11:20
Show Gist options
  • Save Aroueterra/5a1f41cf75b41d3291891ff317ffae8b to your computer and use it in GitHub Desktop.
Save Aroueterra/5a1f41cf75b41d3291891ff317ffae8b to your computer and use it in GitHub Desktop.
//add class definitions below this line
import java.util.*;
class Watch {
private String manufacturer;
private String model;
private int diameter;
private int waterResistance;
private String material;
public Watch(String m, String mo, int d, int w, String ma){
manufacturer = m.toLowerCase();
model = mo.toLowerCase();
diameter = d;
waterResistance = w;
material = ma.toLowerCase();
}
public String summary(){
ArrayList<String> details = new ArrayList<String>();
details.add(getManufacturer());
details.add(getModel());
details.add(getDiameter());
details.add(getWaterResistance());
details.add(getMaterial());
String response = "";
int counter = 0;
for(String detail : details){
if(counter == details.size()-1){
response = response + detail;
}else{
response = response + detail +'\n';
}
counter++;
}
return response;
}
public String sentenceCase(String name){
name = name.substring(0,1).toUpperCase() + name.substring(1).toLowerCase();
return name;
}
public String getManufacturer(){
return "Manufacturer: " + sentenceCase(manufacturer);
}
public String getModel(){
return "Model: " + sentenceCase(model);
}
public String getDiameter(){
return "Diameter: " + sentenceCase(Integer.toString(diameter)) + " mm";
}
public String getWaterResistance(){
return "Water Resistance: " + sentenceCase(Integer.toString(waterResistance)) + " m";
}
public String getMaterial(){
return "Material: " + sentenceCase(material);
}
public void setManufacturer(String m){
manufacturer = m;
}
public void setModel(String m){
model = m;
}
public void setDiameter(int d){
diameter = d;
}
public void setWaterResistance(int w){
waterResistance = w;
}
public void setMaterial(String m){
material = m;
}
}
//add class definitions above this line
public class CodingExercise2 {
public static void main(String[] args) {
//add code below this line
Watch myWatch = new Watch("omega", "speedmaster", 42, 50, "steel");
System.out.println(myWatch.summary());
//add code above this line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment