Question
Asked by:
$100.00 Java Programs
- From Computer-Science: Object-Oriented-Programming , Computer-Science: Programming-Methods
- Closed, but you can still post tutorials
- Due on May. 06, 2008
- Asked on May 05, 2008 at 8:32:11PM
Q:I need the full code for 9 simple java programs. I will also include a tip if the code all works as expected!
The code needs to be as simple as possible while still following the rules of each assingment and must include basic comments on steps taken within code:
1. The formula for converting a temperature from Fahrenheit to Centigrade is C= 5/9 (F-32)
Write a method named centigrade that accepts a Fahrenheit temperature as an argument. The method should return a temperature, converted to centigrade. Demonstrate the method by calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their centigrade equivalents.
2. A prime number is an number that is only evenly divisible by itself and 1. Wrate a method name isPrime, which takes an integer as an arguments and returns “true” if the argument is a prime number, or false if otherwise. Demonstrate the method in a complete program.
3.Write a class named Car that has the following fields:
yearModel – is an int that holds the car’s year model
make – string object that holds the make of the car
speed – int that holds the current speed
In addition, the class should have the following constructor and other methods. Constructor. The constructor should accept the car’s year model and make as arguments. These values should be assigned to the object’s yearModel and make fields. The constructor should also assign 0 to the speed field. Accessors. Appropriate accessor methods should get the values stored in an object’s yearModel, make, and speed fields. Accelerate. The accelerate method should add 5 to the speed field each time it is called. Brake. The Brake method should subtract 5 from the speed field each time it is called. Demonstrate the class in a program that creates a Car object, and then calls accelerate method 5 times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method 5 times. After each call to the brake method, get the current speed of the car and display it.
4. Design a Payroll class that has fields for an employee’s name, ID number, hourly pay rate, and number of hours worked. Write the appropriate accessor and mutator methods and a constructor that accepts the employee’s name and ID number as arguments. The class should also have a method that returns the employee’s gross pay, which is calculated as the number of hours worked multiplied by the hourly pay rate. Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee. The program should display the amount of gross pay earned.
5. A county collects property taxes on the assessment value of property, which is 60 percent of the property’s actual value. If an acre of land is valued at 10,000, its assessment value is 6,000. The property tax is then .64 for each 100 of the assessment value. The tax for an acre assessed at 6,000 will be 38.40. Create a GUI application that displays the assessment value and property tax when a user enters the actual value of the property.
6. Create a class with a method that accepts a charge account number as its argument. The method should determine whether the number is valid by comparing it to the following list of valid charge account numbers:
5658845 4520125 7895122 8777541 8451277 1302850
8080152 4562555 5552012 5050552 7825877 1250255
1005231 6545231 3852085 7576651 7881200 4581002
These numbers should be stored in an array or an ArrayList object. Use a sequential search to locate the number passed an argument. If the number is an array, the method should return “true” showing it is valid. If not it should return “false”. Write a program that tests the class by asking the user to enter a charge account number. The program should display a message indicating whether the number is valid or invalid.
7. Create a class named RoomDimension that has 2 fields: one for the length of a room and one for the width. The RoomDimension class should have a method that returns the area of a room. Then create a RoomCarpet class that has RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have a method that returns the total cost of the carpet. Write a program that asks the user to enter the dimensions of a room and the price per square foot of the desired carpeting. The class should display the total cost of the carpet.
8. Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program that performs the following steps.
1. The user is asked to enter a string.
2. The program displays the following menu:
a. Count the number of vowels in the string
b. Count the number of consonants in the string
c. Count both the vowels and consonants in the string
d. Enter another string
e. Exit the program
3. The program performs the operation selected by the user and repeats until the user selects e, to exit the program.
9. Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6. The program should calculate and display the sum of all the numbers.



