brandon mac

Greenhorn
+ Follow
since Mar 10, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
10
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by brandon mac

If I may suggest I didn't understand and like using IDE either because of having problems as a beginner. So I will suggest this other program that I'm using and its great I have learned so much from this forum and the great people here.

JGrasp

Ensure your Java JDK is updated to the current as well
10 years ago
Mike,

Sorry for the confusion. The occurrence that I'm referring to is getting the count or the # of times a particular value appears given the arrays that i have mentioned.
10 years ago
Here is what I'm trying to do using arrays.

gather sales amount for the week
display the total of sales
display the average of sale
display the highest sale amount
display the lowest sale amount

using occurrences determine how many times the amount occurred for the week

make a sales main
make a sales data

This is what i have so far but I'm confused on how to start the occurrence and where it would be placed in order to get the information from the array

public class SalesData
{
private double[] sales; // The sales data

/**
The constructor copies the elements in
an array to the sales array.
@param s The array to copy.
*/

public SalesData(double[] s)
{
// Create an array as large as s.
sales = new double[s.length];

// Copy the elements from s to sales.
for (int index = 0; index < s.length; index++)
sales[index] = s[index];
}

/**
getTotal method
@return The total of the elements in
the sales array.
*/

public double getTotal()
{
double total = 0.0; // Accumulator

// Accumulate the sum of the elements
// in the sales array.
for (int index = 0; index < sales.length; index++)
total += sales[index];

// Return the total.
return total;
}

/**
getAverage method
@return The average of the elements
in the sales array.
*/

public double getAverage()
{
return getTotal() / sales.length;
}

/**
getHighest method
@return The highest value stored
in the sales array.
*/

public double getHighest()
{
double highest = sales[0];

for (int index = 1; index < sales.length; index++)
{
if (sales[index] > highest)
highest = sales[index];
}

return highest;
}

/**
getLowest method
@returns The lowest value stored
in the sales array.
*/

public double getLowest()
{
double lowest = sales[0];

for (int index = 1; index < sales.length; index++)
{
if (sales[index] < lowest)
lowest = sales[index];
}

return lowest;


}
}


public class Sales
{
public static void main(String[] args)
{
final int ONE_WEEK = 7; // Number of elements

// Create an array to hold sales amounts for a week.
double[] sales = new double[ONE_WEEK];

// Get the week's sales figures.
getValues(sales);

// Create a SalesData object, initialized
// with the week's sales figures.
SalesData week = new SalesData(sales);

// Create a DecimalFormat object.
DecimalFormat dollar = new DecimalFormat("#,##0.00");

// Display the total, average, highest, and lowest
// sales amounts for the week.
JOptionPane.showMessageDialog(null,
"The total sales were $" +
dollar.format(week.getTotal()) +
"\nThe average sales were $" +
dollar.format(week.getAverage()) +
"\nThe highest sales were $" +
dollar.format(week.getHighest()) +
"\nThe lowest sales were $" +
dollar.format(week.getLowest()));

System.exit(0);
}

/**
The getValues method asks the user to enter sales
amounts for each element of an array.
@param array The array to store the values in.
*/

private static void getValues(double[] array)
{
String input; // To hold user input.

// Get sales for each day of the week.
for (int i = 0; i < array.length; i++)
{
input = JOptionPane.showInputDialog("Enter " +
"the sales for day " + (i + 1) + ".");
array[i] = Double.parseDouble(input);
}
}

}
10 years ago
Design a program for a game.

Build a player for the game
Name the character
health of the player max 100
increase health by eating, increments of 15
attack power max 100, cannot attack if health is below 25, if character health is below 25 tell the character to replenish health


I'm reading through this example of what to do and its talking about constructors, mutators, and accessors which I have no idea about any of this.

Also I'm learning about breaking down the program into 2 sections so the player would be one part and the game would be the other part.



Okay I would like to know if I'm headed in the right direction with this but I'm trying to figure out how I'm going to make the player lose health so take damage and then what I can use to replenish the health to allow the character to attack again.









[/code]
10 years ago
I was able to figure this one out and understand methods pretty well now thanks for everyone's assistance.
10 years ago
Okay so from my previous post and what I have learned so far from asking for help on here I shall start with english instead of what I think should be written for code.

Task: Convert cups to quarts

Declare the double variables

cups, quarts

Declare result variable of conversion
cupsToQuarts
4 cups = 1 quart

Ask user to provide input
"How many cups do you have?"

Use user input of cups and convert to quarts with method CupsToQuarts

Display results

So I know how to start with the variables and that it would be a public static double I believe but don't really understand the methods and calling business part

I have a file that I have started but it won't let me attach it as a .java file so not sure if that would be helpful to see what I have done so far.

10 years ago
Joanne,

Good morning I think its because I was tired last night and so frustrated when I was playing with the code. Seems as if I goofed some stuff up.
10 years ago
so should it be a do while loop or just the while loop

while (input = JOptionPane.showInputDialog("Enter valid salary") salary <0 || salary > 250000)
10 years ago
When the user provides input for salary that is between the specific values it should then move to the next statement that will be displayed asking for the users input of years on the job, however if not inputted correctly i want the loop to take affect and ask for a valid salary
10 years ago



I believe there is still a problem with the way the loop is written because of the true status and it not moving forward
10 years ago
Still don't work
10 years ago
I'm so close on this with all the help I have received but just not there yet. The which statement for the loop is still not working I feel that there is something else that can work better is this possible any suggestions.
10 years ago
Joanne,

I removed the semi colon and reran it, however I think Rico has a valid point of the values that are contained in the which statement because its still not fully working. I also changed the or to the &&.
10 years ago
Rico,

Thanks so much for taking a few minutes to explain that. So with the following code

which (salary >=0 salary <= 250000) this is causing the problem and instead your saying is get rid of the which statement and use an if statement ??

if(salary <0)
make user input again
if (salary >250000)
make user input again

Is this some what close
10 years ago
Joanne,

I'm not the type of person to give up or quit but I don't think I know where to go with this as I have went thru the while command and the if statements I'm only doing a while loop not a do while loop. Please push me in the right direction you said a common typo are you talking about the while command I tried to use the && instead of the || and that didn't fix it either.
10 years ago