Saturday, October 26, 2019

Essay --

import java.util.ArrayList; import java.util.Arrays; /** * */ /** * @author sharonim * */ public class CarRadio { private StationData data; private boolean power; private int frequency; private String bandAMFM; private int volume; private boolean mute; private boolean set; private int[] AMpreset; private int[] FMpreset; public static final int Vol_min = 0; public static final int Vol_max = 20; public CarRadio(StationData d){ this.data = d; this.power = false; this.frequency = FreqBand.AM.minFreq(); this.bandAMFM = "AM"; this.volume = 0; this.mute = false; this.set = false; this.AMpreset = new int[5]; this.FMpreset = new int[5]; Arrays.fill(FMpreset, FreqBand.FM.minFreq()); Arrays.fill(AMpreset, FreqBand.AM.minFreq()); } public void powerBtn(){ if(this.power == false){ this.power = true; } else{ this.power = false; } clear(); } public void volumeUpBtn(){ if(this.power == true){ if(this.volume == Vol_max){ return; } else{ this.volume++; } } else{ return; } } public void volumeDownBtn(){ if(this.power == true){ if(this.volume == Vol_min){ return; } else{ this.volume--; } } else{ return; } } public void muteBtn(){ if(this.power == true){ if(this.mute == false){ this.mute = true; } else{ this.mute = false; } } else{ return; } } public void amfmBtn(){ if(this.power == true){ clear(); if(this.bandAMFM == "AM"){ this.bandAMFM = "FM"; this.frequency = FreqBand.FM.minFreq(); } else{ this.bandAMFM = "AM"; this.frequency = FreqBand.AM.minFreq(); } } } public void tuneUpBtn(){ if(this.power == true){ clea... ... == true){ if(this.set == true){ setPreset(3); clear(); } else{ usePreset(3); clear(); } } else{ return; } } public void preset5Btn(){ if(this.power == true){ if(this.set == true){ setPreset(4); clear(); } else{ usePreset(4); clear(); } } else{ return; } } public ArrayList display(){ ArrayList output = new ArrayList(); output.add("Power: " + power); output.add("Band: "+ bandAMFM); output.add("Frequency: " + frequency); output.add("Volume: " + volume); output.add("Mute: " + mute); output.add("FM Preset: " + FMpreset[0] + " " + FMpreset[1] + " " + FMpreset[2] + " " + FMpreset[3] + " " + FMpreset[4]); output.add("AM Preset: " + AMpreset[0] + " " + AMpreset[1] + " " + AMpreset[2] + " " + AMpreset[3] + " " + AMpreset[4]); return output; } }

No comments:

Post a Comment