Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Can you someone help me with my homework for java... Please

1. ## Can you someone help me with my homework for java... Please

Here is the assignments my Professor give me. Thank You again.

CS 111 – Java Assignment #4

Problem 1:
Write an application that prints a one-month calendar. The user specifies the number of days in
the month and the day of the week on which the months begins.
Days of the month  1 = Sun, 7 = Sat
1 2 3 4 5 6 7
S M T W Th F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Hint  use % operator -- you will need at least one loop and a coupe of if statements.

Problem 2:
Write an application that draws a checkerboard on the screen.
Hints: need nested for loops & int num = 30 prints a filled square
a checker board is 8 by 16 squares
outer loop counts(y) down the board
inner loop counts(x) crossed the board
(x + y) % 2 == even numbered squares

Problem 3:
Write a basic checkbook application. This application will keep track of one’s checkbook
balance. Use the following commands:
System.out.println("**** Checkbook balancing program ****\n");
System.out.println("Commands: 0=clear, 1=credit, 2=debit, ");
System.out.println("3=balance, 4=exit\n");

Here is my code from problem 1-3

```import java.util.Scanner;
public class AssignmentFourCalender {

public static void main(String[] args)
{
String[] array = new String[32];
for(int x = 1, y = array.length; x < y; x++)
{
array[x] = x+" ";
}
for(int x = 1, y = array.length; x < y; x++)
{
if(x % 8 == 0)
{
System.out.println();
}
System.out.print(array[x]);
}
System.out.println();
}
}```

How would I put S M T W Th F S on top of the calender.

```public class AssignmentFourCheckerboard{

public static void main(String[] args)
{

for(int row=0;row<8;row++){
for(int col=0;col<8;col++){

if ( (row % 2) == (col % 2) )
System.out.print("O");
else
System.out.print("X");

}
}
}
}```

There is a extra "O" at the bottom of the output. How do I get rad of the extra O.
Also how do I make the output look like:
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX

``` import java.util.Scanner;
public class AssignmentCheckBook {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Scanner keyboard = new Scanner(System.in);

int opinion = 0;
double clear = ' ';
double credit = ' ';
double debit = ' ';
double balance = ' ';

System.out.println("****Checkbook balancing prgram ****\n");
System.out.println("Commmands; 1=Credit, 2=debit, ");
System.out.println("3=Balance, 4=exit\n\n");
System.out.println("Input Commmands; 0=Clear, 6=Input Credit, 7=Input Debit, ");
System.out.println("8=Input Balance, 9=exit\n");
opinion = keyboard.nextInt();

switch (opinion) {
case 1:
System.out.println("You credit is " + credit);
break;
case 2:
System.out.println("You debit is " + debit);
break;
case 3:
System.out.println("You balance is " + balance);
break;
case 5:
credit = 0.0;
debit = 0.0;
balance = 0.0;
break;
case 6:
System.out.println("Enter your credit:");
credit = keyboard.nextDouble();
System.out.println("You credit is " + credit);
break;
case 7:
System.out.println("Enter your debit:");
debit = keyboard.nextDouble();
System.out.println("You debit is " + debit);
break;
case 8:
System.out.println("Enter your balance:");
balance = keyboard.nextDouble();
System.out.println("You balance is " + balance);
break;
case 9:
case 4:
System.out.println("Thank you and good-bye!");
System.exit(1);
break;
default:
System.out.println("Wrong input!");
break;  }
}
}```

How do I make the output go back to the interface after I enter a case number 1,2,ect.

Thank YOU!!! If you need me to explain it better just ask :)

2. ## Re: Can you someone help me with my homework for java... Please

How would I put S M T W Th F S on top of the calender.
Use a call to the println() method first thing.

how do I make the output look like:
Post the program's current output to compare against.

How do I make the output go back to the interface after
I assume you are talking about looping back in the code to where it prints out a message to the user.
Enclose the code in a loop like a while loop that takes the execution back to where the the program asks the questions. You will need a way for the user to tell the program that he is done and wants the program to exit.

3. ## The Following User Says Thank You to Norm For This Useful Post:

surfelijo (February 25th, 2013)

4. ## Re: Can you someone help me with my homework for java... Please

Originally Posted by Norm
Use a call to the println() method first thing.

Post the program's current output to compare against.

I assume you are talking about looping back in the code to where it prints out a message to the user.
Enclose the code in a loop like a while loop that takes the execution back to where the the program asks the questions. You will need a way for the user to tell the program that he is done and wants the program to exit.
```case 9:
case 4:
System.out.println("Thank you and good-bye!");
System.exit(1);
break;```
Does that tell the user how to exit??
How would i write this while loop that takes the user back to the question hahah sorry im new to java Thank You.

5. ## Re: Can you someone help me with my homework for java... Please

Yes, calling System.exit() will exit the program.
How would i write this while loop
See the tutorial:
The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

6. ## The Following User Says Thank You to Norm For This Useful Post:

surfelijo (February 25th, 2013)

7. ## Re: Can you someone help me with my homework for java... Please

Thank you sooooo much I fix it with you help.

I don't fully understand
Post the program's current output to compare against.
Can you help me

8. ## Re: Can you someone help me with my homework for java... Please

I don't fully understand
Post the program's current output
Execute the program, copy the program's output and paste it here on the forum so it can be compared against the desired output.

9. ## Re: Can you someone help me with my homework for java... Please

Originally Posted by Norm
Execute the program, copy the program's output and paste it here on the forum so it can be compared against the desired output.
output:
OXOXOXOXX
OXOXOXOOX
OXOXOXXOX
OXOXOOXOX
OXOXXOXOX
OXOOXOXOX
OXXOXOXOX
O

10. ## Re: Can you someone help me with my homework for java... Please

Can you also post the code that generates the output shown in post#7?

11. ## The Following User Says Thank You to Norm For This Useful Post:

surfelijo (February 25th, 2013)

12. ## Re: Can you someone help me with my homework for java... Please

```public class AssignmentFourCheckerboard {

public static void main(String[] args)
{

for(int row=0;row<8;row++){
for(int col=0;col<8;col++){

if ( (row % 8) == (col % 8) )
System.out.println(" ");
if ( (row % 2) == (col % 2) )
System.out.print("O");
else
System.out.print("X");

}
}
}
}```

Output:
OXOXOXOXX
OXOXOXOOX
OXOXOXXOX
OXOXOOXOX
OXOXXOXOX
OXOOXOXOX
OXXOXOXOX
O

13. ## Re: Can you someone help me with my homework for java... Please

Did the code in post#1 ever put two of the same letters next to each other?
The code in post#9 does.

What was wrong about the code in post#1? Can that be changed to get what you want?

14. ## Re: Can you someone help me with my homework for java... Please

I add this to Post#1 to make the output a square.
if ( (row % 8) == (col % 8) )
System.out.println(" ");

Post#1 output is: OXOXOXOXXOXOXOXOOXOXOXOXXOXOXOXOOXOXOXOXXOXOXOXOOX OXOXOXXOXOXOXO

Post#9 output:
OXOXOXOXX
OXOXOXOOX
OXOXOXXOX
OXOXOOXOX
OXOXXOXOX
OXOOXOXOX
OXXOXOXOX
O

Post#9 is my newest version of my code.

The output I want is
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX

15. ## Re: Can you someone help me with my homework for java... Please

If the output from the code in post#1 has all the characters in the correct order, then the only thing needed is to output a newline at the end of each row after printing the Xs and Os in the columns on that row.

16. ## Re: Can you someone help me with my homework for java... Please

how do i do that?

17. ## Re: Can you someone help me with my homework for java... Please

Add a call to System.out.println();
after all the characters are printed that go on one row.
Hint: the inner for loop that uses the col variable is what prints the contents of a row.

18. ## Re: Can you someone help me with my homework for java... Please

THANK YOU hahah your amazing Norm finished my homework thanks to you Your a great teacher.

19. ## Re: Can you someone help me with my homework for java... Please

Good luck on the next set of problems.