The Artima Developer Community
Sponsored Link

Java Answers Forum
can anyone help me with this assignment?

3 replies on 1 page. Most recent reply: Sep 9, 2003 12:33 AM by David

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Anthony

Posts: 3
Nickname: kingka91
Registered: Sep, 2003

can anyone help me with this assignment? Posted: Sep 7, 2003 5:17 PM
Reply to this message Reply
Advertisement
I am newbie and I have an assignment due next week and I have no idea how to work this out..can anyone please help me with this?

-----------------------------------------------------------------
Design and implement an application or applet that determines and prints the number of odd, even, and zero digits in an integer value read from the keyboard.
-----------------------------------------------------------------

he re is what i have done so far..

mport java.awu.Graphics;

import javax.swing.*;

public class IntegerApplet extends JApplet
{

pulbic void init ()
{

String EnterNumber;
int num;

EnterNumber = JOptionPane.showInputDialog ("Enter an integer value");

x = EnterNumber.charAt()

if (num [x] % 2 == 0

if ( $num % 2 )
{
print "num=$num is odd\n";
}
else
{
print "num=$num is even\n";
}
else

I'm not even sure I did the odd even zero part right..please help me..


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: can anyone help me with this assignment? Posted: Sep 8, 2003 3:36 AM
Reply to this message Reply
Erm...this isn't Perl - you don't use variables like that. I don't think this code would even compile (which is a good place to start).

I suggest that you first write a console application that does the ood/even number thing and get the logic of that right. Once that's done, *then* build the GUI which just calls the object you wrote for you console application.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: can anyone help me with this assignment? Posted: Sep 8, 2003 2:09 PM
Reply to this message Reply
Here's a start. You'll have to put in your own parsing logic (as that, apparently, is your homework), but this will at least compile.
public class NumberReader {
	public static void main(String [] args) {
		NumberReader numberReader = new NumberReader();
		numberReader.setInt(5120);
		System.out.println("Number of zeroes: " + numberReader.getZeroCount());
		System.out.println("Number of odds: " + numberReader.getOddCount());
		System.out.println("Number of evens: " + numberReader.getEvenCount());
	}
 
	private String sInt;
	private int zeroCount;
	private int oddCount;
	private int evenCount;
 
 
	public void setInt(int theInt) {
		this.sInt = Integer.toString(theInt);
		parse();
	}
 
	private void parse() {
		// TODO
	}
 
	public int getZeroCount() {
		return zeroCount;
	}
 
	public int getOddCount() {
		return oddCount;
	}
 
	public int getEvenCount() {
		return evenCount;
	}
}

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: can anyone help me with this assignment? Posted: Sep 9, 2003 12:33 AM
Reply to this message Reply
Yup, I think Joe has given you a nice little framework to get started.

Flat View: This topic has 3 replies on 1 page
Topic: printing in Java Previous Topic   Next Topic Topic: Need some insight into Jini technology

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use