Program of public class tempconverter

Assignment Help C/C++ Programming
Reference no: EM13764600

public class TempConverter
{
// Computes the Fahrenheit equivalent of a specific Celsius
// value using the formula F = (9/5)C + 32.
public static void main (String[] args)
{
//constant variables
final int BASE = 32;
final double CONVERSION_FACTOR = 9.0 / 5.0;
//declare variables
int celsiusTemp = 24; // value to convert

double fahrenheitTemp;
fahrenheitTemp = celsiusTemp * CONVERSION_FACTOR + BASE;
System.out.println ("Celsius Temperature: " + celsiusTemp);
System.out.println ("Fahrenheit Equivalent: " + fahrenheitTemp);
}
}
There are numerous opportunities for errors in any program, many times in places that seem too simple to require close attention.

Questions: Introduce the following errors, one at a time, in the program TempConverter.java. Write in your own words any error messages that the compiler produces. Fix the previous error each time before you introduce a new one. If no error messages are produced, try to run the code and explain what happens. If still no errors are produced, explain why.

a) Change TempConverter to tempConverter.

b) Remove the first quotation mark in the first string literal in the first System.out.println( ) statement.

c) Remove the semicolon at the end of the first println( ) statement.

d) Remove the last brace in the program.

e) Change the variable name fahrenheitTemp to fahrenheit in any one place in the code.

Part #2 - Arithmetic Expressions

Include the answers to these questions as comments above your code for Part 3 below.
1. Assume that you have a program that contains the following three lines of code. What is the value stored in the variable mystery after each line in the following code segment (You should have an answer like a) mystery has the value . . . b) mystery now has the value . . . )? Each line below assumes the previous ones have been executed.

a) int mystery = 5;

b) mystery = mystery - mystery / 2;

c) mystery = mystery + 1;

2. Assume that you have the following variables declared:
int a = 3, b = 10, c = 7;
double w = 12.9, y = 3.2;
What do the following expressions evaluate to in Java?

a) a / b

b) (double) b / a

c) a - b / c

d) w / (int) y

e) y / w

f) b % c / a

g) b % a

Part #3 - Programming
Write a Java program called Assignment1.java that will calculate the tip to leave at a restaurant. Your program must ask the user for the amount of the bill (this could contain decimals), and the percent they want to tip. The user will enter the percent they want to tip as an integer, e.g. 15 for 15%. Then your program should calculate and display the tip amount and the total bill after including the tip. To calculate the tip amount, multiply the bill amount times the percent divided by 100 (be careful of integer division). Make sure to use the following to get full credit:
• Comments explaining the main parts of the code (Getting input, calculating results, etc)
• Descriptive variable names with appropriate types
• Appropriate indentation between braces
• Use the NumberFormat class to format the output to be display as currency as demonstrated in the Coding Sample video.
For this and all subsequent assignments, provide a heading (in comments) described above and demonstrated in Part #1. Make sure your program is called Assignment1.java.

Sample Output
Below is sample output with input in bold. Your output does not need to match directly.

Sample 1
Enter the bill amount: $100.00
What percent would you like to tip: 15
Tip Amount: $15.00
Total amount with tip: $115.00

Sample 2
Enter the bill amount: $15.50
What percent would you like to tip: 10
Tip Amount: $1.55
Total amount with tip: $17.05

Reference no: EM13764600

Questions Cloud

Problems related to ethics 2 : Discuss what is meant by the term abandonment and describe ways that this claim can be avoided. What is a subpoena and who can accept it?
Future social security and medicare users : Tax payers - Future Social Security and Medicare users
Analyze the duty of loyalty in whistleblower cases : Analyze the duty of loyalty in whistleblower cases to determine to whom loyalty is owed and who shows the greater duty of loyalty. Support your analysis with specific examples. Then, suggest at least one (1) change to an existing law
Why doesnt us simply restrict all goods coming in from china : The team must write a speech which the Speaker must deliver about the current state of the U.S. macroeconomy to a number of amateur reporters who are unfamiliar with economics.
Program of public class tempconverter : There are numerous opportunities for errors in any program, many times in places that seem too simple to require close attention.
A screenshot of the modified assembly code : Modify the program to step the lights through a realistic sequence. Include conditional statements that ensure that assembly program only executes for 10 times.
What is the rationale behind the minimax regret rule : How does the adverse selection problem arise in the credit- card market? How do credit- card companies reduce the adverse selection problem that they face? To what complaint does this give rise?
Develop a questionnaire or interview : Develop a questionnaire or interview with a minimum of 10 questions that address the criminal justice issue that you have selected. Make sure your questions are clear, concise, and unbiased
What are the possible policy implications of your research : What are the possible policy implications of your research? Provide some examples of policies that might result from your research

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Lab11

ltbrgt

  A string of characters has balanced parentheses

A string of characters has balanced parentheses if each right parenthesis occurring in a string is matched with a preceding left parenthesis

  1 nbspwrite a c program to accept distance in kilometers

1. nbspwrite a c program to accept distance in kilometers coverts it to meters and then displays the result.2.

  Design your application according to the considerations

Design your application according to the considerations described above.  For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are

  Sum of two squares of natural numbers

The formula "x is a sum of two squares of natural numbers" can be written as ?y?z(x = y × y + z × z).

  What is wrong with this function

What is wrong with this function? Can you find problem in this code?

  Pros and cons of choosing two servers

Classify the two alternatives in terms of what type of application architecture they use. b. Outline the pros and cons of the two alternatives and make a recommendation to Fred about which is better.

  Inventory items stored in Sudbury

Give the details of all suppliers in the Sault Ste Marie, list all inventory items with a quantity less than 100 units and list all the inventory items stored in Sudbury

  Windows application that function like a banking account

Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance.

  Define a string of four characters and converts

Write an assembly program that defines a string of four characters and converts it into an unsigned 16-bit integer.

  Write a program that creates an array of 200 random numbers

Write a program that creates an array of 200 random real numbers between 0 and 200.  Using the statistics library, calculate and output the following: mean, median, variance, standard deviation, maximum value, and minimum value.

  Write a driver program called testrationalnumber.cpp

Write a driver program called testRationalNumber.cpp to test each of the above functions and overloaded operators in the RationalNumber class.

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