Answering questions
COSC 1437
Racetrack
Start with objective 1 and work on creating objects for your lab. If you have questions or encounter errors with your code contact the instructor by email or during live sessions for assistance.
You are to take the given code which shows 1 car running a race. Your job will be to add 5 more cars with varying stats which should participate in the race just like the first car. In this lab each car holds the same types of information, behaves in the same way and only differs in their values for said information. So the optimal solution would be to use Objects. Create an object capable of holding the information for each car. Also include the operations that the cars do as methods (functions). Make certain to create a constructor that takes, as input, adequate information to allow you to build the cars more easily. (Due note that credit for this objective will not be earned if you do not create and use objects for the car’s information.)
· String car2Name = “Pat Sajak Car”;
· car2HandlingS = 0.45f;
· car2HandlingC = 0.65f;
· car2HandlingU = 0.3f;
· car2RaceProgress = 0;
· car2CurrentSpeed = 0;
· car2TopSpeed = 0.83f;
· car2Acceleration = 0.14f;
· car2Wins = 0;
· car2Symbol = ‘P’;
· String car3Name = “Alex Trebek Car”;
· car3HandlingS = 0.29f;
· car3HandlingC = 0.45f;
· car3HandlingU = 0.02f;
· car3RaceProgress = 0;
· car3CurrentSpeed = 0;
· car3TopSpeed = 0.85f;
· car3Acceleration = 0.19f;
· car3Wins = 0;
· car3Symbol = ‘A’;
· String car4Name = “Bob Eubanks Car”;
· Car4HandlingS = 0.15f;
· Car4HandlingC = 0.18f;
· Car4HandlingU = 0.05f;
· Car4RaceProgress = 0;
· Car4CurrentSpeed = 0;
· Car4TopSpeed = 0.89f;
· Car4Acceleration = 0.21f;
· Car4Wins = 0;
· Car4Symbol = ‘E’;
· String car5Name = “Monty Hall Car”;
· Car5HandlingS = 0.18f;
· Car5HandlingC = 0.22f;
· Car5HandlingU = 0.09f;
· Car5RaceProgress = 0;
· Car5CurrentSpeed = 0;
· Car5TopSpeed = 0.93f;
· Car5Acceleration = 0.17f;
· Car5Wins = 0;
· Car5Symbol = ‘M’;
· String car5Name = “Richard Dawson Car”;
· Car5HandlingS = 0.40f;
· Car5HandlingC = 0.5f;
· Car5HandlingU = 0.35f;
· Car5RaceProgress = 0;
· Car5CurrentSpeed = 0;
· Car5TopSpeed = 0.815f;
· Car5Acceleration = 0.19f;
· Car5Wins = 0;
· Car5Symbol = ‘R’;
Right now the race is only being run once. I want you to adjust the code so that the race can be run 25 times to simulate an entire season of racing. At the end of the season I want you to output each car’s race wins and finally display the car with the most wins as the season champion.
Each race of the season should be a different race. Randomly create racetracks prior to the start of each race. Do this by randomly appending the four characters to a string. You can skew the random numbers to give more straightaways or turns depending on your preference (so long as there is a chance of any type of racetrack being possible).
*note that some cars are better than others and 1 or 2 of them are just awful and have no chance of winning – you do not have to balance it in any way, if 1 car wins every time that is fine (there will probably be some competition between at least 2 of them but again, it is not your job to balance the win rates).
For this lab you are allowed to hard-code the values for the race car instances in, but for the bonus objective you should move these to a file(s) where the information can be read into the program.
In all likelihood you created your program where each car outputs his progress on his own individual line. For 5 additional points adjust your program so that it draws each car on the same line unless there are multiple cars at the exact same position (in which case it would draw that car on the next line).
The purpose of this program will be to demonstrate your knowledge of the basic programming fundamentals and show that you can do so in JAVA. I will repeat that your final submission should be a .java file of your own individual solution (not a .class file – I am unable to grade .class files).
Your program will generate a multiple of primes table between 2 selected values. Your java program will need a class and a main to run:
//with any necessary imports
public class MyClass {
public static void main(String args[]) {
}
}
But I will not be grading your main. Instead your job is to write a your solution in a separate method (called a function in c++, java calls them methods, if your wondering why it is a fascinating google search or ask me during live sessions) name that method primeTable. Obviously, your main method (yep, we have to get used to method instead of function) will call this primeTable method to run and will be required to pass in a start and end parameters. (By the way, this is chapter 6 in fundamentals
1
…)
You do not have to read any inputs from a file or a user, you may hard code the start and end values in main as long as you pass them to the function (the primeTable function must take these values in and cannot hard code them).
The only difference between methods done in JAVA and your c++ functions are that you will need to include the word ‘static’ in your method header. The example given here prints out a simple message but make certain it is in the scope block of your class where the main function is located (it can be above or below main without issue):
static void thisIsAFunction()
{
System.out.println(“Hey I’m a function”);
}
The actual goal of this method/function is to take in 2 inputs (as int’s) a start, and an end. Between these 2 values your function will output a table of all the prime numbers between start and end with all the multiples of them.
You will probably need to use 2 loops nested within each other to accomplish this goal (though it can be done with 1 loop). You may use any loop you wish but please format your table so that it is easy to read like the example above. To do so you may use the following function (or any other method such as decimal format):
1
public class RaceTrack
{
public static void main(String[] args)
{
//car 1
String car1Name = “Bob Barker Car”;
float car1HandlingS = 0.30f;
float car1HandlingC = 0.62f;
float car1HandlingU = 0.1f;
float car1RaceProgress = 0;
float car1CurrentSpeed = 0;
float car1TopSpeed = 0.93f;
float car1Acceleration = 0.11f;
int car1Wins = 0;
char car1Symbol = ‘1’;
String Racetrack = “———-U-C-S——-C—S—-C—-C–U—-“;
int raceLength = Racetrack.length();
boolean runningRace = true; //once someone wins we can stop this
while (runningRace)
{
System.out.println(Racetrack);
//Car 1
//display the car
String Progress = “”;
for (int i=0;i Progress+= ” “; System.out.println(Progress+car1Symbol); //accelerate based on where you are on the track //Racetrack[(int)car1RaceProgress)] switch (Racetrack.charAt((int)car1RaceProgress)) { case ‘-‘: //strait-away if (car1CurrentSpeed < car1TopSpeed) car1CurrentSpeed += car1Acceleration; if (car1CurrentSpeed > car1TopSpeed) car1CurrentSpeed = car1TopSpeed; break; case ‘S’: //Chicane if (car1CurrentSpeed < car1TopSpeed*car1HandlingS) car1CurrentSpeed += car1Acceleration; else if (car1CurrentSpeed > car1TopSpeed*car1HandlingS) car1CurrentSpeed = car1TopSpeed*car1HandlingS; break; case ‘C’: //curve if (car1CurrentSpeed < car1TopSpeed*car1HandlingC) car1CurrentSpeed += car1Acceleration; else if (car1CurrentSpeed > car1TopSpeed*car1HandlingC) car1CurrentSpeed = car1TopSpeed*car1HandlingC; break; case ‘U’: //Hairpin if (car1CurrentSpeed < car1TopSpeed*car1HandlingU) car1CurrentSpeed += car1Acceleration; else if (car1CurrentSpeed > car1TopSpeed*car1HandlingU) car1CurrentSpeed = car1TopSpeed*car1HandlingU; break; } //increase progress car1RaceProgress+=car1CurrentSpeed; if (car1RaceProgress >= raceLength) { System.out.println(car1Name+” wins”); car1Wins++; runningRace=false; } } //end of while loop }//end of main }
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.