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.

Results 1 to 16 of 16

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

  1. #1
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    surfelijo (February 25th, 2013)

  4. #3
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by Norm View Post
    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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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)
    If you don't understand my answer, don't ignore it, ask a question.

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

    surfelijo (February 25th, 2013)

  7. #5
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #7
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by Norm View Post
    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. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

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

    surfelijo (February 25th, 2013)

  12. #9
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #11
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #13
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

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

    how do i do that?

  17. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #15
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Good luck on the next set of problems.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Homework Help
    By JustDelta767 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 6th, 2012, 08:22 AM
  2. JAVA HOMEWORK HELP!
    By javafirsttime in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 14th, 2011, 07:00 PM
  3. New to Java Need help with Homework
    By cjg2283 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 20th, 2011, 09:47 PM
  4. Help for java homework
    By Dark_Shadow in forum Object Oriented Programming
    Replies: 6
    Last Post: December 7th, 2009, 04:08 AM
  5. MORE java homework help.
    By TommyFiz in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: October 13th, 2009, 07:15 PM

Tags for this Thread