Demonstrate the class in a program that contains car object

Assignment Help JAVA Programming
Reference no: EM131447454

Assignment

Problem 1:

Write a class named Car that has the following fields:

• yearModel: The yearModel field is an int that holds the car's year model.
• make: The make field is a String object that holds the make of the car.
• speed: The speed field is an int that holds the car's current speed.

In addition, the class should have the following 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.

• Accessor: The appropriate accessor methods should be implemented to access the values stored in the object 's yearModel, make, and speed fields.

• accelerate: The accelerate method should add 5 to the speed field when 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 contains a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and print it on a separate line. Then, call the brake method five times, each time printing the current speed of the car on a separate line.

Problem 2:

Design a Payroll class with the following fields:

• name : a String containing the employee's name
• idNumber: an int representing the employee's ID number
• rate: a double containing the employee's hourly pay rate
• hours: an int representing the number of hours this employee has worked

The class should also have the following methods :

• Constructor : takes the employee's name and ID number as arguments
• Accessors: allow access to all of the fields of the Payroll class
• Mutators: let the user assign values to the fields of the Payroll class
• grossPay: returns the employee's gross pay, which is calculated as the number of hours worked times the hourly pay rate.

Write another program that demonstrates the class by creating a Payroll object , then asking the user to enter the data for an employee in the order: name , ID number, rate, hours.

The program should then print out a statement in the following format (for example, if you had an employee named Chris Jacobsen with ID number 11111, who works for 5 hours at $10/hr):

Chris Jacobsen, employee number 11111, made $50.00 in gross pay.

Using text forming so that the gross pay is rounded to two decimal places.

Problem 3:

Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field:

• ftemp: a double that holds a Fahrenheit temperature.

The class should have the following methods :

• Constructor : The constructor accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field.
• setFahrenheit: The set Fahrenheit method accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field.
• getFahrenheit: Returns the value of the ftemp field as a Fahrenheit temperature (no conversion required)
• getCelsius: Returns the value of the ftemp field converted to Celsius. Use the following formula to convert to Celsius:
Celsius = (5/9) * (Fahrenheit - 32)
• getKelvin: Returns the value of the ftemp field converted to Kelvin. Use the following formula to convert to Kelvin:
Kelvin = ((5/9) * (Fahrenheit - 32)) + 273

Demonstrate the Temperature class by writing a separate program that asks the user for a Fahrenheit temperature. The program should create an instance of the Temperature class, with the value entered by the user passed to the constructor . The program should then call the object 's methods to display the temperature in the following format (for example, if the temperature in Fahrenheit was -40):

The temperature in Fahrenheit is -40.0
The temperature in Celsius is -40.0
The temperature in Kelvin is 233.0.

Reference no: EM131447454

Questions Cloud

Distinguish between dependency and delinquency : The historical development of the juvenile justice system. Use case law or legislation to strengthen your discussion.Predominant philosophy of the juvenile system.Key differences between the juvenile and adult systems.Distinguish between dependency a..
Components of ad are rising and which are dropping : Examine all four components of GDP (C, I, G, and Xn). Which of these four components of AD are rising and which are dropping? On the top righthand corner of the page, you can click on Modify to select prior years.
What rate have sales been growing : Shalit Corporation's 2013 sales were $12 million. Its 2008 sales were $6 million. At what rate have sales been growing? Suppose someone made this statement: "Sales doubled in 5 years. This represents a growth of 100% in 5 years; so dividing 100% by 5..
Briefly describe how a visual was used to address a business : Applying Visual Design Principles, Review one of the client stories in the portfolio section of the Xplane website ( www.xplane.com/portfolio ). Briefly describe how a visual was used to address a business problem and why a visual approach worked ..
Demonstrate the class in a program that contains car object : Demonstrate the class in a program that contains a Car object, and then calls the accelerate method five times. After each call to the accelerate method.
What observations can you make about the use of law : Over 50 years have passed since the Brown decision and while many things have changed, there are still inequalities within and between school districts, and within larger society. What observations can you make about the use of the law to effect ..
Briefly describe technologies that are leading businesses : Briefly describe the technologies that are leading businesses into the third wave of electronic commerce. Define "channel conflict" and describe in one or two paragraphs how a company might deal with this issue
Monopolist produces the competitive output : A monopolist's cost function is C(y)=y(y/50-2)²+y. It faces a demand function y=100-25p. Solve for monopolist's output, price, profit and consumer surplus when :
Currently saving for the down payment : You want to buy a house within 3 years, and you are currently saving for the down payment. You plan to save $5,000 at the end of the first year, and you anticipate that your annual savings will increase by 10% annually thereafter. Your expected annua..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a static recursive java method

Write a static recursive Java method that will accept an int and write the base 2 (binary) representation of that int, one bit per recursive call, to System.out

  Create a java application that stores employee details

SD2720: Module Using Operators, Arrays, and Constructs Lab. Create a Java application that stores and maintains the employee details, including employee ID, employee name, department, designation, marital status, and date of marriage, in a multidim..

  Write a java program to read a string value from the user

Write a Java program to read a string value from the user, the program prints out the entered string, and then prints out the string one character per line.

  Writing a program to have it generate random words

How would I go about writing a program to have it generate random words with a letter missing for a child to guess? Maybe it would have three letters, then four, next five, and so on until maybe 10 letters. Please keep in mind that I'd like it to wor..

  Identify the first character of the name and lengthof length

Write a Java application that stores the names of your family and friends in a one-dimensional array of Strings. The program should show all names in upper case and lower case, identify the first character of the name, and the lengths of the names.

  1 introductionin order to debug an application it is

1 introductionin order to debug an application it is sometimes useful to know where a given object comes from or where

  In light of wrestling with ethics

In light of "Wrestling With Ethics" and other research/articles that you are able to draw upon, should profitability drive social responsibility? Be sure to support your discussion question responses with evidence from the readings and/or additional ..

  Good idea to test a general class with a driver program

Question 1: Why is it a good idea to test a general class with a driver program before trying to use it? Question 2: What is the difference between black box and glass box debugging?

  Design 3 shoppingbay is an online auction service that

3. shoppingbay is an online auction service that requires several reports. design a flowchart or psuedocode this is

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  The abstract class and interface

What is the difference between the Abstract Class and Interface.Write a java Program that counts number of words in each line of the file.

  Write thejava code for a program

Write theJava code for a program that reads the weight of a piece of luggage and print the proper message, depending on the weight, as per the table below.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd