Java Application That Displays Composite Numbers?

Dec 31, 2014

I am trying to write a java application that displays composite numbers between 1 and 100. Here is the format of my code:

//a java application that prints out composite numbers that range from 1 to 100 
public class printcomposites{ 
public static void main(String[] args){ 
int num=0;
 int i=0;
 String printcomposites=""; 
for(i=1; i<100; i++)

[code]...

My code compiles with no errors, but my code generates every integer between 1 and 100 instead of integers that are composite:

Composite numbers from 1 to 100 are:

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 5
7 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

What am I doing incorrectly?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Application That Displays A Frame Containing Two Panels

May 9, 2014

I'm having trouble with this program. In my textbook it says "Write an application that displays a frame containing two panels. Each panel should contain two images (use four unique images - your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does". I successfully imported the images, but I can't find out anywhere how to allow the second panel to change size with the window.

import java.awt.*;
import javax.swing.*;
public class TwoPanels
{
public static void main(String[] args)
{
JFrame frame = new JFrame ("Embedded Images");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon iconOne = new ImageIcon ("glove.jpg");
ImageIcon iconTwo = new ImageIcon ("cleats.jpg");
ImageIcon iconThr = new ImageIcon ("bat.jpg");
ImageIcon iconFou = new ImageIcon ("baseball.jpg");

[code]...

View Replies View Related

Program That Displays First 100 Pentagonal Numbers Using Different Methods

Feb 28, 2015

I have to write a program that displays the first 100 pentagonal numbers using different methods. This is what I have so far:

Java Code:

public class FivePointOne{
public static void main(String[]args){
System.out.println("The the pentagonal numbers are: ");
}
//this method will find the penagonal numbers
public static int getPentagonalNumber(int n){

[Code] ....

But when I compile it to test it out I receive the error message "Illegal start of expression," ';' expected, and "reach end of file while parsing".

View Replies View Related

JSF :: Composite Component In Dependency

Jul 29, 2014

In a java application project called mycomposites, i created xhtml with a composite component interface and implementation in mycomposites/ src/ main/resources/testcomponents/myComponent.xhtml...Then I created a new project testmycomposites added mycomposites as dependency. Here is the source of an xhtml that should use myComponent:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"

[code]...

However running project, I get error:<tp:myComponent> Tag Library supports namespace: http://java.sun.com/jsf/composite/testcomponents, but no tag was defined for name: myComponent

If i put the same custom component in resources/testcomponents folder of the same project everything works fine.I can't find any example in wich custom composite components are located in a dependency.

View Replies View Related

Write Application That Display Numbers 1 To 4 On Same Line

Jul 22, 2007

I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit. The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the program using the following techniques:Use one system.out.printLn statement.Use four system.out.print statement.Use one system.out.printf statement.

This is what i have so far .

Java Code: public class Display
{
public static void main(String [] args) {
System.out.print("1 ");
System.out.print("2 ");
System.out.print("3 ");
System.out.print("4 ");
System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
System.out.printf(" %s %s %s %s ");????
}
} mh_sh_highlight_all('java');

i cant test this my console isn't working right, and i haven't finished my compiler install.

View Replies View Related

EJB / EE :: Convert Standalone Java Thread Application Into Web Application In Tomcat

Nov 17, 2014

convert or move standalone java thread application into Tomcat server container for accessing its JNDI services? Also is it possible to schedule this thread application in Tomcat server? is it possible to keep this app in tomcat as web application and schedule in window's scheduler.

View Replies View Related

JSF :: Load Images From CSS On Composite Component?

May 9, 2014

I have an issue about loading images from css using a composite component. The folder structure is:

resources
resources -> css -> componentname
resources -> images - > componentname
resources -> WEB-INF

If i write in the css something like

border-image: url(resources/images/componentname/image.png) !important;
or
border-image: url(images/componentname/image.png) !important;

i have a 404 error and i can't see the image.

I able to load the image only if i write path with context-root:

border-image: url(/<CONTEXTROOT>/resources/images/componentname/image.png) !important;

but i can't write explicit context root in css files!!

So, i tried to use resource EL variable:

border-image: url(#{resource[image/componentname/image.png]}) !important;

but this last way render

border-image: url("/<CONTEXTROOT>/javax.faces.resource/images/componentname/image.png.faces.faces") !important;

and i not able to replicate the right way written above.

The project is developed with RSA9 and WebSphere Portal 8, but if i try to execute it in NetBeans (no portal) it run correctly!

View Replies View Related

JSF :: Composite Component With Inherited Attributes

Apr 16, 2014

I have to create a new custom tag "imageLabeable" as a div contains a GraphicImage and an OutputLabel (primefaces).

Since I want to make it reusable as much as possible, I tried to write, in cc:interface section, all GraphicImage attributes (id, value, binding etc) and some new (GraphicImage is the main component among the two). But after that I have must associate GraphicImage attributes with the attributes created in cc:interface:

<cc:interface componentType="imageLabeable">
<cc:attribute name="value" />
<cc:attribute name="alt" />
<cc:attribute name="width" />
<cc:attribute name="height" />

[Code] .....

As you can see, if I have a lot of attributes I have to write a lot of association. Furthermore, if I see html rendered code with Firebug or similar, I see all of these associations.

Can I inherit these attributes automatically? Or associate it in easier way?

View Replies View Related

PhoneBook Application - Allow User To Enter Names / Numbers Of Up To 20 Friends

Apr 13, 2014

This application is supposed to allow a user to enter the names an phone numbers of up to 20 friends, until the user enters "zzz" or 20 names. Then the console is supposed to display the names and have the user enter a name to get the phone number. Here's my code:

import java.util.Scanner;
public class PhoneBook{
public static void main(String[] args){
String name;
int phoneNumber;
final int nameAmount=20;

[Code] ....

I can't seem to get it correct, every time I correct a compiler error, another set of them appear.

View Replies View Related

Swing/AWT/SWT :: Scrolled Composite Doesn't Scroll By Mouse Wheel

Sep 7, 2014

Mouse wheel is working properly on macosx but not working on windows.

Here is my layout structure, i implemented mousewheel listener but its not triggering tho.

And my scrolledcomposite declaration:

final ScrolledComposite scrolledComposite = new ScrolledComposite(mainComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_MAGENTA));

final Composite listComposite = new Composite(scrolledComposite, SWT.NONE);
GridLayout layout = new GridLayout();

[Code] ...

View Replies View Related

JavaFX 2.0 :: Synchronize Model Representing Complex UI Composite With FlowPane Backing List

Aug 26, 2014

What is the best way to synchronize a Model representing a complex UI composite w/ a FlowPane's backing list?
 
Currently I have a change listener on the Model.  Upon an add I create a new UI composite and manually add it to the FlowPane's backing list via flowPane.getChildren().add().  Similarly if there is a remove, I iterate over the FlowPane's children, grab the right Node, and remove it.  Similarly, if there is a modification detected, I iterate over the FlowPane's children, grab the right Node, remove it, recreate the UI composite, and re-add it to the list.  I also need the list to be sorted, so I implemented a UIComposite comparator and call FXCollections.sort() on the FlowPane's backing list.  I feel like that is hacky, but it works.  It would be cool if I could maintain sort order in my model somehow and have that automatically propogated to the FlowPane's list.
 
I am correct in assuming that there is no way to have a complex binding in between an ObservableList<CompositeViewModel> and the FlowPane's backing list (ObservableList<T>)? 

Some kind of translator that could create a new UIComposite whenever there is a new CompositeViewModel added to the Model list.

View Replies View Related

Code Only Displays Four Zeros

Jun 20, 2014

why this code only displays four zeros ?????

public class VargjetUshtrimi2 {
public static void main (String a []) {
int r[] = new int[11];
for (int i = 1 ;i < 10; i++)
{System.out.println( r[i] );}
}

View Replies View Related

Swing/AWT/SWT :: Need To Draw JButton Such That It Displays On Top Of Two Different Panels

Mar 3, 2015

one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.

View Replies View Related

Creating A Clock That Displays Different TIME In Different Capitals

Oct 16, 2014

As much as a clock and a calender have to do with date and time, a question arose.

I am creating a clock that displays different TIME in different captials.

Date timestamp = new Date();
timestamp.setTime(timestamp.getTime());
DateFormat time = new SimpleDateFormat("HH:mm:ss");
time.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(time.format(timestamp));

This code, returns the current time in UTC 00:00, the center of the time measuring system. And my program either ADDS an hour to the timestamp or deletes an hour, to make it earlier. My question is: Does Java account for Daylight Savings Time?

On that day, hours shift, and does java shift with them? Is there a changed need to make my code in order to not get the wrong results after the daylight savings time has hit?

View Replies View Related

Applets :: Accessing Java Application Without Adding Site To Java Security

Sep 12, 2014

I have tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.

View Replies View Related

Prompt User To Enter Integer From 1 To 15 And Displays A Pyramid

Jun 1, 2014

The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):

1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7

The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.

import java.util.*;
public class C5_17 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of lines: ");

[Code] ....

View Replies View Related

App That Calculates And Displays Total Basic Pay Week - Overtime Pay

Oct 16, 2014

Having just started college, Bob has been busy looking for a part-time job to fund his new college social life and after only two weeks of looking he has managed to get two job offers! Each job comes with different hours, basic rates of pay and over-time rates so he needs to work out which would get him the most money.

Develop an application that would allow Bob to enter his basic pay rate, his number of regular hours work per week and his number of overtime hours per week. The application should then calculate and display Bobs total basic pay for the week, his overtime pay for the week and his total pay including overtime.

Your application should use instantiable classes to separate the calculations from the user input and output.

Save the instantiable class as Pay.java

Note: The overtime rate is 1.5 times the basic rate of pay

This is my instantiable class code which compiles correctly

public class Pay{
//Declare Data members/Variables
private double pay;
private double hours;
private double overtime;
private double totalBasicPay;

[Code] .....

My errors in the second bit of code that i have never seen before

"C:UsersAndreDownloadsPayApp.java:25: error: no suitable method found for println(<null>,String)
System.out.println(null,"Please enter Basic Pay");
^
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)

[Code] .....

View Replies View Related

Program That Displays A Smiley Face Bouncing Around The Screen

May 30, 2014

I am writing a program that displays a smiley face bouncing around the screen. When I load the program it just shows a blank black JFrame. Here is the panel JPanel

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ReboundPanel extends JPanel {
private final int WIDTH = 300, HEIGHT = 100;
private final int DELAY = 20, IMAGE_SIZE= 35;
private ImageIcon image;

[Code]...

I have a suspicion that it might have to do with image = new ImageIcon("happyFace.gif");

I have tried other programs using .gif and they haven't worked on my computer and I haven't been able to figure out why.

View Replies View Related

Program That Displays Information For Employee Objects Of Different Types

Apr 29, 2014

I'm making a program that displays information for "employee" objects of different types. This works with a hierarchy that goes Person→ Employee→ Fulltime/Adjunct, and a driver that tests the inheritance. The Person class is given and only supplies the name, the employee class manages the year hired and the ID, and the types of employee classes manage the salaries.

One object (called staff[2]) is supposed to first be printed with default information and then later updated via set methods. I figured out how to update the name, but I don't know how to update the rest of the information because the employee's name is managed in the Person class and the reset of the information is managed in the less-general classes, and the objects are all in an array of Person.

How do I call the set methods necessary to update more of staff[2]?Output (scroll to see the updating section)

The current year is 2012

Name: Flintstone, Fred
ID Num: BR-1
Year Hired: 2005
Years Of Service: 7
Salary: 65000.12
Fulltime Type Employee

[code]....

View Replies View Related

JSF :: Dialog Inside Datatable With Button Displays Wrong Variable Value

Nov 27, 2014

I have a bookings table where customers can view their bookings and in the table there is a button with a command button that onclick goes to the dialogue to display the variable petUpdate value but if you have 2 bookings then all the update buttons display the value of the last petUpdate in the arrayList.

DataTable with the button

<p:dataTable
id="bookingTable"
var="customerBooking"
value="#{booking.sessionBookingList}"
editable="true"
style="margin:0px 0px 20px 100px;font-size:15px;width:600px;"
>

Code in the above datatable.......The commented out output label displays the correct value for each but when the button is clicked the dialog only displays the last ones value

<p:column headerText="Check Updates" style ="width:50px;">
<!-- <h:outputLabel value="#{customerBooking.petUpdate}"></h:outputLabel> -->
<p:dialog header="#{customerBooking.petName}'s Status" widgetVar="dlg1" minHeight="60" minWidth="60" maxWidth="60">
<h:outputText value="#{customerBooking.getPetUpdate()}" />
</p:dialog>
<p:commandButton value="?" onclick="PF('dlg1').show();" style ="width:40px;">
</p:commandButton>
</p:column>

View Replies View Related

Use FileInputStream To Open A File That Contains Name Of User Favorite Book And Then Displays It

Aug 9, 2014

I'm working on a problem where I have to use the FileInputStream to opens a file that contains the name of a user's favorite book and then displays it.

If the file doesn't exist, then I prompt for the book title and write it to the file using FileOutputStream. This is what I have so far but I'm lost because if I put a file that exists in line 8 then it closes, but if I don't and the user puts their favorite book nothing happens. Or, as far as I can tell nothing does.

import java.io.*;
class DisplayBook {
public static void main(String[] args)

[code]....

View Replies View Related

Test Program That Prompt User To Enter N And Displays N-by-b Matrix

Nov 25, 2014

I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".

So if a user would enter 3, and output could be 0 1 1
0 1 0
1 0 1

So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...

I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.

import java.util.Scanner;
public class MatrixTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an int");
int number = input.nextInt();
MatrixClass mc = new MatrixClass(number);

[Code] .....

View Replies View Related

PPS Number Generation - Netbeans Displays (Cannot Find Symbol) And Program Fails To Run

Jan 22, 2015

I am writing a payroll program .The program generates random PPS numbers and then takes in users information and calculates the salary accordingly. I am using netbeans and my code is showing errors on line 18 and 42 ("cannot find symbol")on the code for grossPay(). The program seems to crash after a new PPS number is generated and will not run.

package sd_assg_2;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JOptionPane;
public class SD_ASSG_2 {
  public static void main(String[] args) {
String[] newPPs = getPPSno();

[Code] ....

View Replies View Related

Java Application With Several Classes All In Same Java File

Apr 9, 2015

I've written a java application with several classes all in the same .java file. It works just fine. Now, I've broken it up so that each class has its own .java file. Still works fine. My next step is to put those classes into a package, but I'm not about to get the program to run.The .java source files are all in /home/user/src

I've set the CLASSPATH to /home/user/src..All of the source files have "package com.myfirm.program" on the first line.I compiled the application with:

javac -d . File1.java File2.java File3.java (etc...)

the compiler created the directory: /home/user/src/com/myfirm/program and put all of the .class files in there.So how do I get the program to run? if I run from /home/usr/src

java File1

I get: Exception in thread "main" java.lang.NoClassDefFoundError: File1 (wrong name: com/myfirm/program/Program)

View Replies View Related

Read Date From File / Calculate And Then Displays That Data In Table Format On Screen

Apr 22, 2015

The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:

Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:

111
251.41
222
402.00

With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.

import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {

[Code] .....

View Replies View Related

Use DLL On Java Application

Sep 10, 2014

I am working with DLLs in java.

A while ago, I developed an application in VB.net, and I'm trying to "convert" this application to Java. But this VB.net application uses some specific DLLs and I need to use them in my Java application. However, my knowledge in this respect are quite limited in manupulate DLLs on Java.

Up to this point, I can already load the DLL. I've read some documentation on how to use functions that are in the DLL; but I have some doubts. For example, how can I translate this piece of code to Java?

Java Code:

API = New MyDLL.Base
With API
.para1= "1"
.para2= 2
.para3= True
.para4= False

[Code] ....

View Replies View Related







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