Help with program! (Beginner)
Here is what I'm trying to do:
lo : Smallest. Write a program that allows a user to enter a series of positive integers with a -99 to signal the end of the series. The program should then display the smallest of the numbers in the series. Do not use a bogus value for the smallest to begin the program. Use the first value in the data list (if any) to initialize your smallest. This program must have only one programmer-defined method other than main which outputs user directions to the console about how the program works (and that -99 is to be used to end the input). Note that an empty list is possible and should not confuse your program! After displaying directions to the console, use GUI for the remaining input and output. Try out your program on the following lists:
10, 3, 8, 2, -99 (lo = 2)
-99 (ouput should be: "no numbers, no lo")
4, 6, 1, 106, 22, -99 (lo = 1)
So far, I've established that...
loop, probably do/while
get input from user, input
if input != "-99",
set list[i] (array) = input
if input == "-99"
set list[i] = input (makes it easy to terminate your loop through the array and to tell if it is otherwise emtpy)
sort through array, comparing two elements of the array, keep lowest and compare to next available, till -99 found
print as necessary
- This is what my friend has told me so far, but I'm not sure what he means by 'set list[i] (array) = unput.
Please help! Either respond here or my screen name (AIM) is Bionix12
Here's what I've got so far:
import javax.swing.JOptionPane;
public class IO {
public static void main(String[]args){
String dataString =
JOptionPane.showInputDialog(null,
"Enter an int value",
"IO",
JOptionPane.QUESTION_MESSAGE);
int data = Integer.parseInt(dataString);
int min = data;
do {
dataString = JOptionPane.showInputDialog(null,
"Enter an int value: \n (the program exits if the input is -99)",
"IO",
JOptionPane.QUESTION_MESSAGE);
data = Integer.parseInt(dataString);
if (data != -99 && data > min){
min = data
while (number != -99) {
JOptionPane.showMessageDialog(null,
"The min value is " + data,
"IO",
JOptionPane.INFORMATION_MESSAGE);
}
Similar Messages
-
Hai,
Can any one give example for search help with Programming?
I hope we can create search help with help of coding.
With Regards,Jaheer.yes u can create search help by using match code in programs
for eq
go with abap editor se 38
provide the name of program
parameters : vendor like lfa1-lifnr matchcode object yzob.
double click on yzob
provide description for search help
provide selection method
provide search help parameter
enable check box for import and export
provide lpos
spos
save check activate
press f4 for check and import values i.e it will display a records list available in database table
rewards points please -
Hi everybody,
I designed a calculator, and I need help with the rest of the scientific actions. I know I need to use the different Math methods, but what exactly? Also, it needs to work as an applet and application, and in the applet, the buttons don't appear in order, how can I fix that?
I will really appreciate your help with this program, I need to finish it ASAP. Please e-mail me at [email protected].
Below is the code for the calcualtor.
Thanks in advance,
-Maria
// calculator
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class calculator extends JApplet implements
ActionListener
private JButton one, two, three, four, five, six, seven,
eight, nine, zero, dec, eq, plus, minus, mult, div, clear,
mem, mrc, sin, cos, tan, asin, acos, atan, x2, sqrt, exp, pi, percent;
private JLabel output, blank;
private Container container;
private String operation;
private double number1, number2, result;
private boolean clear = false;
//GUI
public void init()
container = getContentPane();
//Title
//super("Calculator");
JPanel container = new JPanel();
container.setLayout( new FlowLayout( FlowLayout.CENTER
output = new JLabel("");
output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
output.setPreferredSize(new Dimension(1,26));
getContentPane().setBackground(Color.white);
getContentPane().add( "North",output );
getContentPane().add( "Center",container );
//blank
blank = new JLabel( " " );
container.add( blank );
//clear
clear = new JButton( "CE" );
clear.addActionListener(this);
container.add( clear );
//seven
seven = new JButton( "7" );
seven.addActionListener(this);
container.add( seven );
//eight
eight = new JButton( "8" );
eight.addActionListener(this);
container.add( eight );
//nine
nine = new JButton( "9" );
nine.addActionListener(this);
container.add( nine );
//div
div = new JButton( "/" );
div.addActionListener(this);
container.add( div );
//four
four = new JButton( "4" );
four.addActionListener(this);
container.add( four );
//five
five = new JButton( "5" );
five.addActionListener(this);
container.add( five );
//six
six = new JButton( "6" );
six.addActionListener(this);
container.add( six );
//mult
mult = new JButton( "*" );
mult.addActionListener(this);
container.add( mult );
//one
one = new JButton( "1" );
one.addActionListener(this);
container.add( one );
//two
two = new JButton( "2" );
two.addActionListener(this);
container.add( two );
//three
three = new JButton( "3" );
three.addActionListener(this);
container.add( three );
//minus
minus = new JButton( "-" );
minus.addActionListener(this);
container.add( minus );
//zero
zero = new JButton( "0" );
zero.addActionListener(this);
container.add( zero );
//dec
dec = new JButton( "." );
dec.addActionListener(this);
container.add( dec );
//plus
plus = new JButton( "+" );
plus.addActionListener(this);
container.add( plus );
//mem
mem = new JButton( "MEM" );
mem.addActionListener(this);
container.add( mem );
//mrc
mrc = new JButton( "MRC" );
mrc.addActionListener(this);
container.add( mrc );
//sin
sin = new JButton( "SIN" );
sin.addActionListener(this);
container.add( sin );
//cos
cos = new JButton( "COS" );
cos.addActionListener(this);
container.add( cos );
//tan
tan = new JButton( "TAN" );
tan.addActionListener(this);
container.add( tan );
//asin
asin = new JButton( "ASIN" );
asin.addActionListener(this);
container.add( asin );
//acos
acos = new JButton( "ACOS" );
cos.addActionListener(this);
container.add( cos );
//atan
atan = new JButton( "ATAN" );
atan.addActionListener(this);
container.add( atan );
//x2
x2 = new JButton( "X2" );
x2.addActionListener(this);
container.add( x2 );
//sqrt
sqrt = new JButton( "SQRT" );
sqrt.addActionListener(this);
container.add( sqrt );
//exp
exp = new JButton( "EXP" );
exp.addActionListener(this);
container.add( exp );
//pi
pi = new JButton( "PI" );
pi.addActionListener(this);
container.add( pi );
//percent
percent = new JButton( "%" );
percent.addActionListener(this);
container.add( percent );
//eq
eq = new JButton( "=" );
eq.addActionListener(this);
container.add( eq );
//Set size and visible
setSize( 190, 285 );
setVisible( true );
public static void main(String args[]){
//execute applet as application
//applet's window
JFrame applicationWindow = new JFrame("calculator");
applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//applet instance
calculator appletObject = new calculator();
//init and start methods
appletObject.init();
appletObject.start();
} // end main
public void actionPerformed(ActionEvent ae)
JButton but = ( JButton )ae.getSource();
//dec action
if( but.getText() == "." )
//if dec is pressed, first check to make shure there
is not already a decimal
String temp = output.getText();
if( temp.indexOf( '.' ) == -1 )
output.setText( output.getText() + but.getText() );
//clear action
else if( but.getText() == "CE" )
output.setText( "" );
operation = "";
number1 = 0.0;
number2 = 0.0;
//plus action
else if( but.getText() == "+" )
operation = "+";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//minus action
else if( but.getText() == "-" )
operation = "-";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//mult action
else if( but.getText() == "*" )
operation = "*";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//div action
else if( but.getText() == "/" )
operation = "/";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//eq action
else if( but.getText() == "=" )
number2 = Double.parseDouble( output.getText() );
if( operation == "+" )
result = number1 + number2;
else if( operation == "-" )
result = number1 - number2;
else if( operation == "*" )
result = number1 * number2;
else if( operation == "/" )
result = number1 / number2;
//output result
output.setText( String.valueOf( result ) );
clear = true;
operation = "";
//default action
else
if( clear == true )
output.setText( "" );
clear = false;
output.setText( output.getText() + but.getText() );Multiple post:
http://forum.java.sun.com/thread.jsp?forum=31&thread=474370&tstart=0&trange=30 -
Can anyone help with programming co ordinates.
how do i develop a class specification for class points.
//pointTest.java
main(...)
Point P1;
P1.create(24,16); // create a point with coordinates {24,16}
P1.display(); // display the {X,Y} coordinates of P1
can anyone help with coding to program two points. can anyone elaborate on the stubs shown above to develop one point.There's already a Point class. So use that.
Unless this is a homework in which case, well, it's your homework isn't it? So why are you asking us? -
Hello, I am new to java and I need a bit of help with some code that I'm writing. here is the code:
import javax.swing.*;
public class Test{
public static void main(String[] args){
JOptionPane.showMessageDialog(null,"We will now build a block with *'s","Block",1);
String input=JOptionPane.showInputDialog(null,"Type a number: ","Number",3);
int number=Integer.parseInt(input);
int count=0; int count2=0;
for(count2=0; count2<number; count2++){
for(count=0; count<number; count++){
System.out.print("* ");
System.exit(0);
}Now, all I need is to build a block of *'s with the number that the user inputs. With the code that I wrote I get the correct number of *'s but not in the form of a block. They just print out in a straight line. I know this is a very simple task but could someone please help me out? What do I need to modify in my code so that the *'s print out arranged as a block like so:
**********Your code only uses the print method which prints without a carriage return/line feed. So you need to add a line of code to print a carriage return/line feed. Where? well that is your task to work out.
-
Beginner needs help with programming assignment
So I have been working on it and it is reading everything and posting everything to the output file, but it looks like this
MonthlyRainfall(cm)
Average: 3.66
January 7.29, above averageApril3.55, below averageNovember0.15, below average
When instead it should look like this. Don't know what I need to do to get it to work like this. If I have to much regarding the IF Else statements or I just don't have it laid out right. Any help is appreciated. Thanks.
Monthly Rainfall (cm)
Average: 3.66
January 7.29, above average
April 3.55, below average
November 0.15, below average
Here is the code I have so far:
package assign4;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Rainfall2 {/** main method
* This is where the program starts.
* @param args
public static void main(String[] args) throws FileNotFoundException {
* Title: Assignment 4
* Description: CS 161 Assignment #4
* date: October 27th 2008
final String fileName = "src/assign4/rain2.txt";
Scanner myFile = new Scanner( new FileReader( fileName ) );
PrintWriter outFile = new
PrintWriter ("src/assign4/rainfalloutput.out");
//declares variables
String title;
String subtitle;
String units;
String date;
int month1, month2, month3;
double rain1, rain2, rain3;
double average;
* Read 6 lines from the input file
title = myFile.next();
subtitle = myFile.next();
units = myFile.next();
month1 = myFile.nextInt();
rain1 = myFile.nextDouble();
month2 = myFile.nextInt();
rain2 = myFile.nextDouble();
month3 = myFile.nextInt();
rain3 = myFile.nextDouble();
myFile.close(); //close the input file
average = (rain1 + rain2 + rain3) / 3.0; //computes the average rainfall from data points
outFile.println( title + subtitle + units);
outFile.printf ("Average: %5.2f %n", average);
if (month1 == 1)
outFile.print ("January ");
else if (month1 == 2)
outFile.print ("February");
else if (month1 == 3)
outFile.print ("March");
else if (month1 == 4)
outFile.print ("April");
else if (month1 == 5)
outFile.print ("May");
else if (month1 == 6)
outFile.print ("June");
else if (month1 == 7)
outFile.print ("July");
else if (month1 == 8)
outFile.print ("August");
else if (month1 == 9)
outFile.print ("September ");
else if (month1 == 10)
outFile.print ("October");
else if (month1 == 11)
outFile.print ("November");
else if (month1 == 12)
outFile.print ("December");
if (rain1 > average)
outFile.print ( rain1 + ", above average");
else
if (rain1 == average)
outFile.print ( rain1 + ", average");
else
if (rain1 < average)
outFile.print ( rain1 + ", below average");
if (month2 == 1)
outFile.printf ("January");
else if (month2 == 2)
outFile.printf ("February");
else if (month2 == 3)
outFile.printf ("March");
else if (month2 == 4)
outFile.printf ("April");
else if (month2 == 5)
outFile.printf ("May");
else if (month2 == 6)
outFile.printf ("June");
else if (month2 == 7)
outFile.printf ("July");
else if (month2 == 8)
outFile.printf ("August");
else if (month2 == 9)
outFile.printf ("September");
else if (month2 == 10)
outFile.printf ("October");
else if (month2 == 11)
outFile.printf ("November");
else if (month2 == 12)
outFile.printf ("December");
if (rain2 > average)
outFile.printf ( rain2 + ", above average");
else
if (rain2 == average)
outFile.printf ( rain2 + ", average");
else
if (rain2 < average)
outFile.printf ( rain2 + ", below average");
if (month3 == 1)
outFile.printf ("January");
else if (month3 == 2)
outFile.printf ("February");
else if (month3 == 3)
outFile.printf ("March");
else if (month3 == 4)
outFile.printf ("April");
else if (month3 == 5)
outFile.printf ("May");
else if (month3 == 6)
outFile.printf ("June");
else if (month3 == 7)
outFile.printf ("July");
else if (month3 == 8)
outFile.printf ("August");
else if (month3 == 9)
outFile.printf ("September");
else if (month3 == 10)
outFile.printf ("October");
else if (month3 == 11)
outFile.printf ("November");
else if (month3 == 12)
outFile.printf ("December");
if (rain3 > average)
outFile.printf ( rain3 + ", above average");
else
if (rain3 == average)
outFile.printf ( rain3 + ", average");
else
if (rain3 < average)
outFile.printf ( rain3 + ", below average");
outFile.close();
}The printf method does not inlcude a LF/CR. You will have to add it yourself.
In future when you post code, highlight it and click the CODE button to retain formatting. -
Need help with program for Inner join
Hello Experts,
I need to create a list from table sbook containing booking number (sbook-bookid), customer number (sbook-customid), customer name (scustom-name) , customer class (sbook-class) and ticket price (sflight-price). I am new to ABAP and am very confused I tried reading up some examples and came up with the attached program
Attached is my program for inner join
Kindly Help
Thanks SuHi Su K
You May use key fields , Foreign keys for joining , Here
SELECT SBOOK~BOOKID SBOOK~CUSTOMID SBOOK~CLASS
SCUSTOM~ID SCUSTOM~NAME FROM SFILGHT
INNER JOIN SBOOK ON SBOOK~CARRID EQ SFILGHT~CARRID
SBOOK~CONNID EQ SFILGHT~CONNID
SBOOK~FLDATE EQ SFILGHT~FLDATE
INNER JOIN SCUSTOM ON SCUSTOM~ID = SBOOK~ID -
Help with programs not opening!
I have a Lenovo Ideapad Miix 10.
Worked fine until recently. Now when I try to open something like Word or Excel, they don't open. Instead, it takes me to the desktop and does nothing. When I go to "troubleshoot compatibility", I have the option to test the program, allow access to change the computer (or whatever its asking for..) but it still does nothing. When I click no and select that the problem is not fixed, the troubleshooter lists incompatible program as being detected.
This is really inconvenient, and I am still getting comfortable with the windows tablet so dont exactly know my way around yet. anyone able to help out? thanks in advance!You are posting in the "icloud on my mac" forum, but your profile mentions Windows. If using a mac, you need to have iphoto or aperture installed in order to receive new photos via photo stream. If using windows, try posting in the iCloud on a PC forum. You'll get better help there.
https://discussions.apple.com/community/icloud/icloud_on_my_pc -
Rookie needs help with program!!
Hi everyone,
I am new to JAVA programming and am trying to figure out my first progam. Any suggestions? Here's what I have to come up with...
This program will test your ability to code a loop function and some work with the strings methods.
INPUT
A SENTENCE OF UNKNOWN LENGTH.
OUTPUT
THE NUMBER OF WORDS IN THE SENTENCE AND EACH WORD ON A SEPARATE LINE. Two spaces are not a word; "a" is a word.
HINT
Use a loop until the end of the sentence and count each word that is removed from the front of the sentence (one at a time). Each time the sentence should be shortened.
I know I need to use a string method...Here's what I have so far...
public class jmstr
public static void main (String[ ] args)
System.out.println ("Please enter a sentence starting with some spaces ");
inputline = SavitchIn.readLine ( ) ;
System.out.println (inputline);
I'm not really sure what to do next....?
Any help would be appreciated!
matermanhttp://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html
look at the example on the page, then scroll down to the Methods section and click on
countTokens() -
Help with program to remove comments from chess(pgn) text files
Hi
I would like to make a java program that will remove chessbase comments from pgn files (which are just based text files).
I have done no java programming on text files so far and so this will be a new java adventure for me. Otherwise I have limited basic java experience mainly with Java chess GUI's and java chess engines.
I show here a portion of such a pgn text file with the chessbase comments which are between the curly braces after the moves:
1. e4 {[%emt 0:00:01]} c6 {[%emt 0:00:10]} 2. d4 {[%emt 0:00:03]} d5 {
[%emt 0:00:01]} 3. e5 {[%emt 0:00:01]} Bf5 {[%emt 0:00:01]} 4. h4 {
[%emt 0:00:02]} e6 {[%emt 0:00:02]}
I want to make a java program if possible that removes these comments, so just leaving the move notation eg:
1. e4 c6 2. d4 d5 3. e5 Bf5 4. h4 e6
I am just starting with this. As yet I am unsure how to begin and do this and I would be extremely grateful for any help and advice to get me going with this project.
I look forward to replies, many thanksI found a simple java text editor (NutPad-with sourcecode) and have tried to adapt it to incorporate the regular expressions code suggested by ChuckBing and renamed it CleanCBpgnPad.
Presently this won't compile! (not surprising).
I copy the code here:
//CleanCBpgnPad by tR2 based on NutPad text editor
// editor/NutPad.java -- A very simple text editor -- Fred Swartz - 2004-08
// Illustrates use of AbstractActions for menus.
//http://www.roseindia.net/java/java-tips/45examples/20components/editor/nutpad.shtml
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class CleanCBpgnPad extends JFrame {
//-- Components
private JTextArea mEditArea;
private JFileChooser mFileChooser = new JFileChooser(".");
//-- Actions
private Action mOpenAction;
private Action mSaveAction;
private Action mExitAction;
private Action mCleanAction;
//===================================================================== main
public static void main(String[] args) {
new CleanCBpgnPad().setVisible(true);
}//end main
//============================================================== constructor
public CleanCBpgnPad() {
createActions();
this.setContentPane(new contentPanel());
this.setJMenuBar(createMenuBar());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("CleanCBpgnPad");
this.pack();
}//end constructor
///////////////////////////////////////////////////////// class contentPanel
private class contentPanel extends JPanel {
//========================================================== constructor
contentPanel() {
//-- Create components.
mEditArea = new JTextArea(15, 80);
mEditArea.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
mEditArea.setFont(new Font("monospaced", Font.PLAIN, 14));
JScrollPane scrollingText = new JScrollPane(mEditArea);
//-- Do layout
this.setLayout(new BorderLayout());
this.add(scrollingText, BorderLayout.CENTER);
}//end constructor
}//end class contentPanel
//============================================================ createMenuBar
/** Utility function to create a menubar. */
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = menuBar.add(new JMenu("File"));
fileMenu.add(mOpenAction); // Note use of actions, not text.
fileMenu.add(mSaveAction);
fileMenu.add(mCleanAction);
fileMenu.addSeparator();
fileMenu.add(mExitAction);
return menuBar;
}//end createMenuBar
//============================================================ createActions
/** Utility function to define actions. */
private void createActions() {
mOpenAction = new AbstractAction("Open...") {
public void actionPerformed(ActionEvent e) {
int retval = mFileChooser.showOpenDialog(CleanCBpgnPad.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File f = mFileChooser.getSelectedFile();
try {
FileReader reader = new FileReader(f);
mEditArea.read(reader, ""); // Use TextComponent read
} catch (IOException ioex) {
System.out.println(e);
System.exit(1);
mSaveAction = new AbstractAction("Save") {
public void actionPerformed(ActionEvent e) {
int retval = mFileChooser.showSaveDialog(CleanCBpgnPad.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File f = mFileChooser.getSelectedFile();
try {
FileWriter writer = new FileWriter(f);
mEditArea.write(writer); // Use TextComponent write
} catch (IOException ioex) {
System.out.println(e);
System.exit(1);
mCleanAction = new AbstractAction ("Clean"){
public void actionPerformed (ActionEvent e) {
int retval = mFileChooser.showCleanDialog(CleanCBpgnPad.this);
if (retval== JFileChooser.APPROVE_OPTION){
File f = mFileChooser.getSelectedFile();
try {
FileCleaner cleaner = new FileCleaner (c);
mEditArea.clean(cleaner); // Use TextComponent clean
}catch (IOException ioex){
String str = "1. e4 {[%emt 0:00:01]} c6 {[%emt 0:00:10]} 2. d4 {[%emt 0:00:03]} d5 {[%emt 0:00:01]} " + "3. e5 {[%emt 0:00:01]} Bf5 {[%emt 0:00:01]} 4. h4 {[%emt 0:00:02]} e6 {[%emt 0:00:02]}";
str = str.replaceAll("\\{.*?\\}", "");
System.out.println(str);
System.exit(1);
mExitAction = new AbstractAction("Exit") {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}//end createActions
}//end class CleanCBpgnPad
As seen I added a newAction mClean.
4 errors arise starting with line 101-cannot find symbol method showCleanDialog
then 3 errors on line 104 tryfilecleaner
Can anyone help me with this please?
Can I incorporate the regular expression code to remove these text comments into this text editor code and if so how?
Obviously a lot of this code is new to me and I will continue to study it and hope to learn to understand most , if not all of it!
Again I look forward to replies,thanks -
Help with JNLP - Beginner with JNLP
Hey guys, I am new here and was hoping someone might be able to help me understand what's going on with this JNLP hocus pocus.
Basically, I'm just trying to deploy a very simple applet using a .jnlp file. I created the applet in Eclipse and it runs fine in the IDE. I set up my jnlp and html files pretty much exactly how the tutorial on Sun's website suggests, but my stupidity seems to prevent the applet from working inside a browser.
The files I'm using are all in the same folder. They are:
HiddenPrizePage.html
HiddenPrizeTask.jar
HiddenPrizeApplet.jnlp
I created my jar using Export in Eclipse with no compression, with the "Export generated class files and resources" checkbox selected. The images folder contains all images used by the applet. The images folder is inside of src. The program is structured so that the logic and drawing is done by HiddenPrizePanel.java and the applet itself is inside HiddenPrizeApplet.java.
MY HTML FILE:
<html>
<body>
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var attributes = { code:'HiddenPrizeApplet', width:800, height:600} ;
var parameters = {jnlp_href: 'HiddenPrizeApplet.jnlp'} ;
deployJava.runApplet(attributes, parameters, '1.6');
</script>
</body>
</html>
MY JNLP FILE:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Hidden Prize Task</title>
<vendor>Clinical Neuroscience Lab at OSU</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="HiddenPrizeTask.jar" main="true" />
</resources>
<applet-desc
name="Hidden Prize Task Applet"
main-class="HiddenPrizeApplet"
width="800"
height="600">
</applet-desc>
<update check="background"/>
</jnlp>
When I try to run the applet inside of a browser, nothing happens. I can right-click the blank space on the page where the applet should theoretically be appearing and choose "Open Java Console" to check for error messages, so I did, and it says:
load: class components.HiddenPrizeApplet not found.
java.lang.ClassNotFoundException: components.HiddenPrizeApplet
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.JNLP2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: components.HiddenPrizeApplet
load: class components.HiddenPrizeApplet not found.
java.lang.ClassNotFoundException: components.HiddenPrizeApplet
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.JNLP2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: components.HiddenPrizeApplet
Can anyone help me figure out what I'm doing wrong? I don't understand why it says "components." in front of "HiddenPrizeApplet" whenever HPA is referenced, since I never refer to HPA as "components.HiddenPrizeApplet" in my jnlp or html files, and I certainly didn't put the java files or the class files or any other kinds of files in a folder or package named "components" to my knowledge. Thanks for any help you can provide.What is the copy/pasted lines in HPA between the first line up to & including..
public class HiddenPrizeApplet extends (J)Applet..?
BTW - when posting code or code snippets, HTML/XML(/JNLP) or input/output. please use the code tags as described on the 'sticky post' at the top of the forum thread listing. You can still edit your original post to do that, but before you do so, it would pay to run the JNLP through JaNeLA and fix any report in the output list that has a red high light. The JNLP as it stands is invalid in at least one respect. But don't take my word for it, JaNeLA validates against an XSD that is better than Oracle's DTD. I am confident in saying that, because I was involved with the development of the XSD ..& JaNeLA. ;) -
Help with program flow and timing a loop please
I'm working on an application that will display vibration data on several tabs. 1 tab displays the time waveform, another a running RMS value, another an FFT etc.
On another tab I want the user to have the option of streaming the data to disk for 'x' number of seconds.
I created a sub-vi with a flat sequence structure.
The first frame open/creates a file. The second frame gets the current time in seconds and adds 'x' seconds to it. The third frame contains a while loop with a "Get Current Time in Seconds" and a "Write to Binary File" which executes while the current time is less than the "previous current time plus 'x'".
This sub-vi is in a while loop that is called when a "capture data" button is pressed.
My problem is that the rest of the program (waveform, RMS, FFT displays) stops executing when the while loop / sub-vi is executing.
This can be seen via the "TEST" indicator that doesn't update.
When the program flow goes back to the rest of the program I get an error 'cause the buffer has over-flown (ed)
I'm really new at this so any help is greatly appreciated.
I've attached images of the main vi (Project3.pdf) and the sub-vi containing the Flat Sequence (WriteToDisk.pdf)
I can attach the actual vis if it helps.
Thanks,
Erik
Attachments:
Project3.pdf 189 KB
WriteToDisk.pdf 85 KBThe behavior you're seeing is by design. There are two solutions to your problem:
Place the write to file in a separate loop that runs in parallel to your main loop. Thus, your "Project3" VI would have two loops. One is the data acquisition, the other is the streaming to file. You should not create data dependencies between the loops that would cause one loop to wait until the other is done. You want both running in parallel. You can stop both loops with the same stop button. With this method you can use local variables to get the Time Waveform data as you're doing now.
Launch the stream to file VI dynamically. This basically uses the VI Server to start a subVI and then immediately return to the caller. The subVI is then running on its own. There are examples that ship with LabVIEW that show you how to do this. You would have to have the subVI monitor something to determine if it should stop should the main program stop.
The first option would be the easiest to implement in your case. The second is more complex, but leaves you with one loop. -
Help with unhappy beginner code...
Hello Java gurus,
I'm learning java and one of my class assignments is the old "mortgage calculator"... I made code up, compiled okay, but it won't execute. Gives me all sorts of errors. I THINK it's to do with the double vs int vs float... Please help!!! I've been playing with this and can't figure whats erroring. I know its prob something simple so please explain when you write back what I'm not understanding... Thank you! -nika
Assignment:
The monthly payment on mortgage loan of L dollars, at a rate of interest r is given by
Monthly payment = []
Where N is the number of years of mortgage. Write a program to find the monthly
payment for 30 years, for principals from $100,000 through $200,000(with increments
of $20,000) and interest rates of 6% through 10% (with increments of 0.5%). Print
monthly payment as a whole number (rounded off).
The output must be a neat table, similar to the following (your answers may be slightly
different because of rounding off).
Principal 6% 6.5% 7% 7.5% 8% 8.5% 9% 9.5% 10%
100000 600 632 665 699 733 768 804 840 877
120000 719 758 798 839 880 922 965 1009 1053
140000 � � � � � � � � �
160000 � � � � � � � � �
180000 � � � � � � � � �
200000 � � � � � � � � �
Hint: Use the following idea to compute (1 + r/12)12N
double temp = 1+r/12;
double temp1 = 1;
for (int i = 1; i<=12*N;i++)
temp1 = temp1*temp;
The final formula now becomes:
double mp = (L*(r/12)*temp1)/(temp1-1);
MY CODE:
import java.util.*;
class MortgagePmt {
public static void main(String args[]) {
int n = 30;
System.out.println("Mortgage Monthly Payment");
System.out.println("Principal 6.0% 6.5% 7.0% 7.5% 8.0% 8.5% 9.0% 9.5% 10.0% ");
for (int l = 100000; l<=200000; l=l+20000){
System.out.printf("%9d ",l);
for(double r = 6.0; r<=10.0; r=r+0.5){
double temp = 1+r%12;
double temp1 = 1;
for (int i = 1; i<=12*n;i++)
temp1 = temp1*temp;
double mp = (l*(r%12)*(temp1))/(temp1 - 1);
System.out.printf("%5.0f", mp);
System.out.println("");
}You really need to do an analysis on your algo... there is NO WAY that it is correct.
MY CODE:
import java.util.*;
class MortgagePmt {
public static void main(String args[]) {
int n = 30;
System.out.println("Mortgage Monthly Payment");
System.out.println("Principal 6.0% 6.5% 7.0% 7.5% 8.0% 8.5% 9.0% 9.5% 10.0% ");
for (int l = 100000; l<=200000; l=l+20000){
System.out.printf("%9d ",l);
for(double r = 6.0; r<=10.0; r=r+0.5){
double temp = 1+r%12;
double temp1 = 1;What is this following little section for? temp1 comes out of there at 1.7x10^304... err, no way that is right. I do not believe there is that much anything in the world, let alone money.
for (int i = 1; i<=12*n;i++)
temp1 = temp1*temp;
double mp = (l*(r%12)*(temp1))/(temp1 - 1);
System.out.printf("%5.0f", mp);
System.out.println("");
}One of the best things you can do at this point, if it's not thee very best thing, is to get your debugger out and find out how to use it. Your code ran as you posted it, but your algorithm is not right and numbers you are calculating do not even make sense--all of them output as NaN (not a number). Take each feature of your assignment and code it 1 piece at a time tracing each seeing that the numbers you calculate make sense, and as you get that piece to work, move on to the next feature of your assignment. This way you don't write out a bunch of none tested code that you don't know what it is doing.
Throwing out code that you think is a solution that you do not know what it does and have no hope of fixing is no better than no solution at all--IMO it is far worse: you'll work attempting to fix it, not knowing what it is doing and all the time all you are building is your frustration.
(BTW: don't think I'm singling you out and speaking harshly to you--I've been there too. Sometimes it's better to just start over. Get a handle on what needs to be done. Get a working pencil and paper model, then describe the process in an algorithm, then code from that algorithm. Implement in steps and make sure each step works before moving on to the next. There is no magic in the computer--it won't make a bad process good--on the contrary it usually makes bad things worse, you have to design a good process first to implement a good process.) -
Help with program plz (long code)
anyone know how i can fix these 2 errors:
Driver2.java:47: code is already defined in main(java.lang.String[])
String code = JOptionPane.showInputDialog(
^
Driver2.java:51: incompatible types
found : java.lang.String
required: int
int val = bc.getCode();
^
the case 2 in the driver is where it messes up, i believe..it works with just the case 1...any help/advice is appreciated(i am aware of spacing errors)
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Driver2
public static void main(String[] args)
String userChoice;
int choice;
Scanner keyboard = new Scanner(System.in);
userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
+ "Enter 2 to enter a bar code:\n"
+ "Enter 3 to exit program:\n");
choice = Integer.parseInt(userChoice);
while (choice != 3)
switch (choice)
case 1:
String input = JOptionPane.showInputDialog( "Please enter a five-digit zip code: ");
int num = Integer.parseInt(input);
BarCode bc = new BarCode(num);
String code = bc.getCode();
JOptionPane.showMessageDialog(null, "The barcode of the zip is: " + code);
System.exit(0);
break;
case 2:
String code = JOptionPane.showInputDialog( "Please enter bar code: ");
int val = bc.getCode();
if (val >= 0)
System.out.println("The zip code is: " + val);
else
System.out.println("Incorrect bar code data");
System.exit(0);
break;
case 3:
break;
userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
+ "Enter 2 to enter a bar code:\n"
+ "Enter 3 to exit program:\n");
public BarCode(int n)
zip = n;
public String getCode()
String barCode = "|";
int sum = 0;
int temp = 0;
temp = zip / 10000;
sum = sum + temp;
Digit d1 = new Digit(temp);
barCode = barCode + d1.getCode();
zip = zip % 10000;
temp = zip / 1000;
sum = sum + temp;
Digit d2 = new Digit(temp);
barCode = barCode + d2.getCode();
zip = zip % 1000;
temp = zip / 100;
sum = sum + temp;
Digit d3 = new Digit(temp);
barCode = barCode + d3.getCode();
zip = zip % 100;
temp = zip / 10;
sum = sum + temp;
Digit d4 = new Digit(temp);
barCode = barCode + d4.getCode();
zip = zip % 10;
temp = zip;
sum = sum + temp;
Digit d5 = new Digit(temp);
barCode = barCode + d5.getCode();
temp = 10 - (sum % 10);
Digit d6 = new Digit(temp);
barCode = barCode + d6.getCode() + "|";
return barCode;
private int zip;
public class BarCode1
public BarCode1(int n)
zip = n;
public String getCode()
String barCode = "|";
int sum = 0;
int temp = 0;
temp = zip / 10000;
sum = sum + temp;
Digit d1 = new Digit(temp);
barCode = barCode + d1.getCode();
zip = zip % 10000;
temp = zip / 1000;
sum = sum + temp;
Digit d2 = new Digit(temp);
barCode = barCode + d2.getCode();
zip = zip % 1000;
temp = zip / 100;
sum = sum + temp;
Digit d3 = new Digit(temp);
barCode = barCode + d3.getCode();
zip = zip % 100;
temp = zip / 10;
sum = sum + temp;
Digit d4 = new Digit(temp);
barCode = barCode + d4.getCode();
zip = zip % 10;
temp = zip;
sum = sum + temp;
Digit d5 = new Digit(temp);
barCode = barCode + d5.getCode();
temp = 10 - (sum % 10);
Digit d6 = new Digit(temp);
barCode = barCode + d6.getCode() + "|";
return barCode;
private int zip;
public class Digit
public Digit(int n)
zip = n;
public String getCode()
String bar = "";
if (zip == 1)
bar = ":::||";
else if (zip == 2)
bar = "::|:|";
else if (zip == 3)
bar = "::||:";
else if (zip == 4)
bar = ":|::|";
else if (zip == 5)
bar = ":|:|:";
else if (zip == 6)
bar = ":||::";
else if (zip == 7)
bar = "|:::|";
else if (zip == 8)
bar = "|::|:";
else if (zip == 9)
bar = "|:|::";
else
bar = "||:::";
return bar;
private int zip;
public class Digit1
public Digit1(int n)
zip = n;
public String getCode()
String bar = "";
if (zip == 1)
bar = ":::||";
else if (zip == 2)
bar = "::|:|";
else if (zip == 3)
bar = "::||:";
else if (zip == 4)
bar = ":|::|";
else if (zip == 5)
bar = ":|:|:";
else if (zip == 6)
bar = ":||::";
else if (zip == 7)
bar = "|:::|";
else if (zip == 8)
bar = "|::|:";
else if (zip == 9)
bar = "|:|::";
else
bar = "||:::";
return bar;
private int zip;
}> i got it to compile now...i can toy around w/
it..thanks for the help
Good.
Stick with this handle, ok?I must say I am not thrilled with
a) when I questioned the first post of WhiteSox asking if it was bugz or a classmate or what I was ignored by the OP
b) I guess the OP is trying to distance himself from his very first thread where somebody did part of his homework for him with results that are now plainly evident. As I predicted at the end of the last thread.
http://forum.java.sun.com/thread.jspa?threadID=703258 Reply 11
I hope that matsabigman and others who help homework posters by doing it for them will take note of the results of this help thus far. Not much good has come of this.
BigMan/WhiteSox I am still detecting a fundamental lack of basic concepts on your part. This is the underlying cause of your compile errors but those are only a symptom. You can continue treating the symptoms but it would be a better use of your time to treat the disease, which in this case means spending some time getting a better grasp of Java fundamentals. -
For my intro to programming class I have this program where i have to take 5 names put them in an array, assign 25 scores (given) to a 1d array named temp and move to an array that is 2d with each 5 scores going to a new line (person). Then you must create a function to compute row & column total, high, low, and average. The average drops the lowest grade and doubling the final exam. Then you must create a function to assign a grade letter in a char array. Then call a "drawGraph" function that prints a bar chart for each person that shows their averages. Then print the results in a frame windwo and then call a function that prints the other arrays in table form (with headings).
I know this is a long post but I cannot get this thing to run and i have typed almost all the code, so any help would be greatly appreciated! This is what i have so far:
import java.io.*;
import javax.swing.*;
import java.net.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
public static void main()
JTextArea dataout= new JTextArea(400,50);
Frame df = new Frame("application frame");
df.setSize(800,500);
Graphics g = df.getGraphics();
int temp[]={34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66};
int scores[][]=new int[8][8];
float[]avg=new float[5];
String name[]={"Mary","John","William","Debbie","Ralph"};
String out=" ";
char grade[]=new char[5];
int c=0;
int d=0;
int e=0;
for (int a=0;a<5;a++)
for(int b=0;b<5;b++)
scores[a]=temp[c];
c++;
scores[a][6]=200;
scores[6][a]=200;
finishscoresarray(scores);
getAverage(scores,avg,grade);
prntGraph(g,avg,name);
prntData(avg,name,grade,scores,out);
dataout.setText(out);
JOptionPane.showMessageDialog(null,out);
public static void finishscoresarray(int[][]scores)
for(int a=0;a<5;a++)
for(int b=0;b<5;b++)
scores[5][a]=scores[5][a]+scores[b][a];
scores[a][5]=scores[a][5]+scores[a][b];
if(scores[a][b]<scores[6][a])
scores[6][a]=scores[a][b];
if(scores[b][a]<scores[a][6])
scores[a][6]=scores[b][a];
if(scores[a][b]>scores[7][a])
scores[7][a]=scores[a][b];
if(scores[b][a]>scores[a][7])
scores[a][7]=scores[b][a];
public static void getAverage(int[][]score, float[]avg, char[]grade)
for(int a=0;a<5;a++)
avg[a]=((score[a][5]-score[a][6]+score[a][4])/5);
if(avg[a]>89)
grade[a]='A';
else if(avg[a]>79)
grade[a]='B';
else if(avg[a]>69)
grade[a]='C';
else if(avg[a]>59)
grade[a]='D';
else
grade[a]='F';
public static void prntGraph(Graphics g, float[]avg, String[]name)
for(int a=0;a<5;a++)
g.drawString(name[a],(int)100*(a+1),100);
g.drawRect(80*(a+1),80*(a+1),(int)avg[a],40);
public static void prntData(float[]avg,String[]name,char[]grade,int[][]scores,String out)
for(int a=0;a<7;a++)
out=out+name[a]+" "+scores[0][a]+" "+scores[1][a]+" "+scores[2][a]+" "+scores[3][a]+" "+scores[4][a]+" "+scores[5][a]+" "+scores[6][a]+" "+scores[7][a]+" "+avg[a]+" "+grade[a]+"\n";
Thanks!but I cannot get this thing to runexplain what it is you expect to happen
e.g.
do you enter some numbers and the output is wrong
does it not compile/run
also, so that people can read the code, repost it, but use the code tags to preserve the formatting
ie click on the code button, which will produce
[code][/code]
and paste your code between the two tags
Maybe you are looking for
-
In the past I had no problems with iTunes, but over the past year or so I'm feeling there is a problem now. When I download upgrade software for my devices I feel Apple or other is removing an important file to do with my movie purchases, people s
-
I don't know my restriction passcode
i dont know my restriction passcode on my ipod 4th gener...
-
SLOW IMAC 2.4GhzINTEL CORE 2, 1 GB MEMORY 10.6
I HAVE SLOW IMAC 2.4GhzI NTEL CORE 2, 1 GB MEMORY OS LION. DO I NEED MORE RAM?
-
Duplicate attribute key in date Dimension
Hi, I have created a date dimension using this code http://www.codeproject.com/Articles/647950/Create-and-Populate-Date-Dimension-for-Data-Wareho It contains one attribute 'Month' I have created one fact table which contains the following dates Start
-
Boot Manager error message on Windows 7 Toshiba Laptop
Well, I will start with what happened to it, though I don't really know. I was on the internet and it started freezing up horribly, then I didn't know what to do so I walked into the room of the house that doesn't get wireless, and gradually it unfro