1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
m_a_m_a [10]
3 years ago
11

The following program redundantly repeats the same expressions many times. Modify the program to remove all redundant expression

s using variables of appropriate types. (Your variables should be used to help solve the overall problem. You must use a sufficient number of variables to receive credit for solving this problem. Declare and initialize each variable in its own statement on its own line.)
Computers and Technology
1 answer:
IRISSAK [1]3 years ago
6 0

Answer:

The program is:

public class ComputePay {

public static void main(String[] args) {

// Calculate pay at work based on hours worked each day

System.out.println("My total hours worked:");

System.out.println(4 + 5 + 8 + 4);

System.out.println("My hourly salary:");

System.out.println("$8.75");

System.out.println("My total pay:");

System.out.println((4 + 5 + 8 + 4) * 8.75);

System.out.println("My taxes owed:"); // 20% tax

System.out.println((4 + 5 + 8 + 4) 8.75 0.20); } }

Explanation:

The first expression that is being repeated many times is the sum of 4+5+8+4. This sum can be stored in a variable that can be used instead of repeating this expression redundantly. Name this variable as hoursWorked

The value of hourly salary is also being used redundantly. So lets store this in a variable and name this variable as hourlySalary

Here the total pay is basically the product of hours worked and hourly salary. So lets store this value in a variable and names this variable as totalPay

Tax rate here is 20% So this can also be stored in a variable tax

Tax owed is the product of hours worked, hourly salary and and tax rate. So this value can also be stored in a variable and names it as taxOwed

So now the program without redundant expressions is given below:

public class ComputePay {

public static void main(String[] args) {

// Calculate pay at work based on hours worked each day

int hoursWorked = 4+5+8+4;

double hourlySalary = 8.75;

double totalPay  = hoursWorked * hourlySalary ;

double tax = 0.20;

double taxOwed = hoursWorked * hourlySalary * tax;  

//above statement can also be written as  taxOwed = totalPay * tax

System.out.println("My total hours worked:");

System.out.println(hoursWorked);

System.out.println("My hourly salary:");

System.out.println("$" + hourlySalary );

System.out.println("My total pay:");

System.out.println(totalPay);

System.out.println("My taxes owed:"); // 20% tax

System.out.println(taxOwed); }  }

You might be interested in
What should not be compromised when trying to meet standards and deadlines?
n200080 [17]
A i believe is the answer
5 0
4 years ago
Design and implement a class called Sphere that contains instance data that represent the sphere’s diameter. Define the Sphere c
Zolol [24]

Answer:

Import java.awt.*;

import java.util.*;

public class Sprhere

{// Instance Data private double surfaceA, volume, r, diameter; //Constructors public Sphere ()

{r = 0;diameter = 0; surfaceA = 0;volume = 0;}

public Sphere (double radius, double d, double SA, double v)

{this. r = radius; this. diameter = d; this. surfaceA = SA;this.volume = v;}

//--------------------------------------------------------------------// Accesors.//--------------------------------------------------------------------public double get Radius()

{return r;}

public double get Diameter()

{return diameter;}

public double get SurfaceA()

{return surfaceA;}

public double get Volume()

{return volume;}

//--------------------------------------------------------------------// Mutators.//--------------------------------------------------------------------

3 0
3 years ago
Which statement gives an advantage of multicellular organisms?
slava [35]

Answer:

D and B

Explanation:

Multicellular organisms thus have the competitive advantages of an increase in size without its limitations. They can have longer lifespans as they can continue living when individual cells die. Multicellularity also permits increasing complexity by allowing differentiation of cell types within one organism.

4 0
3 years ago
Read 2 more answers
Media applications that play audio or video files are part of a class of workkloads called "streaming" workloads (i.e., they bri
emmasim [6.3K]

Answer:

Following is the detailed answer as needed.

<h3>I hope it will help you!</h3>

Explanation:

8 0
3 years ago
Write a program to draw a text-based graph of a mathematical function f(x)
Makovka662 [10]
I have a very good example of the program you need written on Python. You can use this (sorry for bad tabulation):
import math import math def main(): function = input("Enter a function f(x):\n") x = 0 y = 0 for rows in range(10,-11,-1): for col in range(-10,11,1): x=col roundfx = round(eval(function)) if roundfx == rows: print("o", end="") if rows==0 and col==0 and not rows == roundfx: print("+", end="") if col == 0 and not rows == 0 and not rows == roundfx: print("|", end="") if rows==0 and not col==0 and not rows == roundfx: print("-", end="") else: if not rows == 0: if not col == 0: if not rows == roundfx: print(" ", end="") print() main()
4 0
3 years ago
Other questions:
  • Pointsyour company environment includes windows server versions 2003, 2008, and 2012. desktops range from windows xp and vista.
    13·1 answer
  • How do i unblock website on my school computer
    7·2 answers
  • True or false: Your digital footprint is all the information about you online that only you post. Group of answer choices
    12·2 answers
  • Write a program in c++ that asks the user for a sequence of n​integers, where the user provides the number of elements n​ then e
    12·1 answer
  • The ash and dust from a volcanic eruption can cause a ______ change in the environment.
    8·1 answer
  • Write a C program to calculate and display the coordinates of midpoint - M of a linesegment between two given points - say A and
    7·1 answer
  • me pueden ayudar con mi trabajo sii porfss si me dan la respuesta correcta y les doy la mejor coronita si​
    12·1 answer
  • Please help. will give u brainliest!! khan academy computers and the internet!!
    12·1 answer
  • Python Coding:
    15·1 answer
  • Which statement about analog and digital images is true?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!