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.
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.
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
I am new to Java and I am trying to use values that are set for cases in the switch operator.
The first menu ask for you to pick a product and each product has a price on it.
The second menu ask you to pick a state with each state having a decimal value on it.
The third is asking you to put the number of cases and each case is 12 items.
A key note to remember is that each part that a person is choosing is on a different instance!
Here is an example of what i am trying to do.
Menu 1: I picked case 1 that is Computer and it is worth 1000 Menu 2: I picked case 1 that is CT and it's tax is 7.5
Third choice: I picked case 1 and that has 12 items
I want the subtotal witch is: (1000 * 12)
Subtotal in this situation is: 120000
Next i need the total value which is based on what state they picked for the tax percent value picked from the state menu case: (12000 * 0.075 + 120000)
Total value is: 129000
I will post the code I have but based on the choices a person makes will determine the values and I need those values set in the cases to put in a math equation. The problem I am having is retrieving these numbers form the cases inside the menu options and they are on a different instance. So How can I do this in Java code?
Here is the code:
This is menu 1
Java Code:
import java.util.*; //scanners and more class menu{ public void display_menu() { System.out.println ("Please select your product"); //Gives user direction System.out.println ( "1)
There are few modules in our application whose performance degrade with time when 50-100 simultaneous users are working on them at a given instance.The memory allocations are taken care of to allow maximum data.My issue to where to start finding the root cause.
I am currenlty using JvisualVM for profiling and finding memory leaks..Do i need to Simualte 50-100 virtual users and start finding the memory leaks with JvisualVM or working with a single user would do ?
I have following Cipher Code and test for it. But I am getting following exception.
Java Code:
java.lang.IllegalStateException: Cipher not initialized at javax.crypto.Cipher.checkCipherState(Cipher.java:1672) at javax.crypto.Cipher.doFinal(Cipher.java:2079) at com.anjib.util.CipherUtil.encrypt(CipherUtil.java:67) at com.anjib.util.CipherTest.testEncryptDecrypt(CipherTest.java:23) mh_sh_highlight_all('java'); Java Code: public class CipherUtil { private static Logger log = Logger.getLogger(CipherUtil.class);
I'm trying to develop a system for test cases so that whenever a test case is added to a particular package it will automatically be included in testing without having to manually add that particular test case. What is the best way to achieve this? Should I use java reflection? I'm just getting started with Jenkins and trying to configure Selenium test cases.
Looking for some simple use cases for servlet filters other than tracking requests ? I was thinking of using a filter to filter out offensive language from entered text. Would that be a good use case ?
I'm a new Java user and I'm trying to code a simple login page. In first page (NewFile.jsp) users should enter their username and password and should click on "login", or click on "sign up".
1.) If user enters his username and password correctly, a login page (LoginPage.jsp) appears and says "welcome null" but it should show the name of that user instead of null.
2.) In that login page there is an edit button to edit profile information. When I clicked on it, every information is "null" and when I edit them and click on "Submit" button;
HTTP Status 404 - type Status report message description The requested resource () is not available. GlassFish Server Open Source Edition 3.1.2
that message appears.
3.) If I click on "Sign Up" button at the beginning, a registration jsp (SignUpPage.jsp) appears. After filling up text boxes and clicking on "Submit", same Status 404 screen appears.
I created a mysql database called "loginpage" using xampp. In that database there is a table called "users" and it has un, pass, name, surname, email and degree attributes.
Write a Java program ExtractNumber.java to read the data via the keyboard, character by character and print the first number (with or without a decimal point) contained in the input. For example, given the input data: Mary works for $43.75 per hour, the program should print 43.75 to the screen.
When i entered the sentence "The lady works for 8 hours at $10.00 per hour"
ERROR: My output was 810.00 instead of simply the first number 8
A GUI program that allows user to enter their name and the program will convert it in number using array.
For example if i input "EUNISE" the output should be 521149195
Because the letter equivalent of
a = 1 b = 2 c = 3 d = 4 e = 5 f = 6 g = 7 h = 8 i = 9 j = 10 k = 11 l = 12 m = 13 n= 14 o = 15 p = 16 q = 17 r= 18 s = 19 t = 20 u = 21 v = 22 w = 23 x = 24 y = 25 z = 26
import java.io.*; public class MagicSquare { public static void main(String[]args)throws IOException { BufferedReader in=new BufferedReader (new InputStreamReader(System.in)); System.out.print("Enter a Magic Number: "); int number=Integer.parseInt(in.readLine());
[Code] ....
//where should i enter a even number that will be outputted "invalid" //and it only should accept odd numbers
String temp = "hi this sf hello is new what is this"; String[] cmd = temp.split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
However, when i get the input from user , i didnt get the expected result:
Java Code:
System.out.println("Enter the input string to count the words: "); String[] cmd = new Scanner(System.in).next().trim().split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
What I am trying to do here is allow input to loop until 0 is entered for the product number. When 0 is entered, it should then dump the total for each individual product. I've tried it about a dozen different ways and have yet to be able to get the loop to function as intended. The way I have the code below, the loop will not function at all (where as before it looped, but never finished).
import java.util.Scanner; public class Sales { public static void main(String[] args) { double total1=0.0; double total2=0.0; double total3=0.0; double total4=0.0; double total5=0.0; int product;
Any better way to write a program that takes a user number input and the program determines whether or not the number is prime or not. It was suppose to be a number between 0 and 8,000,000.
import java.util.Scanner; public class prime1 { public static void main(String args [])
Write a program that detects Fibonacci numbers. Prompt the user to input a positive integer. Upon input, the program will determine if the number is either a Fibonacci number or not. If a Fibonacci number, then the order of the number in the sequence must be output. If not a Fibonacci number, then the Fibonacci numbers above and below it (including their order in the sequence) must be output. Once it finishes, the program will prompt the user for a new number. The program will exit if the user enters a string (such as “quit”) instead of an integer. Use the sample output file, fib-seq-det.txt, to view a sample session
This is my project, I wrote a programs that tells you if the input number is a fibonacci number or not. For some reason it only works for some Fibonacci numbers but not all of them.
import java.util.Scanner; public class While { public static void main(String[] args) { System.out.println("Welcome to the Fibonacci Sequence Detector "); Scanner in = new Scanner(System.in); System.out.print("Please input a number for analysis: "); int input = in.nextInt();
I'm having trouble with a program, reversing numbers. I got the program itself to work! However, I am having an issue with the output.
import java.util.Scanner; public class p1a { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n; int reverse = 0;
[Code] .....
If I were to input, say 2341, I would get this: The reverse of 0 is 1432
The 0 should have been 2341, or whatever I input. What am I doing wrong?
I tried to move line 21 : (System.out.println("The reverse of " +n+ " is "+reverse);
Above the while loop, but instead get:
The reverse of 2341 is 0
How can I get my input and my result together in the same line?
import java.util.*; public class SumOfAllEvens { public static void main (String[] args) { Scanner s = new Scanner (System.in); //for (int i=1; i<4; i++){ int usernumber;
[code]....
I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package firstgui; import javax.swing.*; import java.awt.event.*; public class TicTacToe {
[Code] ......
Program is 10x10 board, I need to check if the user's input is a duplicate of any number in that same column, but I can't figure it out. When I tried it, it always check the same box. For example, if I entered 4 in [1][1] (going by 10x10 grid), it automatically checks right after I entered that [1][1] is the same as my input and erases it. My professor wants me to check it with the "CheckWinner" method.
I tried the following when someone told me to pass the reference of the JButton being clicked to ignore it.
I need the user to be able to input a number, and for the program to assign this value to an 'int' variable. I know how to do this with a 'string' variable:
Java Code:
String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have? " +" (NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)"); mh_sh_highlight_all('java');
But I need to know how to do this with an 'int' variable.
I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?
import java.util.Scanner; public class Palindrome { public static void main(String[] args) { int number; int digit; int temp;