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

• February 25th, 2013, 12:39 PM
surfelijo
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

Code :

```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.

Code :

```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

Code :

``` 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 :)
• February 25th, 2013, 12:48 PM
Norm
Re: Can you someone help me with my homework for java... Please
Quote:

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.

Quote:

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

Quote:

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.
• February 25th, 2013, 01:01 PM
surfelijo
Re: Can you someone help me with my homework for java... Please
Quote:

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.

Code :

```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.
• February 25th, 2013, 01:10 PM
Norm
Re: Can you someone help me with my homework for java... Please
Yes, calling System.exit() will exit the program.
Quote:

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)
• February 25th, 2013, 05:00 PM
surfelijo
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
Quote:

Post the program's current output to compare against.
Can you help me :)
• February 25th, 2013, 05:47 PM
Norm
Re: Can you someone help me with my homework for java... Please
Quote:

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.
• February 25th, 2013, 07:08 PM
surfelijo
Re: Can you someone help me with my homework for java... Please
Quote:

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
• February 25th, 2013, 07:12 PM
Norm
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?
• February 25th, 2013, 08:12 PM
surfelijo
Re: Can you someone help me with my homework for java... Please
Code :

```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
• February 25th, 2013, 08:18 PM
Norm
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?
• February 25th, 2013, 08:31 PM
surfelijo
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
• February 25th, 2013, 08:34 PM
Norm
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.
• February 25th, 2013, 08:40 PM
surfelijo
Re: Can you someone help me with my homework for java... Please
how do i do that?
• February 25th, 2013, 08:49 PM
Norm
Re: Can you someone help me with my homework for java... Please