Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91334371
  • Price:- $20

Guranteed 24 Hours Delivery, In Price:- $20

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 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