// This program will define 3 strings; It will make use of various string functi
ID: 3695159 • Letter: #
Question
// This program will define 3 strings; It will make use of various string functions and the concept of namespace.
#include <iostream.h>//
#include <stdlib.h>
#include <iomanip.h>
#include <string>
#include <your include file’s full name>
using namespace std;
using namespace name of namespace from the above file;
int main()
{
string first = "", second = "your first name here", third = "your last name here";
string new_string;
int i;
double wage, hours;
// Displaying the string
Display 3 strings in one line
// string length
Display the length of all 3 strings
// put strings together in another variable and print it
Concatenate your first name and last
// empty string
List if the string is empty or not
// use of replace
Use the REPLACE function for second string to say your first initial with your last name
// use of namespace
cout << " What is your hourly wage? ";
cin >> wage;
cout << " How many hours did you work? ";
cin >> hours;
// now call the program from the namespace
Calculate the wage using the program from another file
cout << " Good Bye..." << endl << endl;
system("PAUSE");
return 0;
} // end of main
Explanation / Answer
import javax.swing.JOptionPane; 02 import java.text.NumberFormat; 03 04 public class WageCalculator { 05 public static void main( String args[] ) { 06 07 JOptionPane.showMessageDialog(null, "Wage Calculator computes weekly wages It includes overtime pay"); 08 09 // input hourlyWage and hoursWorked from user 10 String input; // text input which must be converted to numeric form 11 double hoursWorked, hourlyRate; // input form user 12 13 input = JOptionPane.showInputDialog(null,"Enter Hours worked this week:" ); 14 hoursWorked = Double.parseDouble(input); 15 16 input = JOptionPane.showInputDialog(null,"Enter hourly rate: "); 17 hourlyRate = Double.parseDouble(input); 18 19 // declare variables to be calculated 20 double wages, federalTax, takeHomePay, overtimeHours, overtimePay; //added federalTax & takeHomepay here 21 22 // determine total wages without overtime pay 23 if (hoursWorked <= 40) { 24 wages = hoursWorked * hourlyRate; 25 overtimePay = 0; 26 federalTax = wages * .15; //tax rate 27 takeHomePay = wages - federalTax; // 15% federal tax 28 29 } else { 30 // overtime involved 31 wages = 40 * hourlyRate; // for 1st 40 hours 32 overtimeHours = hoursWorked - 40; 33 overtimePay = overtimeHours * ( 1.5 * hourlyRate); // 1.5 x's regular rate 34 wages += overtimePay; // add overtimePay to wages 35 federalTax = (wages + overtimePay) * .15; 36 takeHomePay = (wages + overtimePay) - .15; 37 } 38 39 // display wages using formatting 40 NumberFormat money = NumberFormat.getCurrencyInstance(); 41 42 String output = "Hours Worked: " + hoursWorked + 43 " Hourly Rate: " + money.format (hourlyRate) + 44 " Total Wages: " + money.format (wages) + 45 " Federal Tax: " + money.format (federalTax) + //added Federal Tax 46 " Take Home Pay: " + money.format (takeHomePay) + //added Take Home Pay 47 " Overtime Pay: " + money.format (overtimePay); 48 49 JOptionPane.showMessageDialog(null, output); 50 51 } // end method main 52 53 } // end class WageCalculator import javax.swing.JOptionPane; Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.