Course Hero Logo

Assignment3.pdf - Q1. package fppassignment3; public class...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 9 pages.

Q1.packagefppassignment3;publicclassTelevision {Television(Stringbrand,intsize){this.MANUFACTURER=brand;this.SCREEN_SIZE=size;this.powerOn=false;this.volume= 50;this.channel= 1;}privatefinalStringMANUFACTURER;privatefinalintSCREEN_SIZE;privatebooleanpowerOn;privateintchannel;privateintvolume;publicintgetChannel() {returnchannel;}publicbooleanisPowerOn() {returnpowerOn;}publicvoidsetChannel(intchannel) {this.channel=channel;}publicString getMANUFACTURER() {returnMANUFACTURER;}publicintgetSCREEN_SIZE() {returnSCREEN_SIZE;}publicintgetVolume() {returnvolume;}publicvoidpower() {if(this.powerOn)this.powerOn=false;elsethis.powerOn=true;}publicvoidincreaseVolume(){if(this.volume<100)this.volume+= 5;}publicvoiddecreaseVolume(){if(this.volume>1)this.volume-= 5;}publicstaticvoidmain(String[]args) {Televisiontv=newTelevision("Sony", 42);System.out.println("This TV is made by "+tv.getMANUFACTURER() +" and hasa size of "+tv.getSCREEN_SIZE() +"\"");tv.power();checkPower(tv.isPowerOn());System.out.println("Currently, the tv volume is "+tv.getVolume());for(inti=0;i<3;i++)tv.increaseVolume();System.out.println("Currently, the tv volume is "+tv.getVolume());for(inti=0;i<7;i++)tv.decreaseVolume();System.out.println("Currently, the tv volume is "+tv.getVolume());System.out.println("The channel is set to "+tv.getChannel());
tv.setChannel(22);System.out.println("The channel is set to "+tv.getChannel());tv.power();checkPower(tv.isPowerOn());}publicstaticvoidcheckPower(booleancheck){System.out.print("The tv power is ");//A static method that just takesthe boolean value andif(check) System.out.print("on.\n");//prints out whether the power ison or notelseSystem.out.print("off.\n");//Used by me to simplify the powerchecking}}OUTPUT:The tv power is on.Currently, the tv volume is 50Currently, the tv volume is 65Currently, the tv volume is 30The channel is set to 1The channel is set to 22The tv power is off.Q2.packagefppassignment3;importjava.util.Random;publicclassPairOfDice {publicintdie1;// Number showing on the first die.publicintdie2;// Number showing on the second die.Randomrnd=newRandom();publicPairOfDice() {// Constructor. Rolls the dice, so that they initially// show some random values. Call the roll() method to roll the dice.this.roll();}publicPairOfDice(intval1,intval2) {// Constructor. Creates a pair of dice that// are initially showing the values val1 and val2.this.die1=val1;this.die2=val2;}publicvoidroll() {// Roll the dice by setting each of the dice (die1, die2) to be// a random number between 1 and 6.this.die1=rnd.nextInt(6)+1;this.die2=rnd.nextInt(6)+1;}publicstaticvoidmain(String[]args) {// Create two object for the PairOfDice// Roll the two pairs of dice for both objects until the totals are same.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 9 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
heart rate, System out println

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture