Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Two programming assignments for ap computer science students. The first assignment, named 'video game', requires students to write a program simulating billy's video game spending habits for a given number of weeks. The second assignment, named 'stringtest', asks students to write a program that compares two strings, ignores case, and performs various string manipulations based on user choices. Students are expected to write, test, and document their code.
Typology: Assignments
1 / 4
th
Program #1: Video Game Mania Billy loves video games! In fact, he spends all of his money on them. He has a weekly allowance and each game costs a certain amount of money. (Both of these are values entered by the user.) You will write a program to simulate Billy's spending habits for a particular number of weeks, also a value entered by the user. At the end of each week, determine whether or not Billy buys a video game. Also, any money not spent on a video game carries over to the following week. You are also guaranteed that his allowance is a positive integer number of dollars but is less than the price of one game, which is also an integer. At the end of your program, you write out how much money Billy has left and how many video games he has bought. Write a program that executes this program. A sample run of the program is included below (Program output is in bold, the user input is in italics): Please enter Billy's weekly allowance in dollars. 10 Please enter the cost of a video game in dollars. 33 Please enter the number of weeks to follow Billy's spending habits. 8 After week 1, Billy has 10 dollars and does not buy a video game. After week 2, Billy has 20 dollars and does not buy a video game. After week 3, Billy has 30 dollars and does not buy a video game. After week 4, Billy has 40 dollars and then buys a video game! After week 5, Billy has 17 dollars and does not buy a video game. After week 6, Billy has 27 dollars and does not buy a video game. After week 7, Billy has 37 dollars and then buys a video game! After week 8, Billy has 14 dollars and does not buy a video game. At the end of 8 weeks, Billy has 14 dollars and 2 video games. Call your program Game.java. In your comments at the end of the program, explain any problems you had in creating the program and how you caught and fixed the mistakes. Only do this for the most important issues you dealt with.
Program 2: Using Java Classes Read chapter 3, paying careful attention to section 3.5. Also, read over the specifications of the following methods in the back of your book (ppg 878 – 882): char charAt(int i) int compareToIgnoreCase(String s) boolean contains(String s) int length() String replace(char c, char d) String toLowerCase() Write a program that first prompts the user to enter 2 Strings. Store these in two different String objects. Then present the user with the following menu:
Sample Output from the String Program Please enter the first string. Happy Please enter the second string. feBruArY Here are your choices: