Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

how to call getters and setters method if they are set using swing and if the user's entry will store on an array type and the user is allowed to enter data
Write a program to print the pay slip for each employee. Your program must use the properties of object-oriented programming which are polymorphism and inheritance in constructing the classes for the employees. Your program must have a menu that gives the user an option whether to process the pay slip for part time or full time employee. For a part time employee, the input will be hours worked, hourly rate and sales achieved, and for full time employee, it will be overtime rate, overtime hours worked and sales achieved. Assume the basic pay for full time is $2000.

Below is the commission rate for the sales achieved.

$250 - $600 = 2%
$601 - $900 = 4%
Over $900 = 6%
Palindrome Sentences

A palindromic sentence is a sentence that is spelt the same forwards as backwards, ignoring punctuation and case. For example, 'Madam, I'm Adam' is a palindromic sentence, as is 'Never odd or even'. 'Hello world' is not a palindromic sentence.

Extend your Palindromes class above to include the following method, which tests whether a given sentence is palindromic:

public static boolean isPalindromeSentence(String sentence) throws EmptyStackException, EmptyQueueException;


The methods Character.isAlphabetic() and Character.toLowerCase() could be useful here.
Palindromes

A word is said to be a palindrome if it is spelt the same forwards as backwards. For example, 'eye' and 'racecar' are palindromes, but 'hello' and 'book' are not.

Write a class Palindromes that uses a stack and/or queue to check whether a given word is a palindrome (case-sensitive). Use the structure shown below:

public class Palindromes {
/**
* Returns true if word is a palindrome, false if not
*/
public static boolean isPalindrome(String word) throws EmptyStackException, EmptyQueueException;
}

To test your code, Add a JUnit test class PalindromesTest, and include at least the following test cases:

testEmptyString(), which checks that the empty string is a palindrome
testBasicPalindromes(), which ensures that 'eye' and 'racecar' are palindromes
testBasicNonPalindromes(), which ensures that 'hello' and 'book' are not palindromes
testCase(), which checks that 'EyE' is a palindrome but 'Eye' is not
In a new role-playing fantasy game players must design their character by picking a point value for each of three characteristics:
• Strength, from 1 to 10
• Health, from 1 to 10
• Luck, from 1 to 10
Write a program that asks for a name for the character and asks for the point value of for each of the three characteristics. However, the total points must be less than 15. If the total exceeds 15, then 5 points are assigned to each characteristic
Welcome to Jack Bagbaga’s Quest
Enter the name of your character: Chortle
Enter strength (1-10): 8
Enter health (1-10): 4
Enter luck (1-10): 6

You have give your character too many points! Default values have been assigned:
Chortle, strength: 5, health: 5, luck: 5
You were hired as a programmer by TNP (Telepono ng Pilipino) a phone company. TNP employs a metering scheme in computing the telephone bill. The metering scheme is as follows: Calls made on a weekday between 6:00 AM to 6:00 PM are charged at 2.50 pesos per minute. Charges made at other times during a weekday are charged a discounted rate of 2.00 pesos per minute. Calls made anytime on a weekend are charged a weekend rate of 1.50 pesos per minute. Your job is to write a program that will ask the user to enter the following information: (a) an integer representing the day the call was made, let 1 represent Monday, 2 represent Tuesday and so on, (b) an integer representing the time (in 24 hour format) the call started (c) an integer representing the length of time or duration of the call in minutes (assume that all calls are rounded to the next minute, i.e, a call lasting 2 minutes and 35 seconds is billed as a 3 minute call). The rate applied depends on the day the call was made and on the time the call was
Write a program that calculates the annual cost of running an appliance. The program will ask the user for the cost per kilowatt-hour and the number of kilowatt-hours the appliance uses in a year:
Enter cost per kilowatt-hour in cents: 8.42
Enter kilowatt-hours used per year : 653
Annual cost: 54.9826
write a program where the user will input their respective subject and grades after that it will compute and display their gwa(general average).
Write a Java application that effectively uses Java collections to store pairs of unique colors and their unique hexadecimal values. (For example, Red -> FF0000).
Store up to 30 of these pairs.
Then write a GUI that displays the hexadecimal values using radio buttons to select a value, and a JLabel.
When a radio button is selected, the background of the JLabel should change to that color, and the foreground of the JLabel should change to its previous background

I am having difficulty with changing the forground color to the foreground color to the previously selected color
Modify the ListType class presented in this chapter by adding the following methods:
1. public int getCapacity()
This method should return the current capacity of the list
2. public void ensureCapacity(int minCapacity)
If the list’s capacity is less than minCapacity, this method should increase it so it is equal to min capacity.
Public void trimToSize()
This method trims the list’s capacity so it is equal to the list’s current size.

Demonstrate the new methods in a simple program.


**THIS IS THE ListType class PRESENTED IN THE CHAPTER TO MODIFY***

/** The ListType class is a concrete generic
class for storing a list of objects.
*/

public class ListType<E> implements GeneralList<E>
{
// Constants for the default capacity and
// the resizing factor.
private final int DEFAULT_CAPACITY = 10;
private final int RESIZE_FACTOR = 2;

// Private Fields
private E[] list; // The list
private int elements; // Number of elements stored

/** This constructor creates an empty list of the
default capacity.
*/
public ListType()
{
// The following statement causes a compiler warning.
// It is a necessary work-around because we cannot
// instantiate an array of a generic type.
list = (E[])(new Object[DEFAULT_CAPACITY]);
elements = 0;
}

/** This constructor creates an empty list of the
specified capacity.
@param capacity The initial capacity.
@exception IllegalArgumentException if the
specified capacity is less than one.
*/
public ListType(int capacity)
{
if (capacity < 1)
throw new IllegalArgumentException();

// The following statement causes a compiler warning.
// It is a necessary work-around because we cannot
// instantiate an array of a generic type.
list = (E[])(new Object[capacity]);
elements = 0;
}

/** Add an element to the end of the list.
@param element The element to add.
*/
public void add(E element)
{
// If the list is full, resize it.
if (elements == list.length)
resize();

// Add element to the end of the list.
list[elements] = element;

// Adjust the number of elements.
elements++;
}

/** Add an element at a specific index.
@param index The added element's position.
@param element The element to add.
@exception IndexOutOtBoundsException When index
is out of bounds.
*/
public void add(int index, E element)
{
// First make sure the index is valid.
if (index >= elements || index < 0)
throw new IndexOutOfBoundsException();

// If the list is full, resize it.
if (elements == list.length)
resize();

// Shift the elements starting at index
// to the right one position.
for (int index2 = elements; index2 > index; index2--)
list[index2] = list[index2 - 1];

// Add the new element at index.
list[index] = element;

// Adjust the number of elements.
elements++;
}

/** Clear the list. */
public void clear()
{
for (int index = 0; index < list.length; index++)
list[index] = null;
elements = 0;
}

/** Search the list for a specified element.
@param element The element to search for.
@return true if the list contains the element;
false otherwise.
*/
public boolean contains(E element)
{
int index = 0; // Index counter
boolean found = false; // Search flag

// Step through the list. When the element
// is found, set found to true and stop.
while (!found && index < elements)
{
if (list[index].equals(element))
found = true;
index++;
}

// Return the status of the search.
return found;
}

/** Get an element at a specific position.
@param index The specified index.
@return The element at index.
@exception IndexOutOtBoundsException When index
is out of bounds.
*/
public E get(int index)
{
if (index >= elements || index < 0)
throw new IndexOutOfBoundsException();
return list[index];
}

/** Gets the index of the first occurrence of the
specified element.
@param element The element to search for.
@return The index of the first occurrence of element
if it exists; -1 if element is not in the list.
*/
public int indexOf(E element)
{
int index = 0; // Index counter
boolean found = false; // Search flag

// Step through the list. When the element
// is found, set found to true and stop.
while (!found && index < elements)
{
if (list[index].equals(element))
found = true;
else
index++;
}

// Return the index of element or -1.
if (!found)
index = -1;
return index;
}

/** Determines whether the list is empty.
@return true if the list is empty; false otherwise.
*/
public boolean isEmpty()
{
return (elements == 0);
}

/** Remove a specific element from the list.
@param element The element to remove.
@return true if the element was found; false otherwise.
*/
public boolean remove(E element)
{
int index = 0; // Index counter
boolean found = false; // Search flag

// Perform a sequential search for element. When it is
// found, remove it and stop searching.
while (!found && index < elements)
{
if (list[index].equals(element))
{
list[index] = null;
found = true;
}
index++;
}

// If the value was found, shift all subsequent
// elements toward the front of the list.
if (found)
{
while(index < elements)
{
list[index - 1] = list[index];
index++;
}

// Adjust the number of elements.
elements--;
}

// Return the status of the search.
return found;
}

/** Remove an element at a specific index.
@param index The index of the element to remove.
@return The element that was removed.
@exception IndexOutOtBoundsException When index
is out of bounds.
*/
public E remove(int index)
{
if (index >= elements || index < 0)
throw new IndexOutOfBoundsException();

// Save the element, but remove it from the list.
E temp = list[index];
list[index] = null;
index++;

// Shift all subsequent elements toward
// the front of the list.
while(index < elements)
{
list[index - 1] = list[index];
index++;
}

// Adjust the number of elements.
elements--;

// Return the element that was removed.
return temp;
}

/** Resizes the list to twice its current length. */
private void resize()
{
// Calculate the new length, which is the current
// length multiplied by the resizing factor.
int newLength = list.length * RESIZE_FACTOR;

// Create a new list.
// Note: This statement causes a compiler warning.
// It is a necessary work-around because we cannot
// instantiate an array of a generic type.
E[] tempList = (E[])(new Object[newLength]);

// Copy the existing elements to the new list.
for (int index = 0; index < elements; index++)
tempList[index] = list[index];

// Replace the existing list with the new one.
list = tempList;
}

/** Replace the element at a specified index with
another element.
@param index The index of the element to replace.
@param element The element to replace it with.
@return The element previously stored at the index.
@exception IndexOutOtBoundsException When index
is out of bounds.
*/
public E set(int index, E element)
{
if (index >= elements || index < 0)
throw new IndexOutOfBoundsException();

// Save the existing element at that index.
E temp = list[index];

// Replace the element with element.
list[index] = element;

// Return the previously stored element.
return temp;
}

/** Get the number of elements in the list.
@return The number of elements in the list.
*/
public int size()
{
return elements;
}

/** Convert the list to a String array.
@return A String array representing the the list.
*/
public String[] toStringArray()
{
// Create a String array large enough to hold
// all the elements of the list.
String[] strArray = new String[elements];

// Store each element's toString() return value
// as an element in the String array.
for (int index = 0; index < elements; index++)
strArray[index] = list[index].toString();

// Return the String array.
return strArray;
}
}
LATEST TUTORIALS
APPROVED BY CLIENTS