• anonymous
writing some java codes
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • katieb
I got my questions answered at in under 10 minutes. Go to now for free help!
  • anonymous
1. Write a set of instructions which will prompt the user and input 3 int alues, compute the average, and output the resulat as a double, formatted so that exactly 1 digit appears to the right of the decimal point. Assume Scanner and DecimalFormat classes have been imported. 2. Given the following tax table information, write Java code to assign the double taxRate appropriately given the double pay. Select the selection statement (if, if-else, switch) that makes the most sense: If pay is more than 100,000, tax rate is 40% If pay is more than 60,000 and less than or equal to 100,000, tax rate is 30% If pay is more than 30,000 and less than or equal to 60,000, tax rate is 20% If pay is more than 15,000 and less than or equal to 30,000, tax rate is 10% If pay is more than 5,000 and less than or equal to 15,000, tax rate is 5% If pay is less than or equal to 5,000, tax rate is 0% 3. Show the output that would occur from the following code, including proper spacing. for (j = 0; j < 5; j++) { for (k = 0; k < 5; k++) if(j!=k) System.out.print(' '); else System.out.print('*'); System.out.println( ); } 4. Write a set of code that outputs all of the int values between 1 and 100 with 5 values per line, and each of those 5 values spaced out equally. Use a single for-loop to solve this problem. 5. The following code has syntax error before the world else. What is the error and why does it arise? Fix the code so that this statement is a legal if-else statement. if(x<0); x++; else X--; For questions 6 - 8, write the requested portions of a class called BaseballPlayer. This class contains the following data instances: private String name; private String position; private int numAtBats; private int numSingles; private int numDoubles; private int numTriples; private int numHomeRuns; private double battingAverage; 6. Write the constructor, which is passed the player’s name and position. 7. Write a method that computes the player’s batting average, which is the total number of hits (singles, double, triples, home runs) divided by the number of at bats. Make sure that your method does not cause a division by zero error! 8. Write a toString method that returns the player’s name, position and batting average formatted to have 1 digit to the left of the decimal and 3 digits to the right of the decimal. Assume DecimalFormat has been imported. For questions 9 - 10, consider a class called Building. This class consists of a number of floors (numberOfFloors) for the Building, a current floor for the elevator (current), a requested floor of a person waiting for the elevator (requestedFloor), and methods for constructing the building object, for moving the elevator one floor up, for moving the elevator one floor down, for requesting the elevator and for starting the elevator going. Assume that requestedFloor will be set to 0 if there are currently no requests being made (or the last request has already been fulfilled). 9. Write the constructor for this class. 10. Write the method to start the elevator moving, assuming that requestedFloor has already been set by the requestTheElevator method. Additional Details I get some answers but I do not know if it is right 1. import java.util.Scanner; public class Average { public static void main (String [] agrs) { int x,y,x; double average x= scan.nextint(); y= scan.nextint(); x= scan.nextint(); System.out.print ( "x"); System.out.print ( "y"); System.out.print ( "z"); average = (x+y+z)/3; System.out.println("average" + average); 2. I get it. Thank you 3. * ** *** **** ***** 4. for (value = 1; value <=100,; value ++) System.out.println("value" + "value" + "value" + "value" + "value"): 5. I get it. Thank you 6. No, clue 7. No, clue 8. No, clue 9. No, clue 10. No, clue

Looking for something else?

Not the answer you are looking for? Search for more explanations.