Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Intro Java Class Help

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 06-28-2008, 12:05 PM PM User | #1 codyland New to the CF scene   Join Date: Jun 2008 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Intro Java Class Help 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? :-( Code: ```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...
06-28-2008, 01:33 PM   PM User | #2
Moderator-san

Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Quote:
 Originally Posted by codyland 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? :-( Code: ```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...
Hello. So there are some basic things I can see without compiling it myself (Please list your errors next time so we can get through it as quickly as possible).

The first problem I see is this:

Code:
```  public static void main(String[] args);{
}```
So what you've done is you've created this method called main, then ended the statement, and then created this block for it that does nothing. I think what you meant was to put your code INSIDE the block for main and not ending it with a semicolon.

Remember, that when we are creating methods for Java we want it in main. For example a simple hello world application:

Code:
```public class HelloWorld
{

public static void main(String args[])
{
System.out.println("Hello World!");
}
}```
As you can see, we want our program to say Hello World, and so we put it inside the main function in order for the compile and the JVM to know what to run first.

That's all I see right now, let us know if you have any other errors.
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:57 PM.