Write a class Watch that has the following (20 pts) Instance Variables Type- ass
ID: 3570364 • Letter: W
Question
Write a class Watch that has the following (20 pts) Instance Variables Type- assumed to be the name brand Hours-assumed to be 12 hour watch Minutes Constructors A default constructor set the type, hours and minutes to some default value ii. Another constructor that takes a type, an hourly value, and a minute as parameters and sets those values (making sure each value is valid) Accessors and Mutators for each instance variable MAKE SURE TO CHECK FOR VALID VALUES! Methods A method increaseHour which increases the hour by 1. Remember to take into account this is a 12 hour watch. ii. A method increaseMinute which increases the minute by 1. Remember there are only 60 minutes in an hour and if it is equal to that it should reset and increase the hour by 1. Static Methods A method makeCasio which returns a new instance of a Casio calculator watch, the best type of watch, whose set time is 1:23.Explanation / Answer
public class Watch
{
private String type;
private int hours;
private int minutes;
public Watch() {
super();
this.type = null;
this.hours = 0;
this.minutes = 0;
}
public Watch(String type, int hours, int minutes) {
super();
this.type = type;
if(hours >= 1 && hours <= 12)
this.hours = hours;
else
System.out.println("Wrong input for hours");;
if(minutes >= 0 && minutes <= 59)
this.minutes = minutes;
else
System.out.println("Wrong input for minutes");;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
if(hours >= 1 && hours <= 12)
this.hours = hours;
else
System.out.println("Wrong input for hours");;
}
public int getMinutes() {
return minutes;
}
public void setMinutes(int minutes) {
if(minutes >= 0 && minutes <= 59)
this.minutes = minutes;
else
System.out.println("Wrong input for minutes");;
}
public void increaseHour(){
int hours = this.hours + 1;
if(hours >= 1 && hours <= 12)
{
this.hours = 1;
}
else
{
this.hours = hours;
}
}
public void increaseMinute(){
int min = this.minutes + 1;
if(min > 59)
{
this.minutes = 1;
}
else
{
this.minutes = min;
}
}
public static Watch makeCasio(){
Watch casio = new Watch("Casio", 1, 23);
return casio;
}
@Override
public String toString() {
return "Watch [type=" + type + ", hours=" + hours + ", minutes="
+ minutes + "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.