473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Please help me on this BASIC Java programming question...

My professor gave us the following assignment:

Write a Java program to compute the number of days for the following scheme. The recipient receives a penny on day 1 and the amount is doubled on subsequent days. That is on day 2 the amount received is 2, on day three 4 pennies, day four 8 pennies and so on. The recipient accumulates the amount received. Write a program to compute how many days will it take for the recipient to accumulate more than 100 dollars.

Here is the code i came up with but continue to receive errors when compiling...what is wrong? :-(

import java.util.*;

public class assignment4 {

public assignment4() {
}
public static void main(String[] args);{
}

int dailyAmount, numberOfDays;
double totalAmount;

Scanner keyboard = new Scanner(System.in);

totalAmount = 0;
dailyAmount = 1;
numberOfDays = 1;

while (totalAmount <= 100)
{
totalAmount = dailyAmount*2;
numberOfDays++;
dailyAmount = dailyAmount*2;
}
if (totalAmount >= 100)
System.out.println("The total number of days it took for the balance to equal $100 was" + (numberOfDays));


}

Thank you in advance for any help you can give...
Jun 25 '08 #1
2 1241
r035198x
13,262 8TB
Do the Maths first. You have a geometric progression with a = 1 and r = 2.
The sum of the first n terms is given by
a(1- r(^n)) / (1 - r).
You have been given the required sum as 100, so rearrange the above
for n.
You can then write a function based on your equation for n.
Realize that while n in your function may be non-integral, you'd need to round it up to give the correct response to the question.

P.S When posting compilation problems, include the error message reported by the compiler.
Jun 25 '08 #2
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. public class assignment4 {
  2.  
  3.     public assignment4() {
  4.     }
  5.     public static void main(String[] args);{
  6.     }
  7.  
  8.         int dailyAmount, numberOfDays;
  9.         double totalAmount;
  10.  
  11. // and more statements follow ...
  12. }
  13.  
The structure of that class doesn't make any sense: statements should be put
in the body of methods and constructors, not somewhere else in a class.

Like this:

Expand|Select|Wrap|Line Numbers
  1. public class X {
  2.    public X() { // your constructor
  3.       // statements for your ctor go here ...
  4.    }
  5.    public static void main(String args) { // the main entry point of your program
  6.       // statements go here ..
  7.   }
  8. }
kind regards,

Jos
Jun 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
10
by: Robert | last post by:
Where can i find a free web- based VC++ course? (also i've to dowanload it) I'm interested also in VB and C++ thanks, Robert
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
9
by: takeiteasy | last post by:
Hello everyone, I've got a question about programming by using Java applet and the question is : Design a web page containing an applet that simply switches from one image to the next with some...
28
by: grappletech | last post by:
I took Pascal and BASIC in a couple of beginner programming courses about a decade ago and did well with them. I am good with pseudocode, algorithms, and the mathematics of programming. I decided...
2
by: shblack | last post by:
Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues...
28
by: Hussein B | last post by:
Hey, I'm a Java/Java EE developer and I'm playing with Python these days. I like the Python language so much and I like its communities and the Django framework. My friends are about to open a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.