Lost with how to start

Reply

Join Date: Nov 2008
Posts: 4
Reputation: littlebean21289 is an unknown quantity at this point 
Solved Threads: 0
littlebean21289 littlebean21289 is offline Offline
Newbie Poster

Lost with how to start

 
0
  #1
Dec 2nd, 2008
I have had to miss my last classes due to having to go to my doctor in order to prep me for surgery. My professor has placed the final assignment online and i have no where to begin. I'll take any help and would like to add that while i can understand programs when reading them, I am a complete lost when asked to write them. Heres the program:Implement a class named Date that
Has three instance variables (month & day & year) of type int
Has a constructor that accepts three input parametes
Has a boolean method called isBirthday
Has a method called getZodiacSign that returns the appropriate icon
Use the DateApplication class (given) as the main program

This is the code i have been given and also pictures for the zodiac symbols
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.*;
  5.  
  6. public class DateApplication extends JFrame
  7. {
  8.  
  9. private JButton birthdayButton,zodiacButton,chineseButton;
  10. private JTextField monthField, dayField, yearField;
  11. private JLabel inputPrompt;
  12. private JPanel panel;
  13.  
  14. public static void main()
  15. {
  16. DateApplication frame = new DateApplication();
  17. frame.setSize(350,300);
  18. frame.createGUI();
  19. frame.setTitle("Fun with Dates");
  20. frame.setVisible(true);
  21. }
  22.  
  23. private void createGUI()
  24. {
  25. setDefaultCloseOperation(EXIT_ON_CLOSE);
  26. Container window = getContentPane();
  27. window.setLayout(new FlowLayout());
  28.  
  29. panel = new JPanel();
  30. panel.setPreferredSize(new Dimension(300,200));
  31. panel.setBackground(Color.white);
  32.  
  33. birthdayButton = new JButton("Check Birthday");
  34. birthdayButton.addActionListener(new BirthdayDrawAction());
  35. zodiacButton = new JButton("Zodiac");
  36. zodiacButton.addActionListener(new ZodiacDrawAction());
  37. chineseButton = new JButton("Chinese Year");
  38. chineseButton.addActionListener(new ChineseDrawAction());
  39.  
  40. inputPrompt = new JLabel("Enter your bithday mm-dd-yyyy: ");
  41. monthField = new JTextField(2);
  42. dayField = new JTextField(2);
  43. yearField = new JTextField(4);
  44.  
  45. window.add(inputPrompt);
  46. window.add(monthField);
  47. window.add(dayField);
  48. window.add(yearField);
  49. window.add(birthdayButton);
  50. window.add(zodiacButton);
  51. window.add(chineseButton);
  52. window.add(panel);
  53. }
  54.  
  55. private class BirthdayDrawAction implements ActionListener {
  56. public void actionPerformed(ActionEvent event)
  57. {
  58. int month, day, year;
  59. String inputMonth = monthField.getText();
  60. month = Integer.parseInt(inputMonth);
  61. String inputDay = dayField.getText();
  62. day = Integer.parseInt(inputDay);
  63. String inputYear = yearField.getText();
  64. year = Integer.parseInt(inputYear);
  65.  
  66. Date theDate = new Date(month,day,year);
  67.  
  68. Graphics g = panel.getGraphics();
  69. g.setColor(Color.white);
  70. g.fillRect(0,0,300,200);
  71. g.setColor(Color.red);
  72. Font myFont = new Font("SansSerif", Font.BOLD, 24);
  73. g.setFont(myFont);
  74. if (theDate.isBirthday()) {
  75. g.drawString("Happy Birthday",20,100);
  76. }
  77. else {
  78. g.drawString("It's not your Birthday",20,100);
  79. }
  80. }
  81. }
  82.  
  83. private class ZodiacDrawAction implements ActionListener {
  84. public void actionPerformed(ActionEvent event)
  85. {
  86. int month, day, year;
  87. String inputMonth = monthField.getText();
  88. month = Integer.parseInt(inputMonth);
  89. String inputDay = dayField.getText();
  90. day = Integer.parseInt(inputDay);
  91. String inputYear = yearField.getText();
  92. year = Integer.parseInt(inputYear);
  93.  
  94. Graphics g = panel.getGraphics();
  95. panel.removeAll();
  96.  
  97. Date theDate = new Date(month,day,year);
  98.  
  99. Icon zodiacIcon = null;
  100. // zodiacIcon = theDate.getZodiacSign();
  101.  
  102. JLabel label = new JLabel(zodiacIcon);
  103. panel.add(label);
  104. panel.revalidate();
  105. panel.repaint();
  106. }
  107. }
  108.  
  109. private class ChineseDrawAction implements ActionListener {
  110. public void actionPerformed(ActionEvent event)
  111. {
  112. int month, day, year;
  113. String inputMonth = monthField.getText();
  114. month = Integer.parseInt(inputMonth);
  115. String inputDay = dayField.getText();
  116. day = Integer.parseInt(inputDay);
  117. String inputYear = yearField.getText();
  118. year = Integer.parseInt(inputYear);
  119.  
  120. Icon ChineseIcon = null;
  121. Graphics g = panel.getGraphics();
  122. panel.removeAll();
  123.  
  124. Date theDate = new Date(month,day,year);
  125.  
  126. Icon chineseIcon = null;
  127. // chineseIcon = theDate.getChineseYear();
  128.  
  129. JLabel label = new JLabel(chineseIcon);
  130. panel.add(label);
  131. panel.revalidate();
  132. panel.repaint();
  133. }
  134. }
  135. }
there is an extra credit assignment for including the chinesenewyear but im not concerned with that.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,532
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 191
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Lost with how to start

 
0
  #2
Dec 3rd, 2008
Your professor already gave you basic steps on how to begin. Try those and when you get stuck, tell us what you don't understand. We won't do your assignment for you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC