Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
expand_more
expand_more
format_list_bulleted
Question
Chapter 2, Problem 5PE
a.
Program Plan Intro
NauticalMiles
Define the class “NauticalMiles”.
- Define the main method.
- Declare and initialize the required variable.
- Calculate the given value in kilometers.
- Calculate the given values in miles.
- Print eh value of nautical miles.
b.
Program Plan Intro
Nautical Miles Interactive
Program Plan:
Define the class “NauticalMilesInteractive”.
- Define the main method.
- Declare and initialize the required variable.
- Calculate the given value in kilometers.
- Calculate the given values in miles.
- Print eh value of nautical miles.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
a. Write a class that declares a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay – withholding). Save the class as Payroll.java.
java
a. You want to create a Java main class. You create the source code file, declare the package, and write the class header. Now you must create the main method that starts the program. Write the entire method header, including the opening brace for the method.
b.
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that calculates the whole dollars in the amount and saves it in a new integer variable named dollars.
Note: The Java style guide states that one space is used on either side of binary operators.
In java write a code :
"picture 1"
1- Write a class declaration for Shape class and add the two variables to the class declaration
sides: is an int variable that holds the number of sides the shape has.
angles: is an int variable that holds the number of angles the shape has.
2- The class should have the following constructors:
A constructor that accepts the following value as argument and assigns it to the appropriate fields: sides and angles.
A no-arg constructor that assigns 0 to the sides, and 0 to the angles field.
3- Write mutator methods that store values in these fields and accessor methods that return the values in these fields as in above UML diagram.
4- Once you have written the class, write a separate program that creates two Shape objects to hold the following data:
"Picture 2 "
Chapter 2 Solutions
Java Programming
Ch. 2 - Prob. 1RQCh. 2 - Prob. 2RQCh. 2 - Prob. 3RQCh. 2 - Prob. 4RQCh. 2 - Prob. 5RQCh. 2 - Prob. 6RQCh. 2 - Prob. 7RQCh. 2 - Prob. 8RQCh. 2 - Prob. 9RQCh. 2 - Prob. 10RQ
Ch. 2 - Prob. 11RQCh. 2 - Prob. 12RQCh. 2 - Prob. 13RQCh. 2 - Prob. 14RQCh. 2 - Prob. 15RQCh. 2 - Prob. 16RQCh. 2 - Prob. 17RQCh. 2 - Prob. 18RQCh. 2 - Prob. 19RQCh. 2 - Prob. 20RQCh. 2 - Prob. 1PECh. 2 - Prob. 2PECh. 2 - Prob. 4PECh. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - Prob. 7PECh. 2 - Prob. 8PECh. 2 - Prob. 9PECh. 2 - Prob. 10PECh. 2 - Prob. 11PECh. 2 - Prob. 12PECh. 2 - Prob. 1GZCh. 2 - Prob. 2GZCh. 2 - Prob. 1CPCh. 2 - Prob. 2CP
Knowledge Booster
Similar questions
- PART B: JUnit Testing Write a Java program according to the following: Create a Multiple.java class. Create the following two static methods (with return type float): SquareRoot() and CubeRoot(). SquareRoot) method should take two arguments and return the float value at the end. CubeRoot() method should take three arguments and return the float value at the end. Create a test class with the name MultipleTest.java. In this class, import the following libraries at the top of this file import org.junit. Before; import org.junit. Test; import static org.junit.Assert.assertEquals; Create an object of Calculator.java class by writing the following code in CalculatorTest.java class: private Multiple multiple; @Before public void setup() {this.multiple new Multiple():) 4. Generate the JUnit test classes for both the methods one by one. Declare and initialize the required variables to pass those to the methods. Store the expected result in one of the variables and then compare it with the…arrow_forward7. Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F' for Fahrenheit. The class should have · Four constructors: one for the number of de- grees, one for the scale, one for both the de- grees and the scale, and a default construc- tor. For each of these constructors, assume zero degrees if no value is specified and Cel- sius if no scale is given. · Two accessor methods: one to return the temperature in degrees Celsius, the other to return it in degrees Fahrenheit. Use the for- mulas from Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree. • Three set methods: one to set the number of degrees, one to set the scale, and one to set both. • Three comparison methods: one to test whether two temperatures are equal, one to test whether one temperature is greater than another, and one to test whether one temper-…arrow_forwardJAVA PROGRAM !!!Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class named Roman, and an object of type Roman should do the following:a) Store the number as a Roman numeral.b) Convert and store the number into decimal.c) Print the number as a Roman numeral or decimal number as requested by the userThe decimal values of the Roman numerals are:• M 1000• D 500• C 100• L 50• X 10• V 5• I 1d) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number.arrow_forward
- I need to create this coding: (JAVA PROGRAMMING) Write a program by creating an Employee class. This class has three instance variables: name, which is a String representing the name of the Employee numberOfHoursPerDay, which is an int representing the number of hours the employee has worked per day salary, which is an int representing the salary of the employee per-hourly basis 1. Create getter and setter methods of all the instance variables 2. Write a constructor for the class Employee, which takes a String representing the name 3. Write a method getInfo() which takes the salary, number of hours of work per day of an employee as a parameter 4. Write a method addSal() which adds $10 to the salary of the employee if it is less than $500. 5. Write a method addWork() which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours. 6. Write a caller class and create an object of class Employee then call the methods getInfo, addSal, addWork and…arrow_forwardNeed a java code Create a class called SingleItem This class represents a bag that can hold any single type of object (decided at bag-creation time), and only one item of that type at a time. You may have a zero-parameter constructor if you want one, but you must have the following three features: Add a method called (addItem()) which returns whether or not it was successfully added Add a method which removes an item from the bag and returns it (deleteAnItem()), return null if there is no item Add a method to check if an item is in the bag (hasAnIteminTheBag()) which returns true or falsearrow_forward2. Create a java class named Shipment a. The program must ask for two separate packages to ship b. The program must calculate the cost difference using the difference in volume: i.e. The base price for a package with volume <=1 is $3, for every unit increase in volume, the cost increases by $1 e.g. 1: a parcel with volume 4, the cost is $3+ $1 +$1 +$1 = $6 e.g. 2: a parcel with volume 2.5, the cost is $3 + $1.5 = $4.5 c. Give the following (in order of priority): i. If there is no difference, display the costs as the same ii. If the cost of one is less than twice the other, display that it is “slightly more than” iii. If the cost of one is less than three times the other, display that it is “twice” iv. If the cost of one is less than four times the other, display that it is “triple” v. If the cost of one is less than five times the other, display that it is “quadruple” vi. Otherwise, display that as a calculated multiple (eg 5x, 6x etc) c. The program must indicate the more costly…arrow_forward
- Python Program: Write a program which controls a metro train and that keeps track of stations and who gets on and off. Design and implement a class called train, which has at least the following: At least the following attributes (you can include others): metroID stationNum which keeps track of the station that the train is at. iii. direction which keeps track of the direction the train is travelling in. passTotal which keeps track of the number of passengers currently on the train. A default constructor which sets the metroID to a random number between 1 and 1000, the station number to 0, the direction (int), and the passTotal to 0 (train is empty). A constructor with one parameter; the parameter is the metro id. The constructor assigns the passed integer to the metroID attribute; the rest of the attributes are set as described in the default constructor. Accessor methods for each attributes. Mutator methods for each attributes. nextStation(int lastStation) which determines…arrow_forwardFOR JAVA Create a class named Product that has ID, price and stock as fields. This class must have two constructors; one constructor must take all its fields as parameters, second constructor must take ID and price as parameters and set stock to 0. Also implement the following methods: • String toString(): Returns a brief summary about the object. • void sell(int): Takes a parameter that represents the amount to sell. Checks if stocks are sufficient. If so, it updates the stock and prints the total price. Else it prints a warning to user. Create 3 instances of Product class and test your methods.arrow_forwardPHP Write a Car class Write a class that models the concept of a Car that has a fuel economy (in miles per gallon), an odometer, and a gas tank. Your car should be able to drive a certain number of miles (specified as a parameter) until it reaches its distance or runs out of gas, whichever comes first. Further, you should write functionality to add gas to the car, and read the fuel gauge and the odometer. You should write the following methods: __construct($initialGas, $mpg): which takes the initial gas amount and miles per gallon as parameters. drive($miles): which will drive the specified miles (deducting gas from the tank and incrementing miles on the odometer) addGas($gallons): which will add more gas to the tank (the tank is of unlimited capacity). readFuelGauge(): which will return the number of gallons of gas remaining in the tank. readOdometer(): which will return the number of miles logged on the odometer.arrow_forward
- 0o.Absolutely answer please Write a program that calculates the average of courses, overall grade, and letter grade. Suppose that your students take four courses - English, Mathematics, Science, and History. You should design a class that accepts all four course's numeric scores, calculates average and overall grade, and decides letter grade based on the overall grade. Your class should have a constructor, get and set methods of each course, a method that calculates the average of four courses, a method that calculates overall grade, and a method that decides letter grade. The overall grades are calculated as the following rate: Average of All four courses: 50% Quiz: 40% Attendance: 10% The letter grade is based on the following: 90.0 to 100.0 - A 80.0 to 89.9 - B 70.0 to 79.9 - C 65.0 to 69.9 - D less than 65 - F Your program demonstrates the class by asking the user to input four-course numeric scores, creating an object, and then reporting each course's score, average, overall…arrow_forward: A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as showing the point, setting the coordinates of the point, printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. Also, write a test program to test the various operations on the point.arrow_forwardJava Program: Try to use classes to design an online address book to keep track of the name, addresses, phone mumbers and birthdays of family members, close friends aand certain business associate. Your implementation shall be able to handle a maximum of 500 entries. Define the class Address that can store a street address, city, state, and ZIP code. Use the appropriate methods to print and store the address. Also, use constructors to automatically initialize the data members. Define the class ExtPerson using the class Person and class Date (that have been introduced during the class), and the new class Address in step (a). Add a data member to the class ExtPerson to clarify the person as a family member, friend, or business associate. Also, add a data member to store the phone number. Add (or override) methods to print the appropriate information. Use constructors to automatically initialize the data members. Define the class AddressBook using previous defined clases. An object of…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT