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 :)