Head First Design Pattern
Jan 11, 2014I was reading head first java and the author told to read head first design pattern next.
View RepliesI was reading head first java and the author told to read head first design pattern next.
View RepliesI need selecting which design pattern to use in my case.
I am creating a list of objects "items" to be presented in a list for the user to choose from, all objects have a title and a check box. Some objects have additional textbox for user input, some objects have additional image for illustration, and some objects have additional textbox and image as well.
I read and saw online videos but not sure if my selection "Factory Design Pattern" is the best match.
For example
Select food;
1. hamburger 2. pizza 3.chicken 4.sandwich .. etc
if I choose hamburger there are choices again
1. big mac 2.Quarter Pounder with Cheese 3.Double Cheeseburger ...etc
If I choose big mac there are choices again!!.
choose the drink you want
1.coke 2.orange juice ..etc
situations like this, what design pattern should I use?
I have a design scenario here which is quite interesting and complex. I have a Java class structure as follows,
class A
{
class B;
innerClass B
{
List<class C> listofC;
innerClass C
{
String attribute1;
String attribute2; // Their getter setters
}
}
}
So I have this as an API. Now my challenge is that I need to add one more property to inner class C. i.e attribute3 in innerClass C. I need to do this without disturbing the code in class A by extending these classes or writing a new wrapper, so I can use class C with new properties .
I hope this should be achievable through any design pattern either at runtime or design time.
Is it a good idea to use the factory design pattern for say if I needed to create four different JDialogs for the same parent frame?
factory design interface
package client;
public interface Dialog {
void getInstanceOf ();
void initComponents ();
}
One of the four JDialog class would look something like this without the comments.
package client;
import javax.swing.JDialog;
@SuppressWarnings("serial")
public class AddCustomerDialog extends JDialog implements Dialog{
public AddCustomerDialog () {
//Some stuff goes here to set the settings for JDialog instance
[code]....
Of course you would have your factory class
I am totally new to programming in every way, shape or form, and I'm working my way through the Head First Java book (2nd ed). I have just finished copying the code for the initial BeatBox app, the one starting on page 420. When I try to compile it, I get these errors:
BeatBox.java:36: cannot find symbol
symbol : constructor Box(int)
location: class Box
Box buttonBox = new Box(BoxLayout.Y_AXIS);
^
BeatBox.java:40: cannot find symbol
symbol : method add(javax.swing.JButton)
location: class Box
buttonBox.add(start);
[code]....
I doubt that this is relevant, but I'm running Mac OS X, coding in TextWrangler and compiling with Terminal. Java version is 1.6.0_24.
I want to call the HEAD method on a servlet.If in my HTML code, I specify -
<form name="testHead" action="/servlet/servletName" method="HEAD">
And the servlet handles the HEAD method in the sense that the doGet() method returns if the method type is HEAD.When I run it, the servlet returns the code returned by the entire doGet() method. This shows that the doGet() method does not realize that it is a HEAD method and it should return back without processing further.The application server is Tomcat 4.0.
I'm currently reading Head First Java and want to use the topics shown in the book while I read it to master them. What are some good projects that can be used to practice all the skills taught in the Head First Java book while I read it?
View Replies View Relatedam trying to Develop a download manager that will improve the downloading process, by splitting big files into different parts, and download each part of the file parallel and then combine them properly Just like JDownloader not really too complex like it though but more like it especially the split download part of it. I was able to get a script from some eBook but that doesn't really solve my problem as it only downloads pause and resumes which is not really what am looking for.
View Replies View RelatedI am creating a chained hash table that uses my own LinkedListclass to handle collisons. Here is where my issue is occuring: I start with an array of LinkedLists, my "hash table", intially set to null. When i wish to add a word, if the desired location is null, I create a new LinkedList, place it in that array index. I then create a new LinkedListNode and set the head of the new LinkedList to the new node.
My issue is occuring here: Whenever I set the head of my new LinkedList to my new LinkedListNode all of my previously created linkedlists also have their head changed to the new node.
My debugger shows that I am truly creating new linkedlists every time. I was afraid each array index was just pointing to a single array, but that is evidently not the issue. Below is all the relevant code
public class SetOfStrings {
private int arraySize;
private LinkedList[] mainArray;
private int totalCount;
//other methods here
public boolean add(String toAdd) {
int hashToAdd = hash(toAdd);
[code]....
SUMMARY: Whenever I set the head of a Linked List to a new node, it changes the head of all my linked lists to point to the same new node
I downloaded this code from Head First Java. But when I tried running it on Eclipse, it gives this error message.
import javax.sound.midi.*;
public class MiniMiniMusicApp { // this is the first one
public static void main(String[] args) {
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();
[code]....
and this was the error message: Jan 02, 2015 8:10:36 PM java.util.prefs.WindowsPreferences <init>Could not open/create prefs root node Software Java SoftPrefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
I am trying to flip a coin 1000 times and make the driver class count the number of times a head and tails appear. However, I am having some trouble trying to figure out the error:
package Week5;
import java.util.Random;
public class Coin {
private int heads;
private int tails;
private int face;
[Code] ....
I was able to print out the generated numbers, but java will print either heads or tails a thousand times and count that as 1000 and nil for the other probability...
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*;
public class FileDisplay
{
private String filename;
public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead()
{FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
design a class to conduct a survey of three hospitals. you want to know how many sectors (eg operation, children, gastronomic) each hospitals have, and how many doctors there are in each sector.
what is the process of class design?
I have created this program that outputs
1
12
123
1234
12345
123456
I tried looking up some ways to create spaces in between each number, but I failed miserably. Here is what I have right now.
public class Iterations {
public static void main(String[] args){
for(int i=1;i<=6;i++)
{
for(int j=1;j<=i;j++)
System.out.print(j);
[Code] ....
I want to know how to print this type of pattern when a name is given ???
Example:
name given TEJA
Capture.PNG
we have been given a scenario to design a system in which we have to make the class diasgrams. however we have to use appropriate patterns that match the scenario.
View Replies View RelatedI am designing an application I want to know what are the best technology Like Java FX for front end design?
View Replies View RelatedBasically I have to enter 5 numbers that I put through a loop and they print the star * depending on the number.An example would be this 5:*****. However, my codes prints out 5:*; 5 times. How to correct my code
Java Code:
import java.util.Scanner;
public class IntegerOutput
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int num1;
int num2;
int num3;
int num4;
int num5;
[code]....
I have done this a few times but I want to make sure I am doing it correctly. In other words creating a clean understandable program. Instead of posting code I will just talk about this is my plan:
Create a model (getter and setters)
Create a view (via swing)
Create a controller (pass the model and view in the parameter)
Database DatabaseConnection:
Use the singleton pattern
Database:
Create an interface called Database with all the queries I will need (insert, delete etc)
Create a class called DataBaseDAO and implement the interface database and get an instance of the DatabaseConnection.
Tying it all together:
In the controller should I use the "new" operator and create a new database class or extend the database class? I am thinking I should not do it in the controllers constructor but make a field if I use the "new" operator like:
private Database db = new Database();
Create a class called App
Create a new Model
Create a new View
Pass the view and model into the controllers parameter.
Am I on the right track? Is this messy? Is there a better way of doing it?
I have a class as shown below. This class has a method addFilter with 2 parameters (type String and type Command1 )
public class Command1 {
public StringBuffer addFilter(String query, Command1 dataBase) {
//concrete implementation
return query;
}
}
I have another class Command2. Here I need a similar method. The only difference is in the type of parameters passed. (type String and type Command).
public class Command2 {
//TO DO:
public StringBuffer addFilter(String query, Command2 cmd) {
//concrete implementation
return query;
}
}
I have started by using Interface
public interface Helper {
public StringBuffer addFilter(String query, XXXXX parameter2);
}
I would like the classes Command1 and Command2 to implement the interface Helper and override it these two public classes.
However my problem is in dealing with the 2nd parameter. Am I right in my approach? How do I handle this issue?
I am able to get Cpu speed using my GetProcessorSpeed method and It returns this output 1796. How can apply this pattern "#.##". I am trying something like this.
Format formatter=new DecimalFormat("#.##");
formatter.format(MainClass.GetProcessorSpeed());
label2.setText(formatter.toString());
Why the following string fails the test below:
@Pattern(regexp = "^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*.(([0-9]{1,3})|" +
"([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$", message = "Not a well-formed email address")
I have code which validate code enter by user
the requirement say the maxlength=2 and minlength=1 and is a string
the user can enter code as follows
00
A1
HH
12
10
09
I have this Java Code:
public boolean isValidPattern(String s_value, String s_pattern) {
boolean flag = false;
if (Pattern.matches(s_pattern, s_value)) {
flag = true;
}
return flag;
[Code] ....
My problem is when user put
A1 AM geting error
So I'm studying for a test i have coming up on recursion so i was playing around with it. I ended up making a pattern of stars that look that such :
*
**
***
The code i had for that was
public void makePattern(int size){
if(size == 0){
System.out.println();
}
else if(size > 0){
System.out.print("*");
makePattern(size - 1);
}
}
I was wondering if i wanted to expand on this and make it do something like
*
**
***
**
*
What condition would i have to add i was struggling trying to figure it out...
I am in an intro programming class and we got assigned a problem for creating a super class with about a dozen sub classes for generating a random word(via WordGetter class) and then comparing that word to a variety of different patterns(like: does the word contain "re"). We were given the super class which looks like this...
public class Pattern {
public boolean matches(String text) {
return true;
}
public String toString() {
return "(TRUE)";
[code]...
and from this class, we have to write subclasses that override those three methods. I am struggling to understand inheritance and I am not really sure where to even start. Here is the instructions for the first sub class we need to write...
"CONTAINS" SUBCLASS
Constructor: The constructor accepts a String named ‘letters’.
Matches: This pattern matches any text that contains at least one occurrence of each ‘letter’.
toString: produces the text “(CONTAINS <LETTERS>)” where <LETTERS> is the ‘letters’ string.
getLetters(): this method must return letters.
equals(Object): careful on this one. Two Contains are equal if they have the same letters (order is not relevant).
(Example):
Pattern p = new Contains(“re”);
boolean f1 = p.matches(“renew”); // f1 is true
boolean f2 = p.matches(“zoo”); // f2 is false
String s = p.toString(); // s is “(CONTAINS re)”
boolean f3 = p.equals(new Contains(“er”)); // f3 is true.. really..