Help with Rock, Paper, Scissors Program
I need some help with my program, I got understand writing each of the methods I have to do but then i don't understand how to piece it together to make the program work. in the main method...I didn't complete the scrolling message method I just wanted to get the game itself working first then I was going to complete that method. I just need to know if I'm heading in the right direction or if i did something completly wrong
import javax.swing.*;
public class RockPaperScissors
public static void displayScrollingMessage (String list)
String header = "Game #\tUser\tComputer\tWinner\t";
public static void getUserChoice ( )
int game = 1;
for ( game = 1; game > 0 ; game ++)
String input = JOptionPane.showInputDialog ("Choose Rock, Paper, or Scissors\n Enter\n 1 for Rock" +
"\n2 for Paper\n3 for Scissors\n4 to Exit");
String list = " ";
int option = Interger.parseInt (input);
switch (option)
case 1:
int userChoice = 1;
getComputersChoice ();
itemName (userChoice);
itemName2 (computersChoice);
whowins (userChoice, computersChoice);
winnerName (winner);
winlose (winner);
String list =+ game + "/t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
+ itemName2 + "\nTherefore " + winlose);
return userChoice;
break;
case 2:
userChoice = 2;
getComputersChoice ();
itemName (userChoice);
itemName2 (computersChoice);
whowins (userChoice, computersChoice);
winnerName (winner);
winlose (winner);
String list =+ game + "\t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
+ itemName2 + "\nTherefore " + winlose);
return userChoice;
break;
case 3:
userChoice = 3;
getComputersChoice ();
itemName (userChoice);
itemName2 (computersChoice);
whowins (userChoice, computersChoice);
winnerName (winner);
winlose (winner);
String list =+ game + "\t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
+ itemName2 + "\nTherefore " + winlose);
return userChoice;
break;
case 4:
break;
default:
JOptionPane.showMessageDialog (null, "Error!! Please enter a valid option!"
, JOptionPane.WARNING_MESSAGE);
break;
public static int getComputersChoice ()
int computersChoice = (int) (3 * Math.random() + 1);
return computersChoice;
public static String itemName (int userChoice)
if (userChoice == 1)
String itemName = Rock;
else
if (userChoice == 2)
String itemName = Paper;
else
if (userChoice == 3)
String itemName = Scissors;
return itemName;
public static string itemName2 (int computersChoice)
if (computersChoice == 1)
String itemName2 = Rock;
else
if (computersChoice == 2)
String itemName2 = Paper;
else
if (computersChoice == 3)
String itemName2 = Scissors;
return itemName2;
public static string winlose (int winner)
if (winner == 1)
winlose = "You Win!!!";
else
if (winner == 2)
winlose = "You Lose!!";
else
if (winner == 3)
winlose = "Its a Tie!!";
return winlose;
public static string winnerName (int winner)
if (winner == 1)
String winnerName = "User";
else
if (winner == 2)
String winnerName = "Computer";
else
if (winner == 2)
String winnerName = "Tie";
return winnerName;
public static void whoWins (int computersChoice, int userChoice)
if (userChoice == 1 && computersChoice == 1)
int winner = 3;
else
if (userChoice == 1 && computersChoice == 2)
int winner = 2;
else
if (userChoice == 1 && computersChoice == 3)
int winner = 1;
else
if (userChoice == 2 && computersChoice == 1)
int winner = 1;
else
if (userChoice == 2 && computersChoice == 2)
int winner = 3;
else
if (userChoice == 2 && computersChoice == 3)
int winner = 2;
else
if (userChoice == 3 && computersChoice == 1)
int winner = 2;
else {
if (userChoice == 3 && computersChoice == 2)
int winner = 1;
else
if (userChoice == 3 && computersChoice == 3)
int winner = 3;
return winner;
public static void main (String args [])
getUserChoice ( );
System.exit (0);
}
Here's something to compare to
import javax.swing.*;
public class RockPaperScissors
public RockPaperScissors()
String[] pick = {"Rock","Paper","Scissors","Exit"};
int user = 0, computer = 0;
String result = "", output = "";
while(user < 3)
user = JOptionPane.showOptionDialog(null,"Which do you want?",
"Rock-Paper-Scissors",-1,-1,null,pick,"");
if(user == 3) break;
computer = (int)(3*Math.random());
result = getWinner(user,computer);
output = "You chose "+pick[user] + "\nComputer chose " + pick[computer]+
"\n\nResult:- " + result;
JOptionPane.showMessageDialog(null,output);
System.exit(0);
public String getWinner(int player, int comp)
if(Math.abs(player - comp) > 1)
if(player == 2) player = -1;
if(comp == 2) comp = -1;
return player > comp? "You win.":player < comp? "Computer wins.":"Tie.";
public static void main(String[] args){new RockPaperScissors();}
}
Similar Messages
-
I need help with a basic rock paper scissors program!
i need to make a program that allows the computer to play rock paper scissors at random and compare the results with user and tell who wins or if its a tie. can anyone help me?
import java.util.Scanner;
import java.util.Random;
public class RockPaperScissors
public static final int ROCK = 1;
public static final int PAPER = 2;
public static final int SCISSORS = 3;
public static void main(String[] args)
final int NUM_CHOICES = 3;
Random generator = new Random();
int userWins = 0;
int compWins = 0;
int ties = 0;
int compChoice, userChoice;
boolean exit = false;
Random randGen = new Random();
Scanner scan = new Scanner(System.in);
System.out.println("Enter your choice: ");
userChoice = scan.nextInt();
System.out.println("Computers Choice: ");
compChoice = scan.nextInt(); -
Help with getting Images to show in a Rock, Paper, Scissors game
Hi
I am working on this Rock, paper, scissors java game and the program works, but I can not figure out how to get the images to load onto the program. So my question is how do I get the images to load up with the program? I am using JCreator for this project. I have created the Basic Java Application project, and then added in the 3 .java files that I need to run the program, but I just can not figure out how or where I need to upload the files. The game works without the images, but I would really like them to show up.
This is the .java file that calls up the images:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class pss extends JPanel implements ActionListener, ItemListener
private final Color clrBackground = new Color(163,243,255);
private final Color clrForeground = new Color(0,0,0);
private JComboBox cboxWeapon;
private JTextField txtCPUWeapon, txtWins, txtLoses, txtDraws;
private JLabel lblPlayerWeapon, lblCPUWeapon, lblWins, lblLoses, lblDraws, lblStatus, lblPlayerWeaponIcon, lblCPUWeaponIcon;
private JButton cmdPlay, cmdReset;
private ImageIcon[] imgWeapon;
private JPanel panRoot, panPlayerArea, panPlayerWeapon, panCPUArea, panCPUWeapon, panStatusArea, panGo, panCounters, panWins, panLoses, panDraws;
private pssEngine engine = new pssEngine();
private objCreateAppletImage createImage = new objCreateAppletImage();
private boolean errorWithImages = false;
public static void main(String[] args) //With applications, you have to specify a main method (not with applets)
JFrame.setDefaultLookAndFeelDecorated(true); //Make it look nice
JFrame frame = new JFrame("Paper Stone Scissors"); //Title
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false); //Stops the user resizing the window
JComponent paneMain = new pss();
paneMain.setOpaque(true);
paneMain.setPreferredSize(new Dimension(420,350));
frame.setContentPane(paneMain);
frame.pack();
frame.setVisible(true);
public pss ()
cboxWeapon = new JComboBox(engine.getWeapon());
cboxWeapon.addItemListener(this);
txtCPUWeapon = new JTextField(engine.getStrCPUWeapon(), 5);
txtWins = new JTextField("0", 5);
txtLoses = new JTextField("0", 5);
txtDraws = new JTextField("0", 5);
txtCPUWeapon.setEditable(false);
txtWins.setEditable(false);
txtLoses.setEditable(false);
txtDraws.setEditable(false);
lblPlayerWeapon = new JLabel("Choose your weapon", JLabel.CENTER);
lblCPUWeapon = new JLabel("The CPU's weapon", JLabel.CENTER);
lblWins = new JLabel("Amount of wins:", JLabel.RIGHT);
lblLoses = new JLabel("Amount of loses:", JLabel.RIGHT);
lblDraws = new JLabel("Amount of Drawss:", JLabel.RIGHT);
lblStatus = new JLabel("", JLabel.CENTER);
lblPlayerWeaponIcon = new JLabel("", JLabel.CENTER);
lblCPUWeaponIcon = new JLabel("", JLabel.CENTER);
lblPlayerWeaponIcon.setPreferredSize(new Dimension(150,150));
lblCPUWeaponIcon.setPreferredSize(new Dimension(150,150));
cmdPlay = new JButton("Go!");
cmdReset = new JButton("Restart");
cmdPlay.addActionListener(this);
cmdReset.addActionListener(this);
try
imgWeapon = new ImageIcon[3];
for (int i = 0; i < 3; i++)
imgWeapon[i] = createImage.getImageIcon(this, ".src/images/" + engine.getWeapon(i) + ".gif", "Icon for " + engine.getWeapon(i), 13000);
lblPlayerWeaponIcon.setIcon(imgWeapon[0]);
lblCPUWeaponIcon.setIcon(imgWeapon[0]);
catch (Exception ex) //The game works without the images, so carry on
errorWithImages = true;
setLayout(new BorderLayout());
panRoot = new JPanel(new BorderLayout());
panPlayerArea = new JPanel(new BorderLayout());
panPlayerWeapon = new JPanel(new BorderLayout());
panCPUArea = new JPanel(new BorderLayout());
panCPUWeapon = new JPanel(new BorderLayout());
panStatusArea = new JPanel(new BorderLayout());
panGo = new JPanel();
panCounters = new JPanel(new GridLayout(3,1,2,2));
panWins = new JPanel();
panLoses = new JPanel();
panDraws = new JPanel();
add(panRoot, BorderLayout.CENTER);
panRoot.add(panPlayerArea, BorderLayout.WEST);
panPlayerArea.add(panPlayerWeapon, BorderLayout.NORTH);
panPlayerWeapon.add(lblPlayerWeapon, BorderLayout.NORTH);
panPlayerWeapon.add(cboxWeapon, BorderLayout.SOUTH);
panPlayerArea.add(lblPlayerWeaponIcon, BorderLayout.SOUTH);
panRoot.add(panCPUArea, BorderLayout.EAST);
panCPUArea.add(panCPUWeapon, BorderLayout.NORTH);
panCPUWeapon.add(lblCPUWeapon, BorderLayout.NORTH);
panCPUWeapon.add(txtCPUWeapon, BorderLayout.SOUTH);
panCPUArea.add(lblCPUWeaponIcon, BorderLayout.SOUTH);
panRoot.add(panStatusArea, BorderLayout.SOUTH);
panStatusArea.add(panGo, BorderLayout.NORTH);
panGo.add(cmdPlay);
panGo.add(cmdReset);
panGo.add(lblStatus);
panStatusArea.add(panCounters, BorderLayout.SOUTH);
panCounters.add(panWins);
panWins.add(lblWins);
panWins.add(txtWins);
panCounters.add(panLoses);
panLoses.add(lblLoses);
panLoses.add(txtLoses);
panCounters.add(panDraws);
panDraws.add(lblDraws);
panDraws.add(txtDraws);
panRoot.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
setBackground(clrBackground);
panRoot.setBackground(clrBackground);
panPlayerArea.setBackground(clrBackground);
panPlayerWeapon.setBackground(clrBackground);
panCPUArea.setBackground(clrBackground);
panCPUWeapon.setBackground(clrBackground);
panStatusArea.setBackground(clrBackground);
panGo.setBackground(clrBackground);
panCounters.setBackground(clrBackground);
panWins.setBackground(clrBackground);
panLoses.setBackground(clrBackground);
panDraws.setBackground(clrBackground);
lblPlayerWeapon.setForeground(clrForeground);
lblCPUWeapon.setForeground(clrForeground);
lblWins.setForeground(clrForeground);
lblLoses.setForeground(clrForeground);
lblDraws.setForeground(clrForeground);
txtWins.setForeground(clrForeground);
txtLoses.setForeground(clrForeground);
txtDraws.setForeground(clrForeground);
txtCPUWeapon.setForeground(clrForeground);
public void reset ()
cboxWeapon.setSelectedIndex(0);
lblStatus.setText("");
engine.reset();
public void actionPerformed (ActionEvent e)
if (e.getSource() == cmdReset)
reset();
else
lblStatus.setText(engine.play(cboxWeapon.getSelectedIndex()));
txtCPUWeapon.setText(engine.getStrCPUWeapon());
txtWins.setText(Integer.toString(engine.getWins()));
txtLoses.setText(Integer.toString(engine.getLoses()));
txtDraws.setText(Integer.toString(engine.getDraws()));
if (!errorWithImages)
lblCPUWeaponIcon.setIcon(imgWeapon[engine.getCPUWeapon()]);
public void itemStateChanged (ItemEvent e)
if (!errorWithImages)
lblPlayerWeaponIcon.setIcon(imgWeapon[cboxWeapon.getSelectedIndex()]);
}Here is the other .java file that calls on the Images:
import java.awt.*;
import java.io.*;
import javax.swing.ImageIcon;
public class objCreateAppletImage
public void objCreateAppletImage ()
//If an error occurs (or is thrown by me) it will be thrown to the next level up, and either caught or thrown
public ImageIcon getImageIcon (Object parentClass, String path, String description, int fileSize) throws Exception
int count = 0;
BufferedInputStream imgStream = new BufferedInputStream(parentClass.getClass().getResourceAsStream(path));
byte buff[] = new byte[fileSize];
if (imgStream == null) //If doesn't exist
throw new Exception("File not Found");
try
count = imgStream.read(buff);
imgStream.close(); //Closes the stream
catch (IOException ex)
throw new Exception("Corrupt file");
return new ImageIcon(Toolkit.getDefaultToolkit().createImage(buff), description); //Creates the image from the byte array
}Could someone please help me? I really have no idea and I would like this to work.
Thank you
FrankOh, thank you. I will not do that in the future.
I am not entirely sure how I would use the getImage method in an Applet. I would prefer to just use the code that I have currently, unless the addition of making the program an Applet only adds a small amount of code. But then even still, I am not entirely sure what I would write in the .class file to make the images load. And then I would not really know how to properly incorporate the pss.java file and the .class file together so they read off of each other. -
Need help with a rock paper scissors GUI
i dont know whats wrong, for some reason the String "human" or String "player" is not responding so i keep getting an error also if anyone can PLZ help me set color for the labels
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
import java.util.Random;
public class RPSPanel extends JPanel
private JLabel inputLabel, outputLabel, resultLabel, statementLabel, newlabel, titlelabel, copyrightlabel;
private JTextField player;
private JButton input;
public RPSPanel()
titlelabel = new JLabel ("**************************Rock Paper Scissors v1.52.22*************************");
inputLabel = new JLabel ("Enter Rock Paper or Scissors :");
outputLabel = new JLabel ("Computers Choice: ");
player = new JTextField (9);
resultLabel = new JLabel ("-----------");
statementLabel = new JLabel("---------------------------------------------------------------------");
newlabel = new JLabel("*******************************************************************************");
copyrightlabel = new JLabel("copyright 2007. msg inc");
input = new JButton ("PLAY!");
input.addActionListener (new playerlistener());
add (titlelabel);
add (inputLabel);
add (player);
add (outputLabel);
add (resultLabel);
add (statementLabel);
add (input);
add (newlabel);
add (copyrightlabel);
setPreferredSize (new Dimension(300, 175));
setBackground (Color.black);
private class playerlistener implements ActionListener
public void actionPerformed (ActionEvent event)
Random generator = new Random();
int lol;
String human = player.getText();
String comp = "";
String result = "";
lol = generator.nextInt(3) + 1;
switch (lol)
case 1:
comp = "rock";
break;
case 2:
comp = "paper";
break;
case 3:
comp = "scissors";
break;
if(comp.equals(human))
statementLabel.setText("---------------------------tie. try again-------------------------------------");
if(human.equals("rock") && comp.equals("paper"))
statementLabel.setText("------------------------paper beats rock. YOU SUCK!-------------------------");
if(human.equals("rock") && comp.equals("scissors"))
statementLabel.setText("--------------------------rock beats scissors. is very nice---------------------------");
if(human.equals("paper") && comp.equals("rock"))
statementLabel.setText("--------------------------paper beats rock. you win--------------------------");
if(human.equals("paper") && comp.equals("scissors"))
statementLabel.setText("---------------------scissors beats paper. you n00b-----------------------");
if(human.equals("scissors") && comp.equals("rock"));
statementLabel.setText("----------------------rock beats scissors. owned----------------------------");
if(human.equals("scissors") && comp.equals("paper"))
statementLabel.setText("----------------------scissors beats paper. you win-----------------------");
else
statementLabel.setText("---------------------------------error----------------------------------");
resultLabel.setText(comp);
}Message was edited by:
msg256import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
import java.util.Random;
public class RPS extends JPanel
private JLabel inputLabel, outputLabel, resultLabel,
statementLabel, newlabel, titlelabel, copyrightlabel;
private JTextField player;
private JButton input;
public RPS()
titlelabel = getLabel ("**************************Rock Paper Scissors v1.52.22*************************");
inputLabel = getLabel ("Enter Rock Paper or Scissors :");
outputLabel = getLabel ("Computers Choice: ");
player = new JTextField (9);
resultLabel = getLabel ("-----------");
statementLabel = getLabel("---------------------------------------------------------------------");
newlabel = getLabel("*******************************************************************************");
copyrightlabel = getLabel("copyright 2007. msg inc");
input = new JButton ("PLAY!");
input.addActionListener (new PlayerListener());
add (titlelabel);
add (inputLabel);
add (player);
add (outputLabel);
add (resultLabel);
add (statementLabel);
add (input);
add (newlabel);
add (copyrightlabel);
setPreferredSize (new Dimension(300, 175));
setBackground (Color.black);
private JLabel getLabel(String s)
JLabel label = new JLabel(s);
label.setForeground(Color.red);
return label;
private class PlayerListener implements ActionListener
Random generator = new Random();
public void actionPerformed (ActionEvent event)
String human = player.getText().toLowerCase();
String comp = "";
String dash = "---------------";
int lol = generator.nextInt(3) + 1;
switch (lol)
case 1:
comp = "rock";
break;
case 2:
comp = "paper";
break;
case 3:
comp = "scissors";
break;
if(comp.equals(human))
statementLabel.setText(dash + "tie. try again" + dash);
else if(human.equals("rock") && comp.equals("paper"))
statementLabel.setText(dash + "paper beats rock. YOU SUCK!" + dash);
else if(human.equals("rock") && comp.equals("scissors"))
statementLabel.setText(dash + "rock beats scissors. is very nice" + dash);
else if(human.equals("paper") && comp.equals("rock"))
statementLabel.setText(dash + "paper beats rock. you win" + dash);
else if(human.equals("paper") && comp.equals("scissors"))
statementLabel.setText(dash + "scissors beats paper. you n00b" + dash);
else if(human.equals("scissors") && comp.equals("rock")) // << ";" !
statementLabel.setText(dash + "rock beats scissors. owned" + dash);
else if(human.equals("scissors") && comp.equals("paper"))
statementLabel.setText(dash + "scissors beats paper. you win" + dash);
else
statementLabel.setText(dash + "error" + dash);
resultLabel.setText(comp);
public static void main(String[] args)
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new RPS());
f.pack();
f.setVisible(true);
} -
Rock, Paper, Scissors query?
Hi there, I have a "limiting" question I'm hoping someone can help me out with.
I work for a hospital on the employee's database. I'm trying to update a column in the employee demographic table called "workgroup". It's never been used before so currently the column sits empty.
I need to place one of 3 different codes in that column based on the level of patient contact the employee has. D = Direct contact, I = Indirect contact and N = No contact.
I will need to base this off of another table called Exposures. It's a table that tracks the level of exposure the employee is subjected to. So ER nurses would be Level 1, but the cleaning crew are Level 3.
Here's my problem, unfortunately due to poor past practices, many people are in more than one Level. For example, most nurses are in both Level 1 and Level 2. The reason for this... I have no idea.
So my question is, how if say Sara Johnson was in Level 1 and Level 2, would I place a "D" in her workgroup column and that's it. I've built a script with a CASE statement but that doesn't give me what I want. I gives her both a "D" and an "I". But the "D" is more important - it trumps the "I". Get it? Basically it's like rock paper scissors.MIN worked great!! Thanks a lot!! I think this just saved us a lot of manual excel work.
Here's the script: (sorry about the formatting)
SELECT E.ID, E.LNAME, E.FNAME, NVL(E.MI,' ') MI, E.BDATE,
MIN(B.CODE) CODE, MIN(B.WKGP) WKGP,
L.DESCR
FROM EMPLOYEE E, LOC L, (SELECT EMPLOYEE EE, EXPOSURE CODE,
CASE WHEN EXPOSURE = 'Level 1' THEN 'D'
WHEN FLDEXPOSURE = 'Level 2' THEN 'I'
WHEN FLDEXPOSURE = 'Level 3' THEN 'N'
ELSE ' '
END WKGP
FROM EXPHIST
WHERE FLDEXPOSURE IN ('Level 1','Level 2','Level 3')) B
WHERE E.LOC = L.CODE AND
L.CODE = 'South' AND
E.STATUS IN (SELECT CODE
FROM EMPSTATS
WHERE ACTIVE <> 'n') AND
E.REC_NUM = B.EE
GROUP BY E.ID, E.LNAME, E.FNAME, E.MI, E.BDATE,
L.DESCR
ORDER BY E.LNAME, E.FNAME -
Please help with structure of my program
I am hoping someone can help me with a motor control program that I am
writing. The program is too large to post here, but I attached a
rough outline of the program. I think the problem is with the
higher level logic, so hopefully that will provide the necessary
information.
I have a front panel with lots of buttons to control the motors (eg:
power, stop, start). There is an event structure that contains
most of those buttons (power, start, etc), but if that structure is
exectuting, the other buttons won't work. I need to be able to
stop the motors and exit at any time (for safety), so I made another
event structure that contains the stop and exit buttons. Is this
the right way to do this?
Also, I want all the loops in the program to run continually until the
exit button is pressed. Since the exit button actually calls
exit.vi and closes the whole program, I just wired a F constant to the
stop on the while loops so they never stop. Could this be causing
my problems?
Hopefully I provided enough information here, but if not, please write back and let me know.
Thanks,
Kasey
PS. In case anyone wonders why the whole thing is in a sequence, I need
it for other aspects of the program (safety lights, etc...). I
doubt it makes a difference, but I wanted to include it.
Attachments:
screenshot.jpg 258 KBThis is the first time I have seen a case where it is useful to have two or more event structures in one program. Since they are in separate parallel loops, I would think there would not be a problem. I like the idea that the program can be stopped in the middle of an event, for safety reasons. Great structure, Kasey. The only thing I would add is to make sure that your exit vi gracefully shuts down the program. Like if files or references are open, they get closed before terminating the vi. Just be on the look out for race conditions since you have 3 events that can happen at one time. One event might affect some indicator that is being handled by another event. Also, instead of wiring a false to the other loops, maybe you could use local variables of one general stop boolean. Since your exit vi stops all execution, it may not make much of a difference.
- tbob
Inventor of the WORM Global -
Help with a Word Counting Program..
I need some help with a program I am trying to write
The program is being written in BlueJ.
Im just starting the program and am completely confused on how I should write this...
But here is what I have to do..
I have to use a scanner to scan a Text file and count the # of Words the number of Vowels (including Y when it is) and the # of Palindromes (Word spelled same forward and Back) as well as which Palindromes are being used.
It would be good to have a class to clean the text and a seperate class for the tasks...
I do not want to use anything other than "If" statements and while loops (no "for" loops) and only use Printwriter as the output file writer.
Thnx to anyone in advanceI have a basic Vowel coding that doeswnt work...
public class vowel{
String word = "heyyou";
String vowels = "aeiouy";
int[] countv = new int[vowels.length()];
int countv2;
int i=0;
if(i<word.length();) { i++ {
if (int j=0 && j<vowels.length()) {
return j++;
if (word.charAt(i)==vowels.charAt(j)) {
countV[j]++; countV2++;
for (int i=0; i<vowels.length(); i++) {
System.out.println("Vowel "vowels.charAt(i)" = "+vcnt);
System.out.println("Consonants = "+(word.length()-vtot)); }
I also have a basic Palindrome code that works as a boolean but I need to make it return what the palindromes are and how many of them are there. I wanna know how I would do this.
public class Palindrome{
public static boolean isPalindrome(String word) {
int left = 0;
int right = word.length() -1;
while (left < right) {
if (word.charAt(left) != word.charAt(right)) {
return false;
left++;
right--;
return true;
I would also like to know how to actually start writing the word counter. -
Help with 7 segment led program
hey, I need some help with my program. The program is supposed to make digital numbers display randomly with a possible decimal point in it. If the decimal # has a leading zero, then the zero needs to be not displayed. also, when you click the change color button, the numbers and decimal point are supposed to change to one of three preset colors. I've got the numbers changing colors, but I can't get the decimal point to change color, nor can I get the numbers to change randomly.
package led7segment;
import java.awt.event.*;
import javax.swing.*;
* Robert Lundahl
* cs1410-002
* @author Matthew Lohmeyer
public class Main {
* @param args the command line arguments
public static void main(String[] args) throws InterruptedException {
// TODO code application logic here
JFrame.setDefaultLookAndFeelDecorated(true);
MyJFrame mjf = new MyJFrame();
while (true) {
int deci = (int)(Math.random() * 3);
int num = (int)(Math.random() * 1000);
Digit.DisplayNumber(num, deci);
Thread.sleep(4000);
package led7segment;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
* Robert Lundahl
* cs1410-002
* @author Matthew Lohmeyer
public class MyJFrame extends JFrame implements ActionListener{
private JButton jb1, jb2, jb3;
Digit d1, d2, d3;
Oval deci;
Color c;
Oval o1, o2, o3;
public MyJFrame()
super("LED Display");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(50, 50, 500, 320);
setVisible(true);
setLayout(null);
// jb1 = new JButton("Down");
// jb1.setBounds(10,225, 75, 50);
// add(jb1);
// jb1.addActionListener(this);
jb2 = new JButton("Change Color");
jb2.setBounds(10,225, 200, 50);
add(jb2);
jb2.addActionListener(this);
jb3 = new JButton("Exit");
jb3.setBounds(250,225, 100, 50);
add(jb3);
jb3.addActionListener(this);
d1 =new Digit(7);
add(d1);
d1.setBounds(10,10,120,190);
d1.setVisible(true);
d2 =new Digit(7);
d2.setBounds(150,10,120,190);
add(d2);
d2.setVisible(true);
d3 =new Digit(7);
d3.setBounds(300,10,120,190);
add(d3);
d3.setVisible(true);
o1 = new Oval(125, 160, 15, 15);
o1.setVisible(true);
add(o1, 0);
o2 = new Oval(275, 160, 15, 15);
o2.setVisible(true);
add(o2, 0);
o3 = new Oval(425, 160, 15, 15);
o3.setVisible(true);
add(o3, 0);
repaint();
public void actionPerformed(ActionEvent e) {
Object j = e.getSource();
// if(j==jb1)
// d1.incDown();
// d2.incDown();
// d3.incDown();
if(j==jb2)
d1.changeColor();
d2.changeColor();
d3.changeColor();
o1.changeColor();
else if(j==jb3)
d1.incUp();
d2.incUp();
d3.incUp();
package led7segment;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
* Robert Lundahl
* cs1410-002
* @author Matthew Lohmeyer
public class Digit extends JComponent{
Rectangle rect[] = new Rectangle[7];
Oval o1[] = new Oval[7];
private boolean decimal;
private Color mycolor[] = new Color[]{Color.RED, Color.GREEN, Color.BLUE};
private int cindex = 0;
private int increment =8;
private Rectangle topRectangle = new Rectangle(23, 10, 66, 20);
private Rectangle leftTopRectangle = new Rectangle(0, 13, 20, 76);
private Rectangle leftBottomRectangle = new Rectangle(0, 92, 20, 76);
private Rectangle bottomRectangle = new Rectangle(23, 151, 66, 20);
private Rectangle rightBottomRectangle = new Rectangle(92, 92, 20, 76);
private Rectangle rightTopRectangle = new Rectangle(92, 13, 20, 76);
private Rectangle midRectangle = new Rectangle(23, 82, 66, 20);
public Digit(int n)
super();
rect[0] = topRectangle;
rect[1] = leftTopRectangle;
rect[2] = midRectangle;
rect[3] = leftBottomRectangle;
rect[4] = bottomRectangle;
rect[5] = rightTopRectangle;
rect[6] = rightBottomRectangle;
for (int i = 0; i<7; i++)
add(rect);
setVisible(true);
public void HideDigit(){
for (int i = 0; i<7; i++)
rect[i].setVisible(false);
void changeColor() {
if(cindex==3)
cindex=0;
for (int i = 0; i < rect.length; i++) {
rect[i].setBackground(mycolor[cindex]);
//o1[i].setBackground(mycolor[cindex]);
cindex++;
void DisplayNumber(int n, int decimals)
n=increment;
switch(increment)
case 0:
displayzero();
break;
case 1:
displayone();
break;
case 2:
displaytwo();
break;
case 3:
displaythree();
break;
case 4:
displayfour();
break;
case 5:
displayfive();
break;
case 6:
displaysix();
break;
case 7:
displayseven();
break;
case 8:
displayeight();
break;
case 9:
displaynine();
break;
public void SetDecimal(boolean flag)
decimal = flag;
o1.setVisible(decimal);
// void incDown() {
// if(increment==0)
// increment=10;
// increment--;
// switch(increment)
// case 0:
// displayzero();
// break;
// case 1:
// displayone();
// break;
// case 2:
// displaytwo();
// break;
// case 3:
// displaythree();
// break;
// case 4:
// displayfour();
// break;
// case 5:
// displayfive();
// break;
// case 6:
// displaysix();
// break;
// case 7:
// displayseven();
// break;
// case 8:
// displayeight();
// break;
// case 9:
// displaynine();
// break;
void incUp() {
System.exit(WIDTH);
// if(increment==9)
// increment=-1;
// increment++;
// switch(increment)
// case 0:
// displayzero();
// break;
// case 1:
// displayone();
// break;
// case 2:
// displaytwo();
// break;
// case 3:
// displaythree();
// break;
// case 4:
// displayfour();
// break;
// case 5:
// displayfive();
// break;
// case 6:
// displaysix();
// break;
// case 7:
// displayseven();
// break;
// case 8:
// displayeight();
// break;
// case 9:
// displaynine();
// break;
void displayzero()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(false);
leftBottomRectangle.setVisible(true);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displayone()
topRectangle.setVisible(false);
leftTopRectangle.setVisible(false);
midRectangle.setVisible(false);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(false);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displaytwo()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(false);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(true);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(false);
void displaythree()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(false);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displayfour()
topRectangle.setVisible(false);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(false);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displayfive()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(false);
rightBottomRectangle.setVisible(true);
void displaysix()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(true);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(false);
rightBottomRectangle.setVisible(true);
void displayseven()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(false);
midRectangle.setVisible(false);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(false);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displayeight()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(true);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
void displaynine()
topRectangle.setVisible(true);
leftTopRectangle.setVisible(true);
midRectangle.setVisible(true);
leftBottomRectangle.setVisible(false);
bottomRectangle.setVisible(true);
rightTopRectangle.setVisible(true);
rightBottomRectangle.setVisible(true);
package led7segment;
import javax.swing.*;
import java.awt.*;
/** Oval Supplier Class
* Robert Lundahl
* cs1410-002
* @author Matthew Lohmeyer
public class Oval extends JComponent {
private Color mycolor[] = new Color[]{Color.RED, Color.GREEN, Color.BLUE};
private int cindex = 0;
Oval o1[] = new Oval[0];
/** post: getX() == x and getY() == y
* and getWidth() == w and getHeight() == h
* and getBackground() == Color.black
public Oval(int x, int y, int w, int h) {
super();
setBounds(x, y, w, h);
setBackground(Color.black);
/** post: this method draws a filled Oval
* and the upper left corner of the bounding rectangle is (getX(), getY())
* and the oval's dimensions are getWidth() and getHeight()
* and the oval's color is getBackground()
@Override
public void paint(Graphics g) {
g.setColor( getBackground() );
g.fillOval(0, 0, getWidth()-1, getHeight()-1);
paintChildren(g);
void changeColor() {
if(cindex==3)
cindex=0;
for (int i = 0; i < o1.length; i++) {
//rect[i].setBackground(mycolor[cindex]);
o1[i].setBackground(mycolor[cindex]);
cindex++;
package led7segment;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.*;
* Robert Lundahl
* cs1410-002
* @author Matthew Lohmeyer
public class Rectangle extends JComponent
public Rectangle(int x, int y, int w, int h) {
super();
setBounds(x, y, w, h);
setBackground(Color.black);
@Override
public void paint(Graphics g) {
g.setColor( getBackground() );
g.fillRect(0, 0, getWidth()-1, getHeight()-1);
paintChildren(g);
Edited by: matttheskibum7 on Feb 9, 2008 8:22 PM
Edited by: matttheskibum7 on Feb 9, 2008 8:27 PMYour code does not compile.
EDIT:
for instance your Main class alone has a several glaring problems that suggest that you are foundering here. Please see comments in code below:
public class Main {
public static void main(String[] args) throws InterruptedException {
JFrame.setDefaultLookAndFeelDecorated(true);
MyJFrame mjf = new MyJFrame();
// why use "while (true)"??? Swing is supposed to be event driven and doesn't need loops like this.
// do you need to use a Swing Timer instead?
while (true) {
int deci = (int)(Math.random() * 3);
int num = (int)(Math.random() * 1000);
// why is the method below being called as if it were a
// static method when it's not? This is not a legal
// expression
Digit.DisplayNumber(num, deci);
// why is the method below putting the event dispatch thread
// (the EDT) to sleep. While this is legal, it's not a smart
// thing to do
Thread.sleep(4000);
}Edited by: Encephalopathic on Feb 9, 2008 10:15 PM -
Help with implementing two different programs
I need help with a couple of Java programs that I downloaded. I hope someone can help me. They work great if they're on their own, but if they are both on the same page, the 2nd one works, and the 1st one stops working. I'm pretty new to Java, so I don't know how to debug it too well.. Here's the 1st program:
Conveyor belt slideshow script-
? Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and Terms Of Use, visit dynamicdrive.com
//Specify the slider's width (in pixels)
var sliderwidth="250px"
//Specify the slider's height
var sliderheight="19px"
//Specify the slider's slide speed (larger is faster 1-10)
var slidespeed=2
//configure background color:
slidebgcolor=""
//Specify the slider's images
var leftrightslide=new Array()
var finalslide=''
leftrightslide[0]='<img src="images/movingwords.gif">'
////NO NEED TO EDIT BELOW THIS LINE////////////
var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(" ")+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
//Next line edited for readability
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">
'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide
function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+20+"px"
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slidemenu2
ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+20
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
lefttime=setInterval("slideleft()",30)
window.onload=fillup
function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+30+"px"
if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+30+"px"
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+30
if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+30
if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden">')
//Next line edited for readability
write('<div style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';
background-color:'+slidebgcolor+'" onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3" style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
else if (document.layers){
write('<ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'>')
write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('</ilayer>')
document.write('</td></table>')
}Here's the 2nd program:
//Fade-in image slideshow- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var slideshow_width='305px' //SET IMAGE WIDTH
var slideshow_height='152px' //SET IMAGE HEIGHT
var pause=5000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]="images/Computer Retail Store.jpg"
fadeimages[1]="images/Computer S&S ad.jpg"
fadeimages[2]="images/Computer S&S ad 2.jpg"
fadeimages[3]="images/Phone S&S ad.jpg"
////NO need to edit beyond here/////////////
var preloadedimages=new Array()
for (p=0;p<fadeimages.length;p++){
preloadedimages[p]=new Image()
preloadedimages[p].src=fadeimages[p]
var ie4=document.all
var dom=document.getElementById
if (ie4||dom)
//Next line edited for readability
document.write('<div style="position:relative;width:'+slideshow_width+';height:'+slideshow_height+';overflow:hidden">
<div id="canvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:
alpha(opacity=10);-moz-opacity:10"></div><div id="canvas1" style="position:absolute;width:'+slideshow_width+';
height:'+slideshow_height+';top:0;left:0;filter:
alpha(opacity=10);-moz-opacity:10"></div></div>')
else
document.write('<img name="defaultslide" src="'+fadeimages[0]+'">')
var curpos=10
var degree=10
var curcanvas="canvas0"
var curimageindex=0
var nextimageindex=1
function fadepic(){
if (curpos<100){
curpos+=10
if (tempobj.filters)
tempobj.filters.alpha.opacity=curpos
else if (tempobj.style.MozOpacity)
tempobj.style.MozOpacity=curpos/100
else{
clearInterval(dropslide)
nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1"
tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">'
nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0
setTimeout("rotateimage()",pause)
function rotateimage(){
if (ie4||dom){
resetit(curcanvas)
var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.style.zIndex++
var temp='setInterval("fadepic()",50)'
dropslide=eval(temp)
curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0"
else
document.images.defaultslide.src=fadeimages[curimageindex]
curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0
function resetit(what){
curpos=10
var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
if (crossobj.filters)
crossobj.filters.alpha.opacity=curpos
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=curpos/100
function startit(){
var crossobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">'
rotateimage()
if (ie4||dom)
window.onload=startit
else
setInterval("rotateimage()",pause)Like I said, if the 2nd program is put the same page with the 1st, the 1st program stops working. Any ideas? I would really like to implement both of these programs.The code you post is javascript, NOT java ! ... but either way, maybe the scripts have variables in conflict, so if you pack each piece of code in diferent functions and then you call the functions it may work.
-
Help with GMAIL in Mail Program....
Hi,
I am using the Apple Mail Program in Leopard and just picked up a Gmail account. I want to set up my Gmail account on 4 different computers work/home/laptop) that I access all the time and am hoping I can set it up so that wherever I check my mail it looks more or less like it does on Gmail.com with respect to the emails:
1. All mail that I've deleted on another computer is gone from all the other computers when checking mail on those other computers. Is that possible??? Currently, I use a bellsouth.net account and a .mac account, and when I log on to any of the computers via the mail program, it gives me all of my 'new mail', whether or not it was deleted on another computer.
2. Sent mail. Is there any way to send it on one computer's Mail program and have it show up in my Sent box on the other computers?
3. Ditto on Trash and other folders
I did try to set it up my Gmail account using IMAP but I thendeleted the account on Mail because it looked 'weird'. I had a Mailbox in my Inbox for the Gmail account and then also another whole separate, duplicate Gmail account (with All Mail, Drafts, Sent Mail, Spam, Starred, and Trash Folders) further down the left side of mail. In testing an email to gmail account from my .mac account, the mail ended up in two places in my Mail and deleting one did not delete the others.
If this cannot work, I can just go to gmail.com. BUT, I so love MAIL that I am hoping there is a fix to all this.
Thanks in advance for any help you can provide.My recollection is that unless you are a paid Hotmail account member, you cannot use Mail. Do a search within the discussion group, as I am not an expert, but I recall not getting Hotmail for that very reason.
Perhaps give gmail a try.....
That said....I still need some help with my posting! So please and thank you. -
I need help with the Bon Scott program
Help me! I am learning Java from the book, "Teach Yourself Java through Osmosis" and I am having trouble with the Bon Scott program. Everytime I run it, which has been ca. 2 billion, it prints out, "Some balls are held for charity and some for fancy dress, but when they're held for pleasure, they're the balls that I like the best." It then proceeds to get pissed and finally vomits.
Any suggestions ?What color is the vomit? That is, exactly what does it do when it gets pissed and vomits?
-
I have a problem with a grey text box. It writes and says all i do. For example: When i now write it says all the letters one for one. If i open a new rogram it says so. If i click on something it gives me information about it. I can click the box and drag it, but dont close it. I have restarted the computer and closing all windows and programs. It just popped out when i was pressing some buttons on the mac. I think it is a easy way to fix it, but i cant find out what it is named and search for it. I think it is made for help and i did not download anything to get it. If i change user on the mac it does go away when I am on the other user, but i really want to keep the one i have because off all the settings and programs i have.
Please reply if you know anything about this.
This is a printscreen of the box, the language is Norwegian if someone wonder...
It is really annoying, I hope someone can help me out.Oh thanks alot! Really happy that people take the time to answer my `noob`questions! Would not find that out by my own.
Thanks! -
Need help with running a Java program on Linux
I am trying to get a Java program to run on a Linux machine. The program is actually meant for a Mac computer. I want to see if someone with Java experience can help me determine what is causing the program to stall. I was successful in getting it installed on my Linux machine and to partially run.
The program is an interface to a database. I get the login screen to appear, but then once I enter my information and hit enter the rest of the program never shows, however, it does appear to connect in the background.
Here is the error when I launch the .jar file from the command screen:
Exception in thread "main" java.lang.IllegalArgumentException: illegal component position
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
I am not a programmer and I am hoping this will make some sense to someone. Any help in resolving this is greatly appreciated!Well, without knowing a little bit about programming, and how to run your debugger, I don't think you're going to fix it. The IllegalArgumentException is saying that some call does not like what it's getting. So you'll have to go in an refactor at least that part of the code.
-
Need urgent help with a new Z program please
I have to write a program that finds files matching some pattern, for example I have files test1,test2,test3 in a directory then if I pass test* as parameter it should find all the files i.e, test1,2,3. I have to then store the files in internal table, loop through it and have to call some other program zzz that has a selection screen with default parameters.
1) Is there any function that I can call that gives all the files by passing wild card (ex:test*) and store the files in internal table?
2) How do I call some other program ZZZ from my program?
3) How do I pass values from my program to other program's selection screen?
Your help would be greatly appreciated.
Thanks.
MithunHi,
1) data: FILE_TABLE TYPE STANDARD TABLE OF FILE_INFO.
data: wa_file type file_info.
data: count type i.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = 'C:\'
FILTER = 'test.*'
files_only = 'X'
changing
FILE_TABLE = file_table[]
count = count.
loop at file_table into wa_file.
write: / wa_file-filename.
endloop.
2) You can use SUBMIT statement to call another program..
3) In the SUBMIT statement you can use the WITH addition to pass the values to the program.
Thanks,
Naren -
Need help with a cash register program.
I'm a noob at JAVA, but having fun with i so far! I was wondering if anyone could help me with a school project I need to get done. I've done most of the work, but I can't get it to not display when I have zero results. What I mean is that the project requires you to create a cash register program that gives you change in 20's, 5's, and 1's for a hundred dollar bill. I get it to display the results, but if there are zero of any category, like in the last problem, I can't let it show. Could someone please help! Thank you in advance! Here's what I have so far (sorry about the rapidshare download ^_^;).
[http://rapidshare.de/files/39978938/project.java.html]Zack,
The user should not see the line: 0 $5 bill(s)Then you need to detect the situation where no five dollars bills are included in the change, and suppress the output of that line.
I can read your mind... it's going something like "yeah well righto smartass, I knew that allready... my question was _HOW_ to make that happen...
And my answer to that is "I'm not telling you"... well, not straight out anyway, coz you'll actually learn more if your struggle a bit (but not too much) yourself...
So... I suggest you (at least) read through [this page|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html] on the +if+ statement, and maybe even try out the examples, which should (I imagine) take maybe half an hour or so. "Selection" is an absolutely core programming construct... and the concept is common to every programming language ever (AFAIK) invented... meaning that you will really struggle until you "get" the +if+ statement... so that half hour would be time well spent.
When you've got +if+ concept onboard, you can attempt to apply it to your immediate problem, suppressing those annoying fivers! Have a go yourself, if get really stumped than post a _specific_ question here about the bit that's stumped you.
I know it can be frustrating... but that just hightens the little thrill you get when you "get it".
Cheers. Keith.
Maybe you are looking for
-
"Error compiling movie. Unknown error" while rendering a .PSD or .PNG
Hi, I have this problem: When I try to make a "Render Selection" or export my video, everything is ok until I reach a .PSD file I've placed almost in the end of the clip. The same is for .PNG file, a dialog appears saying "Error compiling movie. Unkn
-
Error in CHECK_REQUIREMENTS phase (Open ABAP Dictionary Conversions)
Hi Gurus, When were are trying to update SPAM/SAINT to version 7.00/0033 from 7.00/0029 we're encountering 'Open Conversions in the ABAP Dictionary' in CHECK_REQUIREMENTS phase, refraining to proceed further. It was due to 2 indexes in a table. Whe
-
10.8.4 MacBook Pro Retina 15" won't complete installation
Hello I've tried repeatedly to install 10.8.4 from 10.8.3 normally these updates have been error free and straight forward, however this time the restart begins and it will say wait for about 5-6 mins and then an error message consistently says "an u
-
Can the "Finder" icon be set to always open a new window?
Can the "Finder" icon (on the dock) be set to simply open a new window every time when clicked? Instead of always selecting the dialog "new finder window" under "File" ? Or having to right clicking on the FINDER dock icon, then selecting "new finder
-
HT1338 where is the location of the mavericks download?
i've already downloaded the mavericks osx file. I was having trouble finding my password. i found it but cant find my download. how can i find the downloaded osx file?