The Artima Developer Community
Sponsored Link

Java Answers Forum
How to set Main to access methods

0 replies on 1 page.

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 0 replies on 1 page
gary davis

Posts: 1
Nickname: antonio45
Registered: Feb, 2003

How to set Main to access methods Posted: Feb 14, 2003 9:13 PM
Reply to this message Reply
Advertisement
I am starting to learn java programming. I would like to know how to setup the main to access the methods. Enclosed is an example of code, would like to know how to design the main to access the method class.

public class Dollars
{
/***************************************************************
*Outputs amount in dollars and cents notation. Rounds after two
*decimal points. Does not advance to the next line after output.
***************************************************************/
public static void write(double amount)
{
if (amount >= 0)
{
System.out.print('$');
writePositive(amount);
}
else
{
double positiveAmount = -amount;
System.out.print('$');
System.out.print('-');
writePositive(positiveAmount);
}
}

//Precondition: amount >= 0;
//Outputs amount in dollars and cents notation. Rounds
//after two decimal points. Omits the dollar sign.
private static void writePositive(double amount)
{
int allCents = (int)(Math.round(amount*100));
int dollars = allCents/100;
int cents = allCents%100;

System.out.print(dollars);
System.out.print('.');
if (cents < 10)
{
System.out.print('0');
System.out.print(cents);
}
else
System.out.print(cents);
}


/***********************************************************
*Outputs amount in dollars and cents notation. Rounds after
*two decimal points. Advances to the next line after output.
***********************************************************/
public static void writeln(double amount)
{
write(amount);
System.out.println();
}





}

Topic: Number of ways to factorize an integer Previous Topic   Next Topic Topic: Free space of harddisk

Sponsored Links



Google
  Web Artima.com   

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