Purchase Solution

Assistance with Java

Not what you're looking for?

Ask Custom Question

First Problem
I need help answering the following questions. I tried to do this in Java but I couldn't get it to execute.
int numValue = 10;
int answer = 0;
switch(numValue)
{

case 5: answer += 5;
case 10: answer += 10;
case 15: answer += 15;
break;
case 20: answer += 20;
case 25: answer += 25;
default: answer = 0;
break;
}
System.out.println("Answer: " + answer);

• What is the value of answer if the value of numValue is 10?

• What is the value of answer if the value of numValue is 20?

• What is the value of answer if the value of numValue is 5?

• What is the value of answer if the value of numValue is 17?

• Is the break statement in the default case needed? Explain?

Second Problem - need assistance with the area highlighted in yellow. Design the logic and write the rest of the program using a nested statement. They are using JOptionPane.showInputDialog.
Productivity Score Bonus
<= 30 $25
31-79 $50
80-199 $100
>=200 $200

// EmployeeBonus.java - This program calculates an employee's productivity bonus.

import javax.swing.*;

public class EmployeeBonus
{
public static void main(String args[])
{
// Declare and initialize variables here.
String employeeName;
double numTransactions;
String transactString;
double numShifts;
String shiftString;
double dollarValue;
String dollarString;
double score;
double bonus;
final double BONUS_1 = 25.00;
final double BONUS_2 = 50.00;
final double BONUS_3 = 100.00;
final double BONUS_4 = 200.00;

// This is the work done in the housekeeping() method
employeeName = JOptionPane.showInputDialog("Enter employee's name: ");
shiftString = JOptionPane.showInputDialog("Enter number of shifts: ");
transactString = JOptionPane.showInputDialog("Enter number of transactions: ");
dollarString = JOptionPane.showInputDialog("Enter transactions dollar value: ");

numShifts = Double.parseDouble(shiftString);
numTransactions = Double.parseDouble(transactString);
dollarValue = Double.parseDouble(dollarString);

// This is the work done in the detailLoop() method

// Write your code here (Design the logic and write the rest of the program
//using a nested if statement.

// This is the work done in the endOfJob() method
// Output.
System.out.println("Employee Name: " + employeeName);
System.out.println("Employee Bonus: $" + bonus);

System.exit(0);
}
}

Purchase this Solution

Solution Summary

The assistance with Java statements are determined.

Solution Preview

The first part of this solution deals with the Java switch statement.

The switch statement in Java is a way of choosing between several
alternatives. It is similar to an if/else statement but it easily
allows for several options. The following code shows a switch
statement:

int numValue = 10;
int answer = 0;
switch(numValue)
{

case 5: answer += 5;
case 10: answer += 10;
case 15: answer += 15;
break;
case 20: answer += 20;
case 25: answer += 25;
default: answer = 0;
break;
}
System.out.println("Answer: " + answer);

The control flow for a switch statement is that execution passes to
the first matching case and then falls through each set of statements
till a break statement is encountered. We can see that with the
following questions.

What is the value of answer if the value of numValue is 10?

In this situation we match the "case = 10" statement. This leads us
to execute answer += 10; ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Javscript Basics

Quiz on basics of javascript programming language.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.