Design Pattern Selection

Mar 27, 2015

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

View Replies


ADVERTISEMENT

Head First Design Pattern

Jan 11, 2014

I was reading head first java and the author told to read head first design pattern next.

View Replies View Related

Too Many Number Of Cases Of Input - Design Pattern?

Apr 16, 2015

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?

View Replies View Related

Modify Internal Object Structure Using Any Design Pattern

Mar 31, 2014

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.

View Replies View Related

Swing/AWT/SWT :: Factory Design Pattern With Swing JDialog

Jul 26, 2014

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

View Replies View Related

How To Design Classes

Mar 29, 2014

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?

View Replies View Related

How To Add Spaces To A Pattern

Apr 21, 2015

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

View Replies View Related

Printing Pattern When Name Is Given

Mar 10, 2014

I want to know how to print this type of pattern when a name is given ???

Example:

name given TEJA

Capture.PNG

View Replies View Related

Java Design Patterns

May 9, 2015

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 Related

Front End Design In Java GUI

Jul 11, 2014

I am designing an application I want to know what are the best technology Like Java FX for front end design?

View Replies View Related

Java Loop Design

Jun 16, 2014

Basically 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]....

View Replies View Related

Handling MVC Design With DatabaseDAO

Mar 31, 2015

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?

View Replies View Related

How To Design - Interface Usage

Jul 17, 2014

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?

View Replies View Related

How To Apply Format Pattern

Jan 12, 2015

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());

View Replies View Related

String Pattern Match

Apr 24, 2015

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

View Replies View Related

Recursive Selection Sort

Oct 21, 2014

How would I modify this version of a selection sort into a recursive method?

public static void selectionSortRecursive(Comparable [] list, int n)
{
int min;
Comparable temp;

[code]....

View Replies View Related

Pattern Matches In Java

Jul 3, 2014

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

View Replies View Related

Using Multiple Selection Choices?

May 28, 2014

This program allows the user to select one of each different type of skateboard/accessories items. Then it allows the user to select as many misc items as he or she chooses. The program works fine for the single choices, but I cannot solve the latter part. I have a get method in the misc class that is trying to pull out any selection or selections that were made by the user, but it simply does nothing...

Here's my program, I have four panel classes for each skateboard type, and then I have one class that takes care of adding each panel to the content pane, and calculating the total cost of the item.

Decks Panel Class:

import java.awt.event.*;
import javax.swing.*;
// The DecksPanel class allows the user to selects a specific type of skateboard
public class DecksPanel extends JPanel

[Code]....

View Replies View Related

Selection Sort Method?

Mar 5, 2014

I'm trying to make a selection sort method that will sort a list of Strings alphabetically.

I have a test list of Strings like so:

Joe, Steve, Oscar, Drew, Evan, Brian, Ryan, Adam, Zachary, Jane, Doe, Susan, Fred, Billy-Bob, Cindy, Mildred, Joseph, Hammer, Hank, Dennis, Barbara

However, whenever I run the method, the element that should go last, Zachary, in this case, ends up getting moved to the front for some reason. I'm not sure why.

I tried changing what the first element was initialized to, to the variable i as that would logically work as well, but it ends up missing the first element in the list.

Java Code:

public static void selectionStringAscendingSort (String[] words){
int i, j, first;
String temp;
for ( i = 1; i < words.length; i++ ) {
first = 0; //initialize to subscript of first element
for(j = i; j < words.length; j ++){ //locate smallest element between positions 1 and i.
if( words[ j ].compareTo(words[ first ]) <0 )
first = j;
}
temp = words[ first ]; //swap smallest found with element in position i.
words[ first ] = words[ i ];
words[ i ] = temp;
System.out.println(Arrays.toString(words));
}
System.out.println(Arrays.toString(words));
} mh_sh_highlight_all('java');

View Replies View Related

Create A Pattern Of Stars

Jul 2, 2014

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

View Replies View Related

Inheritance For Word Pattern

Apr 24, 2014

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

View Replies View Related

Triangle Pattern (For Loop)

Feb 21, 2015

I'm trying to make a triangle which should look like this. But I cant seem o figure it out.

1
2 1
4 2 1
8 4 2 1
16 8 4 2 1
32 16 8 4 2 1
64 32 16 8 4 2 1
128 64 32 16 8 4 2 1

This is the code I have written so far.

public class TestProgram
{
public static void main(String[]args)
{
for (int columns=0; columns<=8; columns++)
{
for (int rows=columns; rows>=1; rows --)
{
System.out.print(rows+ " ");
}
System.out.println();
}
}
}

View Replies View Related

Selection Does Not Contain A Main Type

Mar 23, 2014

I'm trying to run a simple code which is to just print out "Hello World", but whenever I run it, a message appears that reads: "Select a way to run Project_1(Which is the Java Project)"

The selections for it are: Java Applet and Java Application.Whenever I click Java Applet it reads: Selection does not contain an applet.When I click Java Application: Selection does not contain a main type.Here is the code which I believe is correct:

package packag_1;
public class Num_1 {
public static void main(String args){
System.out.println("Hello World");
}
}

View Replies View Related

Composition Pattern In Java

Jun 27, 2014

I'm having a hard time implementing a simple composition example in Java:

Java Code:

public class CompositionPattern {
public static void main(String[] args) {
Udp udp = new Udp();
Imap imap = new Imap();
udp.startService();
imap.startService();

[Code] ....

The above won't compile. It says "The method supportsMe() is undefined for the type Object". I understand that I stored parent as an Object. But in reality it is not simply Object, but a Udp object or Imap object. The point is to make Responder generic. I don't want to have to cast the Object to Udp or Imap. Any solutions so I can keep this generic?

View Replies View Related

Singleton Pattern In Java

Apr 21, 2003

I have heard about using patterns in core java.Is it possible?If yes, how?

View Replies View Related

Observer Controller Pattern (MVC)

Dec 10, 2014

Model View Controller design pattern I completely understand then I was told about the observer controller pattern. After reading and reading I and watching video clips on youtube explaining it I have a question:

Isn't the actionListener the observer so to speak. It is firing whatever action it is told to do and dynamically updates the program to.

Example, I have a JButtons and a JTextArea. I press the button and it gives the current stock price of some stock, I press it again it refreshes. Sounds like an observer to me... Am i on the right track here?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved