Question: using JAVA package question1 ; /** * * Write a loop that adds up all of the integer numbers between 1 and 100, including 1

using JAVA package question1; /**  *  * Write a loop that adds up all of the integer numbers between 1 and 100,  including 1 and 100.  and displays the answer.    */ public class Question_1_add_numbers_1_to_100 { public static void main(String[] args) { int start = 1; int end = 100; int result = addNumbers(start, end); System.out.println(String.format("The sum of the numbers %s to %s is %s", start, end, result)); } public static int addNumbers(int from, int to) { // TODO write your loop here, and replace this return statement with your result.  // It should add up all the numbers between the from and to variables,  // including the values in to and from.   return 0; } } 

-------------------------------------------------------------------------------------------

package question2; import static input.InputUtils.*; /**  Write a loop that asks the user to enter 5 numbers.  The user should enter the numbers, one by one.  Use the doubleInput("enter a number") method.  Once the user has entered all the numbers,  calculate the total and the average value. */  public class Question_2_add_5_numbers { public static void main(String[] args) { // Don't modify these lines  double[] results = new Question_2_add_5_numbers().getNumbers(); System.out.println("The total is " + results[0]); System.out.println("The average is " + results[1]); } public double[] getNumbers() { // TODO Ask user for 5 numbers, one by one   // Calculate total and average and save in the variables below.   double total = 0; // TODO Keep the total variable. Replace 0 with your result.  double average = 0; // TODO Keep the average variable. Replace 0 with your result.   // Write your code here...   for (int x=5; x>0;x--){ double num = doubleInput("enter the number "); total=num+total; // System.out.println("the total is:"+total);   average=total/5; // System.out.println("the average is:"+average);   } // Don't modify this line  return new double[]{ total, average }; } } 

-----------------------------------------------------------------------------------------------------------

package question3; import java.util.Random; import static input.InputUtils.*; /**  *  Your program should generate a random number between 1 and 10,  and challenge the user to guess the number.   Write a loop that asks the user to guess a number that the computer  is thinking of. Print a success message if they guess correctly.   If the user does not guess correctly, tell the user that they need to guess  higher, or lower, and ask the user to try again.   The user should be able to have as many guesses as they need.   Once the user guesses correctly, tell the user how many guesses they needed to  get the right number.   */ public class Question_4_Random_Number_Guessing_Game { Random rnd = new Random(); final String CORRECT = "Correct!!"; final String LOW = "Too low"; final String HIGH = "Too high"; public static void main(String[] args) { int guessesNeeded = new Question_4_Random_Number_Guessing_Game().play(); // TODO print the number of guesses needed.   } public int play() { int secret = generateSecretNumber(1, 10); int guessesNeeded = 0; while (true) { // TODO ask user for their guess  int guess = 0; // Replace with your code   // TODO increase guessesNeeded   String result = checkGuess(secret, guess); // TODO print the result - too high, too low, or correct.   // TODO Check if result is correct. If so, end the loop.  break; // TODO remove and replace with a test   } return guessesNeeded; } public String checkGuess(int secret, int guess) { // TODO Return CORRECT if secret is the same as guess  // TODO Return LOW if guess is too low  // TODO return HIGH if guess is too high   return null; //replace with your code   } public int generateSecretNumber(int min, int max) { // TODO generate a random number between min and max, inclusive of min and max  // The smallest value possible should be min  // The largest value possible should be max  // Use the global Random rnd to generate the number   return 0; //replace with your code   } } 

---------------------------------------------------

package question4; import static input.InputUtils.doubleInput; /**  * Customers of a heating utility company have much larger bills in the cold winter than in the summer.  * The utility company allows customers to spread the cost of bills through the year by  * charging them an average payment every month.  *  * The utility company averages all of the last year's bills, and uses that to estimate the  * average payment for next year.  *  * Ask the user for each month's bill for last year.  * Store this data in an array.  * Store January's bill in element 0, February's in element 1...  *  * Then, add up all of the bills and figure out, and display the average;  *  * Also, display the user's data in a table of months and bill amount, so they can review it for accuracy.  *  * Tip: use another array with the names of the months to help ask for data/display data.   */  public class Question_5_Average_Utility_Bill { String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; public static void main(String[] args) { Question_5_Average_Utility_Bill billsAverage = new Question_5_Average_Utility_Bill(); billsAverage.billAverages(); } private void billAverages() { double[] bills = getYearBills(); double average = averageBillAmount(bills); System.out.println(String.format("Your average bill is %.2f", average)); printBillTable(bills); } public double[] getYearBills() { // TODO ask user for bill amount for January, then February...  // Create a new double array.  // Store values the user enters in this array.  // Return this array.   return null; // replace with your code   } public double averageBillAmount(double[] bills) { // TODO Calculate the average value of all the bills, and return this number.  return 0; // replace with your code  } public void printBillTable(double[] bills) { // TODO display the month name, and bill amounts, in table form.  // Use the months array to display the names.   // Replace these lines with your code. You'll need to use a loop to display all the months.  // String formatting is helpful. Here's some examples to space some columns with exactly 15 character width  System.out.println(String.format("| %-15s| %-15s|", "Month", "Bill" )); System.out.println(String.format("| %-15s| %-15.2f|", "January", 44.5995 )); } } 

----------------------------------------------------

package question5; import static input.InputUtils.doubleInput; /**  *  * A parcel delivery company charges the following rates to ship a parcel.    Up to 10 pounds: $2.15 per pound   Up to 20 pounds: $1.55 per pound   Up to 30 pounds: $1.15 per pound   The shipping company does not ship parcels that weigh over 30 pounds.   So, a parcel that weighs 17 pounds will cost $1.55 x 17 = $26.35.   Write a program that asks the user for the weight of a parcel and displays whether it can be shipped, and what it will cost.   Optional extra: the most obvious solution to this problem uses if statements for the price bands. Can you think of a different way? Hint  loops and arrays of price and max weights for price?   */ public class Question_6_Parcel_Delivery { public double MAX_WEIGHT = 30; // Use this in the canShip method   public static void main(String[] args) { // Don't modify the code in this method.   Question_6_Parcel_Delivery delivery = new Question_6_Parcel_Delivery(); double weight = doubleInput("Enter weight of parcel"); boolean canShip = delivery.canShip(weight); if (canShip) { double price = delivery.calculatePrice(weight); System.out.println(String.format("It will cost %.2f to send your %.2f pound parcel", price, weight)); } } public boolean canShip(double weight) { // TODO return false if parcel weighs 0 or less  // TODO return false if parcel weighs more than MAX_WEIGHT. Use the MAX_WEIGHT variable in this code   // TODO otherwise, the parcel is more than 0 and less than or equal to MAX_WEIGHT. Return true.   return false; // Replace this with your code  } public double calculatePrice(double weight) { // TODO assume parcel is a valid weight. Figure out price to ship this parcel.   return 0; //Replace this with your calculated price   } } 

----------------------------------------------------------------------------------

package question6; import static input.InputUtils.stringInput; /**   Write a program to test if a String contains all of the  punctuation characters from the number keys on a standard US keyboard:   !@#$%^&*()   Write a program to test if an example String contains all of these characters or not.  Your code should NOT use 10 if statements!   */ public class Question_7_String_Contains_Chars { String punctuation = "!@#$%^&*()"; public static void main(String[] args) { Question_7_String_Contains_Chars pangram = new Question_7_String_Contains_Chars(); String testString = stringInput("Enter the string to test: "); boolean containsChars = pangram.testContainsChars(testString); System.out.println("Does the string contain all the characters? " + containsChars); } public boolean testContainsChars(String testString) { // TODO check if testString contains all the punctuation characters being tested.  return false; } } ------------------------------------------------------------------------------ 
package question7; import static input.InputUtils.intInput; import static input.InputUtils.stringInput; /**  *  * Write a program that displays a square of characters  * of any size, between 1 and 100 characters.  *  * The user should be able to enter a size, a character, and  * your program will use loops to display a square.  *  * So, if the user enters 4, and the character "%"  * your program will display   %%%%  %%%%  %%%%  %%%%   */  public class Question_8_square_of_characters { int MIN_SIZE = 1; int MAX_SIZE = 100; public static void main(String[] args) { Question_8_square_of_characters squarer = new Question_8_square_of_characters(); int size = squarer.getSquareSize(); String character = squarer.getCharacter(); squarer.printSquare(size, character); } /* Get a positive number for the square size. You don't need to modify this method. */  public int getSquareSize() { // Input validation. The square size must be positive.   int size = -1; // Loop while user-entered size is less than the minimum, or larger than the maximum  while (size < MIN_SIZE || size > MAX_SIZE) { size = intInput("Enter a number between 1 and 100 for the square size"); } return size; } public String getCharacter() { // TODO ask user for character  // TODO input validation - make sure user enters a string of length = 1.   return null; // Replace with your code   } public void printSquare(int size, String character) { // TODO print a square of characters, of the given size.   } } 

-----------------------------------------------------------------

package question8; /**  *  A smartphone is running 3 apps, each of which syncs and download data from a different server.    App A syncs and downloads data every hour, and downloads 0.5KB each time   App B syncs and downloads daily, and downloads 2KB every time   App C, when installed, is 1MB in size (assume this is equal to 1000KB). This app syncs and  downloads every 4 hours, and every time it syncs it downloads 1% of its current size.  The new data it downloads count towards the app's size, so you'll need to keep track of  the current size of the app.   With all apps installed, the phone has 5MB (or 5000KB) of free space.  When the phone starts, each app syncs and downloads, and then repeats to their own schedule.   With all 3 apps running continuously, how long, in hours, will it be before the phone runs out of space?   Assume the phone is running continuously and nothing else is using space on the phone.  Assume that 1KB = 1000 bytes and 1MB = 1000,000 bytes.   Hint 1: the modulo operator is helpful. An expression like ( number % 4 == 0 ) is true if number divides evenly by 4.  Hint 2: the answer is several hundred hours.  Hint 3: This problem is a little trickier than the other ones, but it can be done :)   */ public class Question_9_cellphone_storage { public static void main(String[] args) { int hoursToFill = new Question_9_cellphone_storage().calculateTimeToFillPhone(5000, 0.5, 2, 1, 1000); System.out.println(hoursToFill); } public int calculateTimeToFillPhone(double freeSpaceKB, double appAHourlyDownloadKB, double appBDailyDownloadKB, double appCPercentDownload, double appCSizeKB) { // TODO Calculate and return the number of hours until the phone runs out of space  // Make sure all the apps sync and download at hour = 0  // Use the method arguments.   int hours = 0; // TODO write your code here   return hours; // TODO replace with your own calculated value   } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!