Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92256197
  • Price:- $45

Priced at Now at $45, Verified Solution

Have any Question?


Related Questions in Java

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As