Problem with this program

I see this board is very young. Well I'm a high school freshman in a java programming class and i have a little problem with my homework.
My source code is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class DogsHumanAge extends JApplet
implements ActionListener
JTextField inputHumanyears, displayDogyears;
public void init()
JLabel labelHumanyears = new JLabel("Enter the dog's age in human years:",
SwingConstants.RIGHT);
inputHumanyears = new JTextField(5);
JLabel labelDogyears = new JLabel("Dogyears = ", SwingConstants.RIGHT);
displayDogyears = new JTextField(5);
displayDogyears.setEditable(false);
JButton go = new JButton("Compute age");
go.addActionListener(this);
Container c = getContentPane();
c.setBackground(Color.white);
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2, 5, 5));
p.add(labelHumanyears);
p.add(inputHumanyears);
p.add(labelDogyears);
p.add(displayDogyears);
c.add(p, BorderLayout.CENTER);
c.add(go, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e)
int Humanyears = Integer.parseInt(inputHumanyears.getText());
double Dogyears = calculateDogyears(Humanyears);
DecimalFormat df = new DecimalFormat("00.0");
displayDogyears.setText(df.format(Dogyears));
private double calculateDogyears(int Humanyears, int Dogyears)
return 13 + (int)(16.0 / 3.0 * (Dogyears - 1));
The error message i get is:
DogsHumanAge.java:42: calculateDogyears(int, int) cannot be applied to (int)
double Dogyears = calulateDogyears(Humanyears);
The intent of this program is to calculate the number of dog years from the given human years that is inputted into the input box.

Ok I got the solution. A friend helped me out. I had to make a few minor changes. Now the program looks like:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class DogsHumanAge extends JApplet
implements ActionListener
JTextField inputDogYears, displayHumanYears;
public void init()
JLabel labelDogYears = new JLabel("Enter the dog's age in dog years:",
SwingConstants.RIGHT);
inputDogYears = new JTextField(5);
JLabel labelHumanYears = new JLabel("Human years = ", SwingConstants.RIGHT);
displayHumanYears = new JTextField(5);
displayHumanYears.setEditable(false);
JButton go = new JButton("Compute age");
go.addActionListener(this);
Container c = getContentPane();
c.setBackground(Color.white);
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2, 5, 5));
p.add(labelDogYears);
p.add(inputDogYears);
p.add(labelHumanYears);
p.add(displayHumanYears);
c.add(p, BorderLayout.CENTER);
c.add(go, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e)
int dogYears = Integer.parseInt(inputDogYears.getText());
double humanYears = calculateHumanYears(dogYears);
DecimalFormat df = new DecimalFormat("00.0");
displayHumanYears.setText(df.format(humanYears));
private double calculateHumanYears(int dogYears)
return 13 + (int)(16.0 / 3.0 * (dogYears - 1));
Thanks to all that helped me!

Similar Messages

  • Problems with this program...

    Hello, i'm trying to write this program that will display a matrix of [] and be able to move a character around using the arrow buttons. Here is an example,
    I want to be able to move the char around the world. Here is what i have done so far. I know it is sloppy but i would greatly appreciate any help.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.awt.event.*;
    public class World1 implements KeyListener{
    public static Vector rooms;
    public static int location = 234;
         World1(){
         Vector temp = new Vector(468);
         rooms = temp;
              for(int i = 0; i < 468; i++){
              Room tempRoom = new Room();
              rooms.add(i, tempRoom);
         public void keyPressed(KeyEvent event) {
         int keyCode = event.getKeyCode();
         if(keyCode == KeyEvent.VK_LEFT){
         Room temp = new Room((char)2);
         rooms.insertElementAt(temp, location-1);
         Room del = new Room();
         rooms.insertElementAt(del, location);
         location--;
         if(keyCode == KeyEvent.VK_RIGHT){
         Room temp = new Room((char)2);
         rooms.insertElementAt(temp, location+1);
         Room del = new Room();
         rooms.insertElementAt(del, location);
         location++;
         if(keyCode == KeyEvent.VK_UP){
         Room temp = new Room((char)2);
         rooms.insertElementAt(temp, location+18);
         Room del = new Room();
         rooms.insertElementAt(del, location);
         location = location +18;
         if(keyCode == KeyEvent.VK_DOWN){
         Room temp = new Room((char)2);
         rooms.insertElementAt(temp, location-18);
         Room del = new Room();
         rooms.insertElementAt(del, location);
         location = location - 18;
    public void keyReleased(KeyEvent event) {}
    public void keyTyped(KeyEvent event) {}
         public static void main(String[] args){
                   World1 yu = new World1();
                   Room smile = new Room((char)2);
                   rooms.insertElementAt(smile,location);
              DrawFrame frame = new DrawFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.show();
    class Room{
    char content;
    public boolean isThisEmpty;
    public boolean isEmpty(){
         if(isThisEmpty == true)return true;
         return false;
    Room(){
    isThisEmpty = true;
    Room(char c){
    content = c;
    public String printRoom(){
         if(isEmpty() == true)return " ";
         return (content+"");
    class DrawFrame extends JFrame
         public DrawFrame(){
              setTitle("Welcome to Montreax");
              setSize(WIDTH, HEIGHT);
              DrawPanel panel = new DrawPanel();
              Container contentPane = getContentPane();
              contentPane.add(panel);
         public static final int WIDTH = 400;
         public static final int HEIGHT = 400;
    class DrawPanel extends JPanel {
         public void paintComponent(Graphics g){
         super.paintComponent(g);
         addKeyListener(new World1());
         int counter = 0;
         for(int x = 1; x <=26; x++){  //-->This part is icky...i want to display the matrix
         for(int i = 1; i <= 18; i++){ //but i don't know how with the frame
         Room temp = (Room)rooms.get(counter);
         g.drawString("[",i,x);
         g.drawString(temp.printRoom(),i,x);
         g.drawString("]",i,x);
         if(i==18)g.drawString("",i,x);
         counter++;
    }

    I'd suggest using images. So have, say, a collection of 32x32 images, meant to be tilable, each showing a different state for that square in the map. Then display those, rather than drawing text. This seems to be the standard way of doing things like that.
    Where you're currently writing "[ ]", draw a box image. Where you're currently writing "[*]", draw a box image with a glyph indicating the player (or whatever the "*" is).
    BTW, you may not want to give up on ASCII art yet. Perhaps you could use a curses library for java. Or read unbuffered input and output and throw your own key events (or actually just invoke methods that key events would also call in a GUI environment). Or maybe somebody has done AWT- or Swing-for-text. Try Google.

  • Anyone spot the problem with this program???

    Everytime I compile part of my program it keeps on saying....
    "missing return statement
    ^
    1 error"
    can anyone spot it on my program???
    //GAME
    public class Game2 extends MyPrint
         GameInterface gameInt;
         String s = "?123456789";
         Player player1;
         Player player2;
         public Game2() // Constructor
         public int makeMove()
              gameInt = new GameInterface ();
              player1 = new Player ();
              player2 = new Player ();
              myPrintln("Enter name of player");
              String FP = c.input.readString();
              myPrintln(FP, SYSTEM);
              myPrintln("Enter name of other player");
              String SP = c.input.readString();
              myPrintln(SP, SYSTEM);
              gameInt.pictureBoard(s);
              myPrintln("");
              //boolean whoWon=false;
              int loop = 0;
              while(loop<=6)
                   player1.setName(FP);
                   myPrintln(player1.getName() + " (X) to play");
                   char name1 = c.input.readChar();
                   name1 = c.input.readChar();
                   boolean playTurn = true;
                   gameInt.play(name1, true);
                   gameInt.pictureBoard(gameInt.display());
                   myPrintln("");
                   player2.setName(SP);
                   myPrintln(player2.getName() + " (O) to play");
                   char name2 = c.input.readChar();
                   name2 = c.input.readChar();
                   playTurn = false;
                   gameInt.play(name2, false);
                   gameInt.pictureBoard(gameInt.display());
                   myPrintln("");
                   loop++;
    cheers
    Dave

    Change public int makeMove() into: public void makeMove()
    and the compiler will keep quiet (or finds more things to complain about)

  • When attempt to download 10.5, receive message: "...problem with this widows installer package. a program run as part of the set up did not finish as expected. ..." -- what to do?

    I have attempted to upgrade my iPad which is necessar to downloan an app I want (My Radar).  The iTunes on my computer will not process the upgrade of 10.5 without message:  "There is a problem with this Windows Installer Package. A program run as part of the set up did not finish as expected. Contract your support personnel or packae vendor."  ..... Little old lady needs help, my iTunes "appears to be 10.5 on my PC; however, will not upgrade my iPad.  I have BitDefender as the "protector" on my PC if that is the issue.

    Go to support.microsoft.com/fixit
    In section 2 click on: Install or upgrade software or hardware
    Then click on the title in section 3: Fix problems with programs that cannot be installed or uninstall
    This link may get you there:  http://support.microsoft.com/mats/Program_Install_and_Uninstall/
    Let it run and then try to download it again

  • I get the errer message "There is a problem with this windows installer package. A program required for this install to complete could not be run."

    I have Wondows Vista... I tried to upgrade to Itunes 10.5, and received an error orginially stating that I was trying to install a version older than the one I had.  I uninstalled all of itunes, and now I'm getting the error  message "there is a problem with this windows installer package.  Aprogram required for this install to complete could not be run.
    Help!  I have an IPhone, and I would like to get my Itunes upgraded so I can download the new Iphone software...
    Thanks!

    I have been in touch with Apple support in reference to my problem. We went through every solution available, and found no fix. The tech then suggested I contact Microsoft concerning this issue. I thought that suggestion was just to get me pointed somewhere but Apple. Boy was I wrong!! I contacted Microsoft, and was directed to a free download called Microsoft Fix. This program fixed something in the regisitor, and wala everything was fixed!! I now have I-Cloud and I-Tunes loaded and working well. So, if you can't install Apple Software and are running Window 7 you might give Microsoft Fix a try, it fixed my problem.....

  • I am trying to upload itunes 10.5, but get a message "There is a problem with this Window Installer Pkg. A program required for this install to complete could not be run.  Contact your support personnel or package vendor".  What is it I need to do?

    I am trying to install itunes 10.5, but during the download I get the following message, "There is a problem with this Window Installer Package.  A program required for this install to complete could not be run.  Contact your support personanal or package vendor."  If this is my personal computer and was able to upgrade to the previous version (pre 10.5), why not now?  What is my "package vendor"? And what is it I need to do to fix this?  The message is unclear.  Unfortunately, I deleted my itunes program, thinking that in doing so, 10.5 would finally load.  Now I have no itunes on my computer and unable to sync my iphone.  Help!
    Thanks - Rick

    Hi Rick,
    by "repair" I mean I went to the control panel, option - programs and features, and in the list of all my installed programs I selected "Apple Software Update". On top of the screen you find the options Uinstall, Change and Repair. I clicked the repair button and that did the trick. After the repair I could uninstall the program. I also uninstalled iTunes, Apple Application Support, Apple Mobile Device Support en Bonjour, thus all Apple programs. Then I installed iTunes 10.5 again and everything went fine.
    Success,
    Peter

  • HT1926 when trying to setup itunes on my pc i get the following message: there is a problem with this Windows installer package. A program required for this install to complete could not be run. How could I solve this problem?

    when trying to setup itunes on my pc i get the following message: there is a problem with this Windows installer package. A program required for this install to complete could not be run. How could I solve this problem?

    Repair your Apple software update.
    Go to START/ALL PROGRAMS/Apple Software Update. If it offers you a newer version of Apple Software Update, do it but Deselect any other software offered at the same time. Once done, try another iTunes install
    If you don't find ASU, go to Control Panel:
    START/CONTROL PANEL/Programs n Features/highlight ASU and click REPAIR,

  • I'm not able to download Itunes.  I keep getting this Apple Software Update message that states "There is a problem with this Windows installer package.  A program required for this install to complete could not be run.  Contact your package vendor"

    Not able to access Itunes store anymore.  Just quit working for no reason.  I've tried deleting Itunes and related components from the Control Panel, but when I try to remove Apple Software Update, I get a message that states "There is a problem with this Windows installer package.  A program required for this install to complete could not be run.  Contact your support personnel or package vendor".  Not sure what this message means.  Am I suppose to contact Apple ?  What is meant by package vendor ?

    Apparently it's an itunes issue. I just tried to update and got the same issue. Called att to activate my iphone 4s and they say they can do the swap but apple is telling them itunes is down atm.  So will have to wait

  • When I try to install iTunes 10.5, it says, "There is a problem with this Windows Installer package.  A program run as part of the setup did not finish as expected.  Contact your support personnel or package vendor."  I have Windows XP and I need help.

    5, it says, "There is a problem with this Windows Installer package.  A program run as part of the setup did not finish as expected.  Contact your support personnel or package vendor."  I have Windows XP and I need help.

    After reading all these posts, one by one did not resolve my problem until I got the very end.  Regardless of what step would resolve your problem, these are the steps I would recomment to everyone for a what seems to be a safe and fool-proof upgrade to iTunes 10.5.
    1. Stand alone upgrade to the latest Quicktime version
    2. Go to control panel and "change" then select repair to the following applications in the order specified by the post on Oct 27. (Notice I skipped Quicktime because it had been upgrade manually,and Bonjour did not have a "repair" option)
    iTunes; Apple Software Update: Mobile Device Support; Apple Applications Support
    Some of these applications may not appear if they do not apply to your configuration (no iPhone, or no iPad, or other apple devices).
    Once all updated, I did not need to restart nor launch any applications, I simply went straight into the 10.5 upgrade, and where it normally got stuck, this time the installation continued for a while longer until it completed successfully.
    Great work everyone who contributed!  Thank you very much!

  • Error message on window 7 for install iTune and iCloud!!!"There is a problem with this Windows installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor."

    Hi,
    I just try to install the setup download from apple website for iTune and iCloud.
    During the installation, there was error message prompt out "There is a problem with this Windows installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor."
    I am using Window 7 32 bit. I have try several time for install, but the result is getting same error message.
    Anyone can help on this??????
    Thanks.
    Justin

    I have also tried extracting the individual components to the temp file and attempting to install them individually despite being unable to remove the previous install of Apple Software Updater.  The outcome, both Apple Software Updater and itunes encountered the same error message during the install process.

  • I am trying to update to iTunes 10.5 and am getting a Apple Software update error. "There is a problem with this Windows Installer Package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. ??

    I am trying to update to iTunes 10.5 and am getting a Apple Software update error. "There is a problem with this Windows Installer Package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. ?? I can't uninstall the Apple Software Update from my Control Panel. It states "Fatal error during installation" Please HELP!!!

    I am experiencing the exact same issue during the installtion process for iTunes 10.5.
    I uninstalled all Apple components but when I attempted to uninstall the Apple Software Update I received the same message: "Fatal error during installtion." I was able to repair the Apple Software Update but still could not install iTunes 10.5 afterwards.
    I have tried everything that I could find on these discussions pages as well as other suggestions on third party sites. I continue to receive the error message: "There is a problem with this Windows Installer Package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor.
    I was able to uninstall and reinstall QuickTime 7.7.1. During the reinstalltion process I received the same message (There is a problem with this Windows Installer Package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor.) But after clicking "OK" the installtion process was succesful. PLEASE HELP!

  • When I installed iTunes 10.6 to windows 7, during the process i got this message -" There is a problem with this windows installer package. A program required for this install to complete could not be run"

    when I installed iTunes 10.6 to windows 7, during the process i got this message -" There is a problem with this windows installer package. A program required for this install to complete could not be run" and after that the setup closed automatically. Plaese tell me if any setting up of windows is in order.

    Try looking at the two previous discussions listed on the right side of this page with your same question.
    Also, try searching/posting in the iTunes forum since you do not have an iPod problem.

  • I am trying to update my iPhone software but to do so I needed to update iTunes.  When I try to do that, I keep getting this error message" "There is a problem with this Windows Installer Package. A program required for this install to complete could not

    I am trying to update my iPhone software but to do so I needed to update iTunes.  When I try to do that, I keep getting this error message" "There is a problem with this Windows Installer Package. A program required for this install to complete could not....

    Try the following user tip:
    "There is a problem with this Windows Installer package ..." error messages when installing iTunes for Windows

  • Unable to install itunes 10,5.I receive this message: there is a problem with this window installer package. A program required for nthis install to complete could not run. Contact your support personnel or package vendor.Am using window ultimate 64 bits

    I am unable to install itunes 10,5. I receive this message: There is a problem with this window installer package. A program required for this install to complete could not run. Contact your support personnel or package vendor. I am using window 7 ultimate 64 bits

    There is a problem with the Window installer package. A program required for this intall to complete could not be run. Contact your support personnel or package venfor.
    Perhaps let's first try updating your Apple Software Update.
    Launch Apple Software Update ("Start > All Programs > Apple Software Update"). Does it launch and offer you a newer version of Apple Software Update? If so, choose to install just that update to Apple Software Update. (Deselect any other software offered at the same time.)
    If the ASU update goes through okay, try another iTunes install. Does it go through without the errors this time?

  • What to do when installing itunes to windows vista home basic an message appears saying"there is a problem with this windows installer package.A program run as part of the setup did not finish as expected.Contact your support personnel or package vendor."

    what do i do when trying to install itunes to my windows vista home basic computer and a message appears saying
    "There is a problem with this windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor."
    Need to know because this is driving me nuts now!

    Let's try the following user tip with that one:
    "There is a problem with this Windows Installer package ..." error messages when installing iTunes for Windows

Maybe you are looking for