/* The first assignment asks you to convert the following C++ program into Java, then make some additions to the java program. You are expected to have read the C++ to Java tutorial. For the Adams 204 linux workstations, enter the following in your ~/.bashrc file: export PATH=/opt/jdk1.5.0_07/bin:$PATH and restart the bash shell (type bash). If you still have problems running java programs, also add the following to the ~/.bashrc file: export CLASSPATH=./:$CLASSPATH Now, when you log into linux, you're likely not put into bash automatically. You'll see a prompt like "-sh$". So THE FIRST THING YOU SHOULD DO IS to type "bash". This puts you in the bash shell, where the PATH variable you just set now has effect. Type "javac progname.java" to compile source code progname.java. Then type "java progname" to run the program. Remember: if the file name is "progname.java", then the public class that contains main must be called "progname" as well. 1. In converting the following simple program involving "gas station" objects, please remember that the "main" method in java must also be inside a class. In fact, for a stand-alone program, it must be inside a public class that shares the name of the file of the source code. */ /* C++ program for managing gas stations */ using namespace std; #include class gasStation { public: double regularprice; // price for a gallon of regular double superprice; // price for a gallon of super double sales; // total sales of station // constructor gasStation(double r, double s) { regularprice = r; superprice = s; sales = 0; } // methods to sell gas, parameter indicates number of gallons void sellregular(double gallons) { sales += regularprice * gallons; } void sellsuper(double gallons) { sales += superprice * gallons; } // method to double prices void gouge() { superprice *= 2; regularprice *= 2; } // method to compare the total sales of one station versus another bool moreprofit(gasStation * other) { return sales > other->sales; } }; // class gasStation int main(int argc, char** argv) { gasStation * A = new gasStation(3.29, 3.49); gasStation * B = new gasStation(3.39, 3.69); A->sellregular(10); A->sellsuper(8); B->sellsuper(11); B->sellregular(12); if (A->moreprofit(B)) cout << "station A is more profitable\n"; else cout << "station B is more profitable\n"; // You've made a lot of money and now you own a whole array of gas stations. gasStation** G = new gasStation*[10]; // creates 10 null pointers for(int i=0;i<10;i++) G[i] = new gasStation(3.19,3.39); //... // Loop to find gas station with highest sales value. gasStation *highest = G[0]; for(int i=1;i<10;i++) if (G[i]->moreprofit(highest)) highest = G[i]; cout << "highest total sales is " << highest->sales << endl; }//main /* 2. After you have converted the above program into java, modify the program by writing a method called "onsale". This method should lower the prices of both types of gas by a certain percentage, with is passed in as a parameter. For example, calling A.onsale(0.1); // should decrease prices by 10 per cent. Add another method that would reset the prices after a sale (you'll have to decide how to do this; what to add to the class, etc...). A.resetprices(); */ /* 3. Instead of an array of gas stations, you need to modify the above program (in java) so that the gasStation class implements a linked list. The simplest way to do this is to add a "next station" pointer to the gasStation class, but there are also other ways to implement linked lists. Write a method that adds a new gas station object to the end of your list of gas stations. Write a method that returns the sum of all sales of your gas stations. Write a method that examines each gas station in the list and call gouge() if the sales value of the station exceeds $100. These methods can be written either inside the gas station class or in another class. 3b. (challenge) Write a method that deletes the gas station making the least amount of money in your list. */