Java Programming (MindTap Course List)
8th Edition
ISBN: 9781285856919
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 2, Problem 6PE
a.
Program Plan Intro
Inches to Feet
Program Plan:
Define the class “InchesToFeet”.
- Define the main method.
- Declare named constant variables to hold the number of inches in a foot.
- Compute number of feet in the given inches by dividing given number of inches and number of inches in a foot.
- Compute number of inches left by taking modulus of given number of inches and number of inches in a foot.
- Display number of feet in the given number of inches.
b.
Program Plan Intro
Inches to Feet Interactive
Program Plan:
Define the class “InchesToFeetInteractive”.
- Define the main method.
- Declare named constant variables to hold the number of inches in a foot.
- Create a scanner class object to get user input.
- Prompt the user to enter number of inches.
- Convert the user input and store it in a variable.
- Compute number of feet in the given inches by dividing given number of inches and number of inches in a foot.
- Compute number of inches left by taking modulus of given number of inches and number of inches in a foot.
- Display number of feet in the given number of inches.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
TOPICS: Using Classes and Objects
MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM.
2. Write an application that reads the (x,y) coordinates for two points. This should prompt for and read each of the four values individually. Compute the distance between the two points using the following formula:
Distance=(?2−?1)2+(?2−?1)2‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾√Distance=(x2−x1)2+(y2−y1)2
Testing: Include test exhibits for the following inputs:
(1, 2) and (1, 2) are distance 0
(4, 0) and (2, 0) are distance 2
(0, 0) and (3, 4) are distance 5
(0, 0) and (1, 1) are distance 1.414... (i.e., the square root of 2)
TOPICS: Using Classes and Objects
MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM.
3. Write an application that reads the radius of a sphere then calculates and displays the circumference, volume and surface area. Use the following formulas, in which r represents the sphere’s radius. Print the output to four decimal places.Circumference = 2 π rVolume = 4/3 π r3Surface Area = 4 π r2
Hint: Section 3.5 of the textbook describes the many methods of the Math class and how they are used. The Math class also contains pre-defined constants like π. Search on the web for how you can use these.
Testing: Include test exhibits for inputs that you choose. Make sure you check the results either with a calculator or some other independent source. Hint: Try Google!
Create a class that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics. Include a constructor that accepts values for each of the fields. Also
include a get method for each field. Create an application that instantiates several job applicant objects and pass each in turn to a Boolean method that determines whether each applicant is qualified for an interview. Then, in the main() method, display an appropriate method for each applicant. A qualified applicant has at least three of the four skills. Save the files as JobApplicant.java and TestJobApplicants.java.
Chapter 2 Solutions
Java Programming (MindTap Course List)
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a GUI application that calculates a car’s gas mileage. The application should let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked, the application should display the number of miles that the car may be driven per gallon of gas. Use the following formula to calculate MPG: MPG = Miles / Gallons. //Here are the given class fields and layout to help you with the coding. public class MPGCalculator extends JFrame //Components private JPanel panel; private JTextField gallonsInput; private JTextField milesInput; private JButton calcButton; //Constants for the window size private final int WINDOW_WIDTH = 360; private final int WINDOW_HEIGHT = 130; //Constructor // Set the title // Specify what happens when the close button is clicked. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Build the panel that contains the…arrow_forwardWrite a class that declares a variable named inches, which holds a length in inches, and assign a value. Display the value in feet and inches; for example, 86 inches becomes 7 feet and 2 inches. Be sure to use a named constant where appropriate. Save the class as InchesToFeet.java.arrow_forwardWrite a GUI application that calculates a car’s gas mileage. The application should let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked, the application should display the number of miles that the car may be driven per gallon of gas. Use the following formula to calculate MPG: MPG = Miles / Gallons. //Here are the given class fields and layout to help you with the coding. public class MPGCalculator extends JFrame //Components private JPanel panel; private JTextField gallonsInput; private JTextField milesInput; private JButton calcButton; //Constants for the window size private final int WINDOW_WIDTH = 360; private final int WINDOW_HEIGHT = 130; //Constructor // Set the title // Specify what happens when the close button is clicked. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Build the panel that contains the…arrow_forward
- Create a constructor for the Student class you created. The constructor should initialize each Student's ID number to 9999, his or her points eamed to 15, and credit hours to 3 (resulting in a grade point average of 3.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. ShowStudent2.java. Save the application asarrow_forwarda. Create a class named Pizza. Data fields include a String for toppings (such as “pepperoni”), an integer for diameter in inches (such as 18), and a double for the price (such as P699.00). Include methods to get and set values for each of these fields. Save the class as Pizza.java. b. Create an application named TestPizza that instantiates one Pizza object and demonstrates the use of the Pizza set and get methods. Save this application as TestPizza.java.arrow_forward0o.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
- 12 public class DayProg 13 public static void main(String[] args) { // Step 2: Construct a Day object representing today 14 15 16 // and assign it to a variable called aDay 17 Date aDay = new Date(); 18 19 // Step 3: Construct a Day object representing the day for our Exam1 on March 1, 2022, and assign it to a variable called examOne 20 21 // 22 // Date examOne = new Date(2022,03,1); 23 24 I. // Step 4: Declare three*integer variables called 25 // year, month and day with initial values of 2022, 4, 12. // 27 int year=2022, month=4, day=12; 28 30 // Step 5: Construct a Day object using the three variables // Date examTwo = new Date(2022,04,12); 31 32 and assign it to a variable called examTwo 33 34 35 // Step 6: Display the three days on separate lines // System.out.println(aDay.getYear() +""+aDay.getMonth() +""+aDay.getDay ()); System.out.println(examOne.getYear()+""+examOne.getMonth()+""+examOne.getDay()); System.out.println(examTwo .getYear()+""+examTwo.getMonth()+""+examTwo.getDay…arrow_forward1.In your game console class, add a start function which should prompt the user for an email address. -Use a regular expression to validate that it is a valid email address and prompt them again until they enter a valid one. -Next, prompt the user to enter a credit card number and use a regular expression to validate the credit card. -Prompt them again until they enter a valid one and once done, display the game menu. Existing Code below: class Game {constructor(name){this.name = name;}} class GameConsole{constructor(){this.games = [];} load(){var gameNames = ["Zelda", "Halo", "Mario", "The God Among Us\n"];for (var i = 0; i < gameNames.length; i++) {let game = new Game(gameNames[i]);this.games.push(game);}} log(){console.log("Games Loaded:");for (var i = 0; i < this.games.length; i++) {var name = this.games[i].name;console.log(name);}}} let gamecon = new GameConsole();gamecon.load();gamecon.log(); const prompt = require('prompt-sync')(); var adventurersName = ["Captain…arrow_forwardTOPICS: Using Classes and Objects MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM. 1. Write an application that prompts for and reads the user’s first and last name (separately), then displays a string composed of the first four characters of the user’s last name, followed by the first two letters of the user’s first name, followed by a random number in the range of 10 to 99. Assume that the last name is at least four letters long. Similar algorithms are sometimes used to generate usernames for new computer accounts. Testing: If the inputs were “Michael” and “Jackson,” the output should look like “JackMi42.” Include several tests with different inputs, including your own name.arrow_forward
- Create a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. Save the application as ShowStudent2.java.arrow_forward2. Write a class named MonthDays. The class's constructor should accept two arguments: • An integer for the month (1 = January, 2= February, etc.). • An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if only it is divisible by 400. For example, 2000 is a leap year but 2100 is not. 2. If the year is not divisible by 100, then it is a leap year if and if only it is divisible by 4. For example, 2008 is a leap year but 2009 is not. Demonstrate the class in a program that asks the user to enter the month (letting the user enter an integer in the range of 1 through 12) and the year. The program should then display the number of days in that month. Here is a sample run of the program: Enter a month (1-12): 2 [Enter] Enter a year: 2008 [Enter] 29 daysarrow_forwardA company accepts user orders by part numbers interactively. Users might make the following errors as they enter data: - The part number is not numeric. The quantity is not numeric. - The part number is too low (less than 0). - The part number is too high (more than 999). - The quantity ordered is too low (less than 1). - The quantity ordered is too high (more than 5,000). Create a class that stores an array of usable error messages; save the file as DataMessages.java. Create a DataException class; each object of this class will store one of the messages. Save the file as DataException.java. Create an application that prompts the user for a part number and quantity. Allow for the possibility of nonnumeric entries as well as out-of-range entries, and display the appropriate message when an error occurs. If no error occurs, display the message "Valid entry". Save the program as PartAndQuantityEntry.java.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
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY