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

Info icon This 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()
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern