Engine - public int getRPM() public void setRPM(int r)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * A program that models an engine that can be driven to a maximum * and minimum nuber of revolutions per a minute. * * @author (Luke Wyatt) * @version (v.1.4) */ public class Engine { /* The instance variables are: 'rpm', 'min', 'max', 'increment' (all are private and type int), and are initialized by the constructor */ private int rpm; private int min; private int max; private int increment; /* The static variable is: 'counter' (private, static, int), and should be explicitly initialized to 0*/ private static int counter=0; /* The constructor signature is: public Engine(int Min, int Max, int Inc) The constructor initializes min to Min, max to Max, and increment to Inc. Also initializes 'rpm' to 'Min' */ public Engine(int Min, int Max, int Inc){ min=Min; max=Max; increment=Inc; rpm=min; } /* The method signatures are as follows: public void faster() public void slower()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public int getRPM() public void setRPM(int r) public int getCount() Following the instructions, write the code for each of the above methods below: */ public void faster() { int fasterRPM=rpm+increment; if(fasterRPM>=max){ rpm=max; System.out.println("Warning! Engine rpm reached maximum."); } else { rpm=fasterRPM; } } public void slower(){ int slowerRPM=rpm-increment; if(slowerRPM<=min){ rpm=min; System.out.println("Warning! Engine rpm reached minimum."); } else{ rpm=slowerRPM; } } public int getRPM(){ return rpm; } public void setRPM(int r){ counter++; if(r<min){ rpm=min; System.out.println("Warning! Engine rpm reached minimum."); } else if(r>max){ rpm=max; System.out.println("Warning! Engine rpm reached maximum."); } else { rpm=r; } } public int getCount(){ int Count=counter; return Count; } }...
View Full Document

Page1 / 2

Engine - public int getRPM() public void setRPM(int r)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online