Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies


ADVERTISEMENT

User Enter A Number For Width And Length - Calculate Area And Perimeter

Apr 27, 2014

I am trying to make a program so that the user has to enter a number for the width and length and it will give the area and perimeter:

import java.util.* ;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class jframe extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

[Code] ....

It is giving me an error saying that the ExitButtonHandler and ebHandler do not have classes but I don't understand why.

View Replies View Related

Compute Recursively Total Number Of Blocks In Triangle With Given Number Of Rows

Jul 8, 2014

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

triangle(0) → 0

triangle(1) → 1

triangle(2) → 3

View Replies View Related

How To Get Total Number Of Pennies In Dollar Amount For The Output Of Total Pay

Mar 28, 2014

I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:

Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Do not accept a number less than 1 for the number of days worked.

import java.util.Scanner;
import java.text.DecimalFormat;
public class PenniesForPay {
public static void main(String[] args) {
int numDays;

[Code] ....

totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?

View Replies View Related

JSP :: How To Get Total Number Of Pages In JavaScript

Apr 22, 2014

How to find the total number of pages in java script .how to achieve it.

View Replies View Related

Total Number Of Each Alphabetical Letter From A File

Nov 28, 2014

So far I've got it where the program is reading the file and returning

a:0
b:0
c:0
d:0
e:0
f:0
g:0
h:0
i:0
j:0
k:0
l:0
m:0
n:0
o:0
p:0
q:0
r:0
s:0
t:0
u:0
v:0
w:0
x:0
y:0
z:0

But I need it to print the letters and then the total amount of each character that is found in the file.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

[code]....

View Replies View Related

Calculate Total Price And Display Total In Order Class

Oct 11, 2014

I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.

My main class

package useorder;
import javax.swing.*;
public class UseOrder {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Order.display();

[Code] .....

The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?

View Replies View Related

Receive Information (Number) From User And Calculates Its Total

Apr 19, 2014

I wanted to write a simple code that receives information from the user (double-digit number and above) and calculates it's numbers.

For instance- The user wrote a number- 234, the software will return the number 9 (2+3+4 = 9).

Tried to use a loop for that, but I got stuck since I didn't know what to write.

This is what I've wrote so far

Java Code:

import java.util.Scanner;
public class Calculate {
public static void main(String[] args) {
System.out.println("Please type a number larger than 9");
Scanner type = new Scanner(System.in);
String number1 = type.nextLine();

for( int i = 0; i < number1.length(); i++ ){
int calculate = number1.charAt(i);
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Adding Number Of X Consecutive Values In Array And Get Minimal Total Value

Nov 9, 2014

Here is my problem: if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that?

For example:

X = 2
array[4] = (5,2,8,6,7)

start adding every 2 consecutive values as following:

array[0]+array[1] = 5+2 = 7 //minimal value
array[1]+array[2] = 2+8=10
array[2]+array[3] = 8+6= 14
array[3]+array[4] = 6+7=13

output:

minimal value = 7
indexes of minimal values are: 0 and 1

View Replies View Related

Counting Total Number Of Searches - Calling Price Method

Apr 23, 2015

How would I program a counter that will return the total number of search, failed searches and correct searches. The second thing is how can a return the price of the search methods with out calling for it specifically. Here is my current code.

package stu.paston.program7;
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
InventoryClass productData= new InventoryClass();

[Code] ....

View Replies View Related

JOptionPane - Display Total Number Of Goals Scored By All Players

May 22, 2014

JOptionPane.showMessageDialog(null,myRoster.totalGoalsScored + " is the total number of goals scored by all the players on the roster");

HOW CAN I CALL THE METHOD totalGoalsScored and display it using JOptionPane

ERROR: CAN NOT FIND SYMBOL

View Replies View Related

Calculate SUM And AVERAGE Of ODD Number Digits Between 25 And 75

Jun 19, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive).

The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Fibonacci Sequence - Calculate Nth Number

Apr 29, 2014

Write a recursive method that calculates the Nth number in the Fibonacci sequence. The first and second numbers in the sequence (the base cases) are both 1. After that, each subsequent number is the sum of the previous two. Stated a bit more formally:

fib(n)={1fib(n−1)+fib(n−2)n<2otherwise

For example, here is the first few numbers in the sequence:

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Your fib method should be part of a class named Fibonacci. In addition to the fib method, the Fibonacci class should have a main method that calls fib(9). If the result doesn't equal 34, you should print an error message. Otherwise, it should print out a message saying that it was successful.

After writing your Fibonacci class, answer the following question: How many times is the fibonacci method called when calculating the 5th number in the sequence?

View Replies View Related

Calculate The Factors Of A Positive Integer Number

Mar 16, 2014

lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

i don't get why that is.

package assignment7;
public class Exercise3
{
public static void main(String[] args)
{
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next())

[Code]...

View Replies View Related

Calculate Factors Of Positive Integer Number

Mar 17, 2014

Lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

I don't get why that is.

Java Code :

public class Exercise3
{
public static void main(String[] args) {
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next()) {
int n = (int)Math.round(Math.pow(2,p)) - 1;
System.out.printf("%d 2^%d-1%d", p, p, n);
if (Primes.isPrime(n))

[Code] ....

View Replies View Related

Java Code To Calculate Variance Of A Set Of Number?

May 2, 2014

I'm trying to write a java code that calculates the varince of a set of number and I wanted to know if this is the proper way to do it.

for (int i = 0; i <= (myArray.length - 1); i++){
variance = Math.pow((myArray[i] - average), 2);

}

View Replies View Related

Calculate Nth Fibonacci Number And Returns That To User

May 1, 2014

I have to create a program that calculates the nth Fibonacci number and returns that to the user. Fibonacci said his number sequence would describe the ideal breeding patterns of immortal rabbits. So, you are going to make this vision a reality.

First, take in a numeric value from the user and calculate that value in the fibonacci series. Next, find an image of a rabbit and display the image on a GUI (put the image as an icon on a label!) the number of times returned by the algorithm (Put all the aforementioned labels on one panel with FlowLayout!).

You need to remove the old images from the Panel. Probably the easiest way to do this is to create a whole new panel and remove the old one (hint: the remove method of JPanel should come in handy)

You could use an array of JLabels
You will need to create a new JLabel and add each member of the array to the panel
I should be able to scroll to see any images that are off screen

I am having difficultly on to making the array list for JLabel, and getting the Fibonacci sequence to show the pictures of rabbits. Below is my current code.

import java.awt.FlowLayout;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Rabbit extends JFrame

[Code] ....

View Replies View Related

Get Certain Number Of Items And Then Calculate How Much Every Item Cost

Jan 4, 2015

This is supposed to get a certain number of items, and then calculate how much every item costs. It adds up the sum of those prices and checks if it is over 150$, if it is, it returns true, if it's not, it returns false.

import java.util.*;
class Cust
{
public static boolean DelPay (int a) {
Scanner reader=new Scanner (System.in);
int b,s=0;
for (int i=1;i<=a;i++) {
b=reader.nextInt();
s=s+b;
}
if (s>150)
return true;
return false;
}
}

View Replies View Related

Parallel Program - Calculate SUM And AVERAGE Of Odd Number Digits Between 25 And 75

Jun 11, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Unable To Print Out Results Of Program That Calculate Number Of Seats

Nov 11, 2014

I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.

I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.Is it possible, or doIhave to create a method in Parties class to solve the problem?

This is what I have now.

for (Parties p : h.geral) {
show += String.format("Constituency - %5s - %5s - %d%n",
p.getConstituency(), p.getParty(), p.getNum_seats());
}

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

1. Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.

b) Output must look as follows:

Size of land in acres: 3.5
Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.
b) Output must look as follows:

Size of land in acres: 3.5 Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

this is what i got so far

public class Land
{
public static void main(String[] args){
double nrAcres = 3.5;
int feetInAcre = 43560;
double feetInTract = nrAcres * feetInAcre;
System.out.println("Size of land in acres: " + nrAcres + "
Size of land in square feet: " + feetInTract);
}
}

i tried to compile it but it says

error: class names, Land, are only accepted if annotation is explicitly requested 1 error

what is wrong with my code

View Replies View Related

How To Add A Method To Calculate Mean Of Length Of Each Word Output

Mar 6, 2014

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Assignment extends Applet implements ActionListener {
TextArea textInput = new TextArea(); // user input
Button analyzebutton = new Button("Analyze");
Button resetbutton = new Button("Reset");
Label lbloutput = new Label ("Please enter text into the textbox!");

[Code] .....

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved