• Post Reply Bookmark Topic Watch Topic
  • New Topic

using for loop  RSS feed

 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,


I am new to programming, and I have to write a program to show the following below, with user's input in bold . I am using pen and paper to get the steps correct before i try doing the code.

Subjects: 1. Java
2. English
3. Math
4. Music
5. Law

Subject: 3

How many assignments shall i calculate?: 3
homework mark for assg 1: 54
exam mark for assg 1: 60
homework mark for assg 2: 79
exam mark for assg 2: 81
homework mark for assg 3: 83
exam mark for assg 3: 51

Math

average homework mark : 72.0

This is what i have so far, am I thinking in the right direction? any help would be greatly appreciated.

1. I am unsure what to use to read in the subject number after offering the menu.

2. Thinking of using a for loop with the counter set to 0, so that i can read in the number of assignments which will always be an integer between 1 and 4 (criteria)

system.out.println("How many assignments shall I calculate?:");
int =a
for (int a=0;a<5;a=a++) system.out.println("homework mark for assignment"+a);

for (int a=0;a<5;a=a++) system.out.println("examination mark for assignment"+a);

Thanks

 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need two loops. One loop should be fine

 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning. I don't know if anyone has greeted you and welcomed you to the ranch, but let me do so now. Hi. Welcome to the Ranch. :-)

I believe the answer to your question can be found Here in the discussion on entering integers. Re-read Campbell Ritchie's reply. This is a perfect entry for your keyboard input utility class. I also posted a link in there to a document here on the Ranch the gives a good introduction on handling user input.

Regards,
Robert.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!