Win a copy of Terraform in Action this week in the Cloud forum!

Shaylen Patel

Greenhorn
+ Follow
since Oct 23, 2013
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shaylen Patel



I need to implement these methods, how would i do so?

Create an account: Verify that username provided does not already exist.
Both username and password must be provided, and stored in the hashmap

Login to existing account has two possible errors: Username not found and
Incorrect password. If valid username/password pair is given, give a
Congratulations message.

Changing a password requires a correct username and current password to
be entered. If valid, prompt for a new password, and update the hashmap
with that value. Give Username not found and Incorrect password errors, as
needed.

In order to remove an account, the user must enter a valid
username/password pair. If not, give appropriate error messages.

Listing all accounts, list both the username and password (yes, this is not
normal, but you need to be able to access both key and value). If the
password hash is empty, give an appropriate error messages.
7 years ago
Traverse the tree. So when 2 birthdays with the same day it will list all of them In order from Jan 1 to Dec 31
7 years ago
How do i get the names/birthday in the text file, to print on the console
7 years ago
Here is my code so far,i have created a "birthdays.text" file with various peoples birthdays. How do I implement that into my code?
Thank your for any help.


7 years ago
I am new a creating GUIs and am not quite sure how to correctly make one. I have done the inheritance parts, and created two extra appliances: a washer and dryer. Creating the GUI is where i need the help.
Thank you for all responses.

Here are the instructions to my project.
Introduction to GUIs (+ some inheritance)
For this assignment, you are going to create a user interface that interacts with the setters and getters of some classes that you will create.
First, create an abstract class called Appliance. This abstract class should have two attributes (dealing with household appliances) and two abstract methods called turnOn() and turnOff(). These methods should return void.
Then, create two subclasses of Appliance that represent household appliances (like a Refrigerator or Stove ((don't use those!))). These subclasses should have two attributes that are specific to the various appliance. Each subclass should implement the turnOn() and turnOff() methods. These methods should print to the command line some information about the appliance as it turns on and off.
Now, the fun part! Create a GUI interface!
Your window should have two panels: one for each appliance subclass. Each panel should have 4 textboxes (with appropriate labels) to receive/display information that correspond to the 4 attributes (2 from Appliance and 2 from the subclass) for each subclass.You also need 2 buttons on each panel: A Get button and a Set button.
When the Get button is pressed, the text boxes should be filled with the information from the instantiated object of the appropriate subclass. When the Set button is pressed, the object should then contain the information contained that the user has altered.
In your main method, you should create an object of each subclass, and prefill it with information (either using the constructor or the setters), then display your GUI. You should now be able to get and set the information for your objects from the GUI.
Notes:
At least one of your attributes for each subclass should be numeric
Note that you will need to handle incorrectly formatted input (You can use exception handling to do this if you want to. Wrapper classes also will work)
If there is text in the boxes when the "Get" button is pressed, it should be overwritten by what is in the object
Remember that these two panels should both be on screen at the same time. You don't need 2 different windows, one window: 2 panels.


7 years ago
Hello, I need some help with my code.

Here is the question:
-In your main, you should create a thermostat and thoroughly test it. Be sure to showcase time passing and the temperature reaching the desired setting. Also, showcase switching modes from heating to cooling.

My question is, once it reaches the desired temp, would the thermostat turn off, and then how do you show switching from heating and cooling.
Thanks for the help.

This is what prints.
Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 69.0
Tue Feb 25 19:06:21 CST 2014
Tue Feb 25 20:06:21 CST 2014
Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 70.0



Here is my Class:

7 years ago
These are questions from the study guide my professor gave us. She did not give us the answers.
8 years ago

1. Consider the array:
s[ 0 ] = 7
s[ 1 ] = 0
s[ 2 ] = -12
s[ 3 ] = 9
s[ 4 ] = 10
s[ 5 ] = 3
s[ 6 ] = 6
The value of s[ s[ 6 ] - s[ 5 ] ] is:
a. 0.
b. 3.
c. 9.
d. 0.

2. Consider the program below:
public class Test
{
public static void main( String[] args )
{
int[] a;
a = new int[ 10 ];

for ( int i = 0; i < a.length; i++ )
a[ i ] = i + 2;
int result = 0;
for ( int i = 0; i < a.length; i++ )
result += a[ i ];
System.out.println( "Result is: "+ result );
} // end main
} // end class Test

The output of this program will be:
a. Result is: 62.
b. Result is: 64.
c. Result is: 65.
d. Result is: 67.

Analyze the following code (This is tricky!):
public class Circle {
public static int result1, result2;

public static void main(String [ ] args) {
int radius1 = 3;
int radius2 = 1;
twoCircles(radius1, radius2);
System.out.println(“The area of circle 1 with radius “ + radius1+” is “ + result1);
System.out.println(“The area of circle 2 with radius “ + radius2+” is “ + result2);
}

public static void twoCircles(int radius2, int radius1) {
radius1++;
radius2 *= radius1;
result1 = Math.PI * Math.pow(radius1,2);
result2 = Math.PI * Math.pow(radius2,2);
System.out.println(“The area of circle 1 with radius “ + radius1+” is “ + result1);
System.out.println(“The area of circle 2 with radius “ + radius2+” is “ + result2);
}
}

3. What radius1 is output in the main method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

4. What radius2 is output in the method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

5. What radius1 is output in the twoCircles method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

6. What radius2 is output in the twoCircles method?
a. 1
b. 2
c. 3 d. 4
e. none of the above

Analyze the following code:
public class Color {
private int red(r); //red hue
private int g; //green hue
private int b; //blue hue

public Color( ) {
red = 0;
g = 0;
b = 0;
}
}

7. True or False: The Color constructor is an example of an overloaded constructor?

8. If I have instantiated a Color object as follows:
Color color1 = new Color();

Which would properly call an Accessor method for the red instance variable
a. color1 = getR( );
b. int rValue = color1.toR( );
c. int rValue = color1.getR();
d. int rValue = getR(color1);

9. Say I want a specialized mutator method, setColors, that updates all three colors.
Which of the following methods would do this?
a. public int setColors( ) {
a. return red + b + g;
}

b. public void setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}
c. public setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}

d. public int setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}
8 years ago
and this is the client program

public class Chicago
{
private final int MAX = 6; // maximum face value

private int faceValue1; // current value showing on the die
private int faceValue2;
//-----------------------------------------------------------------
// Constructor: sets the initial face value.
//-----------------------------------------------------------------
public Chicago()
{
faceValue1 = 0;
faceValue2 = 0;
}

//-----------------------------------------------------------------
// Rolls the die and returns the result.
//-----------------------------------------------------------------
public void roll()
{
faceValue1 = (int) (Math.random() * MAX) + 1;
faceValue2 = (int) (Math.random() * MAX) + 1;

}

//-----------------------------------------------------------------
// Face value mutator. The face value is not modified if the
// specified value is not valid.
//-----------------------------------------------------------------
public void setFaceValue (int value)
{
if (value > 0 && value <= MAX)
faceValue1 = value;
faceValue2 = value;
}

//-----------------------------------------------------------------
// Face value accessor.
//-----------------------------------------------------------------
public int getFaceValue1()
{
return faceValue1;
}

public int getFaceValue2()
{
return faceValue2;
}

//------------------------------------------------------------------
// Play method to determine if this player scores a point or not
//------------------------------------------------------------------



//------------------------------------------------------------------
// Winner method to determine who wins the game
//------------------------------------------------------------------




}
8 years ago
this is what i have for playChicago

import java.util.*;
public class PlayChicago
{
public static void main(String [ ] args)
{
//Declare variables and instantiate objects
Chicago player1 = new Chicago();
Chicago player2 = new Chicago();
Chicago player3 = new Chicago();
Chicago player4 = new Chicago();

int p1=0, p2=0, p3=0, p4=0;
int playerWinner;
final int ROLLS = 6;
Die die1 = new Die();
Die die2 = new Die();

// Play Chicago
for(int roll = 1; roll <=ROLLS; roll++)
{
num1 = die1.roll();
num2 = die2.roll();

// Determine the winner


// Output the winner and scores
System.out.println("Player 1's score: " + p1 +
"\nPlayer 2's score: " + p2 +
"\nPlayer 3's score: " + p3 +
"\nPlayer 4's score: " + p4 + "\n");

if (playerWinner == 0)
System.out.println("A winner could not be determined");
else
System.out.println("Player " + playerWinner + " won!");

}
}
8 years ago
The dice game Chicago has eleven rounds numbered 2 -12. In each round, the player tries to
roll and score the number of the round, the numbers being the possible combinations with 2
dice.
If a player throws the correct number for that round they score 1 point (e.g., if they roll a 4
and a 2 for round 6, they score a point). If they throw any other number they don’t score (e.g.
if they roll a 5 and a 3 for round 10, they do NOT score a point). The highest total after 11
rounds wins the game. If there is a tie for the highest score, then a winner cannot be
determined.
You will need to add two additional methods to the Chicago class called play and winner that are
implemented as follows:

Method play:
Return value: int (the number of points to add to the player’s score: 0 or 1)
Method name: play
Parameter list: one parameter – an integer representing the round number (i.e. int
roundNumber)
Algorithm: (determine number of points to add to current score)
-If the sum of FaceValue1 and FaceValue2 is equal to the roundNumber return 1
(a point is given)
-Otherwise, return 0 (no point is given)

Method winner:
-Return value: int (the number of the player who has the greatest score: 1, 2, 3, 4 for
player 1, player 2, player 3, and player 4, respectively. Return 0 if no player can be
determined)
-Method name: winner
-Parameter List: four parameters – four integers, one for each player's score
-Algorithm: determine which player number has won. The score must be greater than
all the other scores, NOT greater than or equal. For example, who wins if the following
is true?

Client Program PlayChicago.java:
Algorithm:
Create a for- loop that will iterate from 2 to 12 (the round number)
For each player, you will need to roll the dice and play this round by calling the
appropriate methods in Chicago. You will have 8 statements in this for-loop, 2
for each player. Also, remember to use your compound assignment operator.
Once rounds 2 through 12 are completed, call Chicago's winner method with
the four players' scores. The value returned is the player number of the winning
player. Note that if there’s a tie for the high score, then no winner is determined.


8 years ago
Introduction
The international standard letter/number mapping found on the telephone is as follows:
1
2
ABC
3
DEF
4
GHI
5
JKL
6
MNO
7
PQRS
8
TUV
9
WXYZ
0

Write a method that returns a number, given an uppercase letter using the method definition:
public static int getNumber(char upperCaseLetter)

Input
phoneNumberStr - String

Output
phoneNumber translated to numbers - String

Sample Output:
Enter the phone number string
1-800-flowers
Phone: 1-800-3569377

Enter the phone number string
1800FLOWERS
Phone: 18003569377

Directions
1. Before each significant step, provide a comment explaining the step (do not comment
every line of code).

2. The input is a String. It is recommended you immediately convert this String to
uppercase since 1-800-flowers and 1-800-FLOWERS would both display 1-800-
3569377 as the phone number.

3. You MUST use a for-loop to step through phoneNumberStr.

4.Within the for-loop body, convert only the letters to their equivalent number using the
following algorithm:
a. If the current character of phoneNumberStr is an uppercase letter, call the
method getNumber to determine the number and append (or concatenate) to
phoneNumber. Note that to check if the character is a letter consider the
ASCII range of uppercase letters.

For example, if(phoneNumberStr.charAt(i) == 65) is true when the character
at index i is A.

Also, recall that when considering characters use single quotes – ‘A’

b. If the current character of phoneNumberStr is NOT a letter, you will need to
create a one-character substring and then append/concatenate this substring to
phoneNumber

c. Output the phoneNumber

EXTRA CREDIT (2 points) Include appropriate hypens to the actual phone number.
That is, 1-800-flowers or 1800FLOWERS would display the phone number as
1-800-356-9377
8 years ago
I need some help writing a program. My professor is the worst at explaining how to do these, and expects us know how to do this in a beginner java course

Write a Java application that prompts for the distance to be traveled in kilometers (you
will need to convert this to meters). Then, determine the number of burns required to
reach the destination within 35 meters. Output the burn number, how far the probe
traveled for the burn, and the remaining distance to reach its destination. You must use
a While loop in your script.

this is what the output should look like
Enter the distance to be traveled in kilometers:
50
Burn 1: Traveled 30000 meters
20000 meters to go
Burn 2: Traveled 12000 meters
8000 meters to go
Burn 3: Traveled 4800 meters
3200 meters to go
Burn 4: Traveled 1920 meters
1280 meters to go
Burn 5: Traveled 768 meters
512 meters to go
Burn 6: Traveled 307.2 meters
204.8 meters to go
Burn 7: Traveled 122.88 meters
81.92 meters to go
Burn 8: Traveled 49.152 meters
32.768 meters to go
You made it to Jupiter in 8 burns

additional info
determine the actual number of burns required for your spacecraft to travel from
Earth to Jupiter. Note that the average distance from Earth to Jupiter is 778412028 million km.
1. The Burn and distance traveled and the “meters to go” should appear on two
lines as shown in the sample output. Note that this print should be done within
the while loop.
2. “meters to go” on the second line of the burn information should be lined up with
“Traveled x meters” as shown in the Sample Output. To do this, you should use
the tab escape sequence, \t
3. For the distances, use a DecimalFormat object that prints only to three decimal
places.

Thanks for any feedback.
8 years ago