in january i will be starting a computer science class using java. i went ahead and got the book so i could start practicing and hopefully stay on top of everything. i have come across a project that i just cant seem to figure out. i have got the first part accomplished but i am not doing something right with the numbers in the next part.
i put 2 hours of tv a day on the first part so that would be 7300 hours , 304.16666666666666666666666666667 days , or 0.83333333333333333333333333333334 years watching tv! i cant figure out how i am suppose to enter it, and doing something wrong with the tab and spacing.
also under the to do list it says to write a pseudocode algorithm for this and to write your program one step at a time. doesnt this mean the same thing?
any help would be appriciated!
sorry for adding all this to email but it wouldn't let me attach anything
You should be able to:
• Use sequential logic to write an algorithm
• Create a simple class to do some input from the keyboard, output and simple calculations
• Declare and define identifiers of primitive types
• Use constant identifiers where appropriate
• Request and process input from the keyboard
• Perform basic mathematical operations
• Display output to the monitor
Develop a simple program in Java that will interact with the user through some dialog. It will ask the user for his/her name and the number of hours that the watches TV per day (on average). The program will then display to the user the approximate number of hours and the equivalent number of days and the equivalent number of years that the user will have spent watching TV over the next 10 year
• The average hours of TV watched per day can have a decimal place when entered (ex, 2.5 or 5.3 or 6)
• The output should look exactly like that shown in the examples (pay close attention to line breaks and spacing)
• You can make the following assumptions: there are 24 hours in a day, 365 days in a year. This program does not account for leap years. Obviously, using 365 days in a year is not totally accurate, but it makes the solution to this problem much simpler
• Since there are always 24 hours in a day and 365 days in a year (for this program, anyway) you should make these constant values
• This program should be designed such that the number 10 years can easily be changed by the programmer in one place rather than throughout the program
PROJECT TO DO LIST:
Write a pseudocode algorithm for this project Test your algorithm before coding
Create a class called Project1 containing a method called main (which contains the code to implement this project). Your project should be saved in a folder named LastnameFirstnameProject1 (replace Lastname and Firstname with your own last and first name)
Write your program one step at a time, i.e. make sure one thing works before going on to something else. For instance, write the part that asks for the users name and says hello back to the user (and test it to make sure that it works) before writing the rest of the code
Test your program to make sure that it works!
Complete the documentation of the application by inserting comments and adhering to programming standards
You will find that the more effort you put into a problem prior to posting about it the better and quicker responses you will get. Please post your best code for solving the problem and ask a specific question about it.
Develop a simple program in Java that will interact with the user through some dialog. It will ask the user for his/her name and the number of hours that the watches TV per day (on average).***I completed this part.
The program will then display to the user the approximate number of hours and the equivalent number of days and the equivalent number of years that the user will have spent watching TV over the next 10 year.
I having trouble with this. It is suppose to look like this example:
7300 hours , or
304.16666666666666666666666666667 days, or
0.83333333333333333333333333333334 years watching TV!
not sure if i am suppose to use the Scanner keyboard=new Scanner(System.in);
or if i am suppose to just do System.out.print("....");
and it is suppose to be tabbed. i believe the correct way to do that is to insert '\t' a the beginning of the statement but when i try to compile it shows a bunch of errors.
Joined: Sep 09, 2010
Remember that one time when I suggested you post your actual code along with a specific question? Good times.
christopher Shepstead wrote:when i try to compile it shows a bunch of errors.
It is pointless to write "it shows a bunch of errors". WHAT the errors are is not just significant, it's really the point. HOW you fix the errors is determined by what those errors are. Solving a "could not find javac.exe" error is a vastly different problem than a "no such method: System.out.print1n()" error.
So...if you want help fixing your 'bunch of errors', you need to do two thing - and do both of them:
1) Post your code so we can see exactly what you are doing (and use code tags!!!)
2) Post the EXACT TEXT of the errors
Once you do that, you will get more help that you could ever want.
Kurt Van Etten
Joined: Sep 07, 2010
The project description in your post does not look like something out of a book; it looks more like an assignment from an online class ("Your project should be saved in a folder named LastnameFirstnameProject1"). Just saying...
Anyway, to answer the one specific thing you asked about, the Scanner class is used for input. For output to the screen, you'd use System.out.println() or something similar. The tab characters (and any other special characters, like newline characters) should be a part of the string being output, like so:
That should help get you started. If you need more guidance, then as others have mentioned, it helps to post your actual code, any error messages you're getting, and specific questions!