Change Program Below To Array
Feb 14, 2014
I need to change the program below to an "array"....
public class RecursiveFibonacci {
public int fibonacci(int n) {
int result;
if (n == 1 || n == 2)
result = 1;
else {
int n1 = fibonacci(n-1);
int n2 = fibonacci(n-2);
[code]....
View Replies
ADVERTISEMENT
Jan 22, 2015
I want to programmatically change the default program which an extension is opened in. So .resantic extensions for example to run in my jar file when I double-click on it. I know i need a bat file or exe file because i can't directly run the jar file. But i was wondering if its possible to run it if its an executable jar file. Else i can just make a bat file that runs my program. Also how can i on double click send the path to the file that was clicked in the args[] array so i can open the actual file aswell instead of just opening the program?
View Replies
View Related
Sep 4, 2014
So obviously I'm new to java and i need to write a program that gives exact change in quarters, dimes, nickels, and pennies. For some reason it seems to work correctly but the nickels never is correct and I'm not sure why, seeing as though everything else is.
Java Code:
public class Coins{
private int c;
public Coins(int coins){
c = coins;
}
public void calculate(){
int quarters = c / 25;
[Code] .....
View Replies
View Related
Aug 8, 2014
I would like to make an incremental change to an existing Java program. And the program has been installed on the user's machine. Now I only want to do an incremental download (to minimize the download time) to update the program.
View Replies
View Related
Sep 20, 2014
write a program that calculates the change due to a customer by denomination; that is, how many pennies, nickels, dimes, etc. are needed in change. The input is to be purchase price and the size of the bill tendered by the customer($100, $50, $20, $10, $5, $1).
View Replies
View Related
Nov 2, 2014
I know how to do this program it is just not coming to me. The whole point is to calculate and display the base (base-2 or binary, base-8 or octal and base-16 or hexadecimal) in representation of 'N'. The symbols A, B, C, D, E, F should display 10, 11, 12, 13, 14, and 15 in hexadecimal system.
import java.io.*;
import java.util.Scanner;
public class ChangeBase
{
public static void main(String[]args) {
double num;
[Code]...
View Replies
View Related
Jul 23, 2008
Its just two problems:
1.Write a Java Program that calculates the change for a cashier. The program requests the cost of the item. The user then types in the cost. The program then outputs the cost of the item including the sales tax (use 6% as the sales tax value). The program next requests and recieves the amount tendered by the customer. Finally, the program outputs a summary of all figures, including the amount of change due to the customer. Name the program as Change.java.
This program has the following attributes and methods:
double cost;
double tax;
double payment;
double getCost();
double getTax();
[code].....
2. Create a java program named Numbers whose main() method holds two integer variables. Assign values to the variables. Pass both variables to methods named sum() and difference(). Create the methods sum() and difference(); these compute the sum and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results. Name the program as Numbers.java.
View Replies
View Related
Oct 28, 2014
SO for my project, we have to create a program where we input two four letter words, and using a list of words our teacher provided us and only changing one letter at a time, make the words match.For example, you input BALD and CALL and it would output BALD BALL CALLWe have to use recursion to do this, and I'm totally lost as to where to even begin.
View Replies
View Related
Feb 13, 2015
I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:
Java Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemo {
//Global Variables
static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue .
static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .
[Code] ....
The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.
View Replies
View Related
Dec 7, 2014
I have a 2d array that i am manipulating. In my class i have a constructor that takes the dimensions of the array and within th econstructor i need to randomly fill the array. However, when i try to manipulate it in the test program, all that prints out are the default values.
here is the class
import java.util.*;
import java.lang.Math;
import java.util.Arrays;
import java.util.Random;
class SummerStats
[Code] .....
And here is the printout
Enter number of rows(people):
3
Enter number of columns(years):
3
Enter number of person to find sum salary:
1
Enter year to find Max salary of that year:
1
[]
[]
The max salary is at index: (0, 0, )
The largest salary ocurred in year: 0
The sum of person 1 is: 0.0
The total of all salaries is: $0.0
The max salary in year 1 is: 0.0
The average salaries for each year:
0.0, 0.0, 0.0,
The total salary for each person is recorded below.
And the last method called doesn't finish or printout ie the program doesnt end
View Replies
View Related
Dec 11, 2014
I am trying to change an input String to an array of characters, but it only stores the word before the space into the array. Here is the code:
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".I am trying to change an input String to an array of characters, but it only stores the word before the space into the array.Here is the code:
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".
View Replies
View Related
Dec 14, 2014
I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :
1)enter which car he wanna move,
2)what direction (w,a,s,d) and after that,
3) how many moves( not out of bound) he wants to make, and finally
4) we print out the new parking lot for his next move
And i am stuck at how to move the car to corresponding position and then prompt user for the next move?
For example:
I want to move A to the right by 1 (d)
擷取.PNG
print result:
擷取1.PNG
How do I do that? The code that i have right now
public class CarParkGame {
public static void main( String [] args) {
String carPark[][] = new String [6][6] ;
carPark[0] = new String[] {"A","A","A","0","0","0"};
carPark[1] = new String[] {"b","0","0","0","0","c"};
carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};
[Code] .....
View Replies
View Related
Apr 20, 2015
I am new to OOP, i am not sure if this is the correct approach or not. Write a class named CreditCard that has (at least) the following member variables:
- name. A String that holds the card holder's name.
- cardNumber. A field that holds the credit card number.
- balance. A double that stores the current credit card balance.
- spendingLimit. A double that stores the spending limit of the card holder.
- Bonus: additional fields that you can think of.
In addition, the class should have the following member functions:
- Constructor. The constructor should accept the card holder's name and card number and assign these values to the object's corresponding member variables. The constructor should initialize the spending limit to $2,000 and the balance to $0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's member variables.
- purchase. This function should add the amount specified as a parameter to the balance member variable each time it is called.
- increaseSpendingLimit. This function should add 500 to the spendingLimit member variable each time it is called.
- payBill. This function should reset the balance to 0.
- Input validation: Whenever a credit card number is modified, verify that it is of reasonable length.
Demonstrate the class in a program that creates a CreditCard object and allows the user to change and view the state of the credit card with a menu driven program.
View Card Information.
- Purchase an Item: ask the user the purchase amount and increase the card balance accordingly.
- Pay Bill: call payBill method to set the balance to 0.
- Increase Spending Limit: ask the user how much the spending limit should be, and call the increaseSpendingLimit function the appropriate number of times.
[CODE]
import java.io.*;
import java.util.Scanner;
public class CreditCard
{
Scanner input = new Scanner(System.in);
//data members
private String holderName;
private int cardNumber;
private int accountBalance;
private double spendingLimit;
[Code] ....
View Replies
View Related
Oct 7, 2014
I am trying to write a program where I input numbers and if both arrays contain the same numbers it prints out identical. If not it prints out not identical. The issue I am having is that it says I am missing return statement at the very end of my program (the last bracket).
I added the else at the very end before the return true and this was the error that occurred. However is I remove the else all it says is lists are not identical even if they are?
import java.util.*;
import java.util.Scanner;
import java.util.Arrays;
public class Tester {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
[Code] ....
View Replies
View Related
Oct 16, 2014
i'm trying to write a program that uses an array to store 10 numbers. The numbers should be randomly generated ( Math.random() ), and they should be between 1 and 100 ( 1 and 100 inclusive ). The program should produce an output like the one below:
Element 1 = 23 ( Odd )
Element 2 = 15 ( Odd )
Element 3 = 32 ( Even )
Element 4 - 10 ( Even )
Element 5 - 99 ( Odd )
Element 6 - 1 ( Odd )
[Code]...
I have written code for this but its only showing me 0's after first number can you check whats wrong with my code. my code is.
class even/odd{
public static void main(String[]args){
int y=0;
int z=0;
int[] array= new int[11];
for(int x=1; x <array.length ; x++){
array[x]= (int) (Math.random()* 100);
[Code]...
View Replies
View Related
Apr 25, 2014
Ok, so the program we are supposed to do is to create implement a employee class then create a main tester class that can accept user inputs for 5 employee names, salaries, and performance rating. After that, we have to input code to calculate a provided raise amount, then print out the array with the updated raises. I have completed the program with no syntax errors, but it doesn't do anything. not even a screen comes up on my end to accept user inputs. I know its something basic, but what am i missing
Employee class
public class Employee
{
private String employeeName;
private int salary;
private int performanceRating;
[Code] ....
View Replies
View Related
Mar 7, 2015
Java Code:
public synchronized boolean isHit (FilledRect missile) {
for (int col = 0; col < aliens[0].length; col++) {
for (int row = 0; row < aliens.length; row++) {
if (aliens[row][col]!= null && aliens[row][col].overlaps (missile)) {
aliens[row][col] = null;
return true;
}
return false;
}
}
} mh_sh_highlight_all('java');
And I get an error saying that it cannot find symbol method overlaps. So is there something wrong that I am doing?
View Replies
View Related
Jul 11, 2014
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.
A sample run of the program is shown below:
Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1
View Replies
View Related
Apr 8, 2015
So I'm trying to write a program that prints out the "most-repeated integer" in an Array.
For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.
public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);
[Code]...
View Replies
View Related
Mar 3, 2014
i need to create a program that asks the user for an array and then asks the user to fill in the slots of the array but i have to do it in a method
View Replies
View Related
Feb 3, 2014
I'm required to create a program that finds the minimum value in an Array of integers.
Here is my approach :
public class Person {
public static void main(String [ ] args){
int theArray[]=new int [10];
int result = 0;
for (int i:theArray){
if (i < Integer.MAX_VALUE)
[Code]...
I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..
View Replies
View Related
Feb 19, 2015
Working on a program that creates an array from a file, organizes it in various ways, and then prints the results. Right now I'm specifically having trouble with the printAry() method - when I try to run it, I receive a NullPointerException for the active line in printAry() (EDIT: line 102). Not sure which sections are important to this, so I will include the client class and most of the service. I realize that the amount of documentation I included is not necessary, but it is required for the class.
class Lab3StudentAryService
{
private int count;
private Lab3StudentData [] studentAry = new Lab3StudentData[50];
/*
@param: none
@return: none
reads file and converts to array.
*/
public void fillAry() //constructor
{
Scanner scan = new Scanner(System.in);
[code]....
View Replies
View Related
Apr 23, 2015
import java.util.Scanner;
public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;
numbers = readArray();
reverse = reverseOrder(numbers);
[Code] ....
I have to write a program that takes an order of numbers and print the reverse order of those numbers.
the out put i receive is:
How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302
View Replies
View Related
Aug 2, 2014
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.
A sample run of the program is shown below:
Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1
View Replies
View Related
Aug 18, 2014
Write a program to initialize and display variable size array.
View Replies
View Related
Mar 19, 2015
I was wondering if it's possible to do this: I want to build a java program that reads a java array from a text file.
Then I want to read it, and output it in a different format.
The reading and out is easy - as text.
But how can I incorporate the read text in to a java valid array in my program, which I can use?
Is this even possible?
View Replies
View Related