Question

In: Computer Science

I'm having trouble understanding this concept. I already completed the first part now I need to...

I'm having trouble understanding this concept. I already completed the first part now I need to convert the Second Part into a Control Structure. Please help answering the Problem. The first part will be below.

(Second Part)

Continuing with Control Structures

Control Structures are called such because they control the execution flow during the running of a program. There are 3 basic control structures: Sequence, Selection and Loop. This week let's work with the structures we already know - Sequence and Selection - but now let's add the loop structure to our logical programming toolbox.

Remember (from CIS 103) that the defining factor of a structured programming logic is that each control structure has exactly 1 entry point and 1 exit point. How do the 'break' and 'continue' statements, used in loop structures, that we learn about in Chapter 4, affect structured programming logic? (2 points, write answer in text box)

Chapter 4 (section 4.1 through 4.9)

Submit SalaryCalcLoop.java

Update SalaryCalc.java (Salary Calculator) from last week to now continue to take input for every employee in a company, and display their information until a sentinel value is entered (pg. 219), that exits the loop and ends the program.

(First Part Already completed)

import java.util.Scanner;

public class SalaryCalc {
double Rpay = 0, Opay = 0;

void calPay(double hours, double rate) {
if (hours <= 40) {
Rpay = hours * rate;
Opay = 0;
} else {
double Rhr, Ohr;
Rhr = 40;
Ohr = hours - Rhr;
Rpay = Rhr * rate;
Opay = Ohr * (1.5 * rate);
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
int shift = 0;
Double rate, hours;
System.out.println("Pay Calculator");
String ch = "";
//added loop here to take the inputs repetedly
do {
System.out.println("Enter Your Name");
name = sc.next();
System.out.println("Enter Your Shift, Enter 0 for Day, Enter1 for Night");
System.out.println("0=Day, 1= Night");
shift=sc.nextInt();
System.out.println("Enter Number of Hours Worked");
hours = sc.nextDouble();
System.out.println("Enter Hourly Pay");
rate = sc.nextDouble();
SalaryCalc c = new SalaryCalc();
c.calPay(hours, rate);
Double Tpay = c.Rpay + c.Opay;
System.out.println();
System.out.println("Calculate Pay");
System.out.println("Employee Name: " + name);
System.out.println("Employee Regular Pay: " + c.Rpay);
System.out.println("Employee Overtime Pay: " + c.Opay);
System.out.println("Employee Total Pay: " + Tpay);
if (shift == 0) {
System.out.println("Employee PayPeriod is Friday");
} else {
System.out.println("Employee PayPeriod is Saturday");
}
//asking user if they want to continue to enter another employee data
System.out.println("Press Y to continue.Other key to exit ");
ch=sc.next();
} while (ch.equalsIgnoreCase("y"));
}
}

Solutions

Expert Solution

If you need any corrections/clarifications kindly comment.

Program

import java.util.Scanner;

public class SalaryCalcLoop{
double Rpay = 0, Opay = 0;

void calPay(double hours, double rate) {
if (hours <= 40) {
Rpay = hours * rate;
Opay = 0;
} else {
double Rhr, Ohr;
Rhr = 40;
Ohr = hours - Rhr;
Rpay = Rhr * rate;
Opay = Ohr * (1.5 * rate);
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
int shift = 0;
Double rate, hours;
System.out.println("Pay Calculator");
String ch = "";

//added loop here to take the inputs repetedly
while(true)   
{

System.out.println("Enter Your Name(Type 'quit' to exit): ");
name = sc.next();
if (name.equals("quit"))
{
break; // exit infinite loop
}
System.out.println("Enter Your Shift, Enter 0 for Day, Enter1 for Night");
System.out.println("0=Day, 1= Night");
shift=sc.nextInt();
System.out.println("Enter Number of Hours Worked: ");
hours = sc.nextDouble();
System.out.println("Enter Hourly Pay: ");
rate = sc.nextDouble();
SalaryCalcLoop c = new SalaryCalcLoop();
c.calPay(hours, rate);
Double Tpay = c.Rpay + c.Opay;
System.out.println();
System.out.println("Calculate Pay");
System.out.println("Employee Name: " + name);
System.out.println("Employee Regular Pay: " + c.Rpay);
System.out.println("Employee Overtime Pay: " + c.Opay);
System.out.println("Employee Total Pay: " + Tpay);
if (shift == 0) {
System.out.println("Employee PayPeriod is Friday");
} else {
System.out.println("Employee PayPeriod is Saturday");
}
}
}
}

Output

Pay Calculator
Enter Your Name(Type 'quit' to exit):
yom
Enter Your Shift, Enter 0 for Day, Enter1 for Night
0=Day, 1= Night
0
Enter Number of Hours Worked:
155
Enter Hourly Pay:
100

Calculate Pay
Employee Name: yom
Employee Regular Pay: 4000.0
Employee Overtime Pay: 17250.0
Employee Total Pay: 21250.0
Employee PayPeriod is Friday
Enter Your Name(Type 'quit' to exit):
quit


Related Solutions

If anyone could simplify this for me. I'm having trouble understanding the material and I just...
If anyone could simplify this for me. I'm having trouble understanding the material and I just need a keep it simple stupid approach Discuss the various non influential as well as influential investments that company may have on their financial statements. Also compare and contrast how they are treated/recorded on the companies financial statements.
Using dev c++ I'm having trouble with classes. I think the part that I am not...
Using dev c++ I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues: The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the...
I'm having trouble understanding a CS assignment. I would appreciate it if you all code do...
I'm having trouble understanding a CS assignment. I would appreciate it if you all code do this for me. The template for the lab is below which you must use. You're only supposed to create/edit the product function. The assignment has to be written in asm(Mips) You will need to create a NOS table and use the structure below and write a function called product. The structure used in this program is: struct Values { short left; short right; int...
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the...
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the story. Why would Rama be set apart as a true hero? The story of Rama and Sita is a favorite story that parents tell their children. What purpose does the Ramayana serve as an instructional story for Indian culture? What effect do the test and temptations have on the heroic character?
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
Using Java This is two-part question, but I have already completed the first part and just...
Using Java This is two-part question, but I have already completed the first part and just need help with the second. Here I will provide both questions and my answer to the first part: Part I Question: Write a class called Dog that contains instance data that represents the dog’s name, breed, weight, birthdate, and medical history. Define the Dog constructor to accept and initialize instance data (begin the medical history with an empty line). Include accessor and mutator methods...
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in...
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in proper sterilization. Can someone please explain the role of both in proper sterilization?
I'm having trouble printing a fibonacci sequence using pointers with malloc's to get this output. now...
I'm having trouble printing a fibonacci sequence using pointers with malloc's to get this output. now printing with pointers: 0 1 1 2 3 5 8 13 21 34 55 89 Here's my code: #include <stdio.h> #include <stdlib.h> void fib1(int a[]); void fib2(int* a); } int main() {   int arr[2] = {0,1};   int *pointer;   arr[0]=0;   arr[1]=1;   fib1(arr);      return 0; } void fib1(int a[]){   printf("printing with arrays:\n");        for(int i=0; i<6; i++){     printf("%d %d ", a[0],a[1]);     a[0] = a[0] +...
I'm having trouble with knowing what type of dye you need to use for the microorganisms...
I'm having trouble with knowing what type of dye you need to use for the microorganisms in Microbiology, can you please explain
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT