Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assignment #12 - Computer Programming I | CSIS 44141, Assignments of Computer Science

Material Type: Assignment; Professor: Spradling; Class: COMPUTER PROGRAMMING I; Subject: Computer Science/Info Systems; University: Northwest Missouri State University; Term: Spring 2010;

Typology: Assignments

2009/2010

Uploaded on 02/22/2010

apalmer14
apalmer14 🇺🇸

4 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
44.141 Exercise12
1. Examine the Driver class listed below, the main method and the methods ( method1(), method2(),
method3(), method4(), method5() ) listed inside the Driver class. Using the variables declared in
the main method, write in the space provided how one should call each of the static methods from
inside the main method.
public class Driver
{
public static void main(String [] args)
{
int intNumber;
String message;
double doubleValue = 11.5;
//Call method1
method1();
//Call method2
intNumber = method2();
//Call method3
method3( intNumber);
//Call method4
message = method4(doubleValue);
//Call method5
doubleValue = method5(intNumber);
}
public static void method1()
{
System.out.println( "Hello from method 1" );
}
public static int method2()
{
return 10;
}
public static void method3(int number)
{
System.out.println( "This is my number " + number );
}
public static String method4(double number)
{
String message = "This is my number returned as part of a string "
+ number;
return message;
}
pf3
pf4
pf5

Partial preview of the text

Download Assignment #12 - Computer Programming I | CSIS 44141 and more Assignments Computer Science in PDF only on Docsity!

44.141 Exercise

  1. Examine the Driver class listed below, the main method and the methods ( method1(), method2(), method3(), method4(), method5() ) listed inside the Driver class. Using the variables declared in the main method, write in the space provided how one should call each of the static methods from inside the main method. public class Driver { public static void main(String [] args) { int intNumber; String message; double doubleValue = 11.5; //Call method method1(); //Call method intNumber = method2(); //Call method method3( intNumber); //Call method message = method4(doubleValue); //Call method doubleValue = method5(intNumber); } public static void method1() { System.out.println( "Hello from method 1" ); } public static int method2() { return 10; } public static void method3(int number) { System.out.println( "This is my number " + number ); } public static String method4(double number) { String message = "This is my number returned as part of a string " + number; return message; }

public static double method5(int number) { if ( number == 10 ) return (double) 10 * 2; else return (double)10; } }

} //======= end class StaticProblem2 =======

  1. Examine the Driver class listed below. Note that a portion of the main method has been written for you. Your task to do the following:  You should write a static method named calculateMonthlyInterest that contains two parameters. The first parameter will be the an int variable which is used to store the principle. The second parameter will be a double variable which is used to store the interest rate. The method will calculate the monthly interest for the principle using the interest rate. For example, if the principle is 1111 and the interest rate is 12%, then the monthly interest would be 11.11.  The main program contains variables that will be used with the calculateMonthlyInterest method. Complete the main method by showing how you would call the calculateMonthlyInterst() method. import java.util.Scanner; public class StaticProblem { public static void main( String[] args) { int principle; double interestRate; double monthlyInterest; Scanner keyboardInput = new Scanner( System.in ); System.out.print( "Enter the principle: " ); principle = keyboardInput.nextInt(); System.out.print( "Enter the interest rate: " ); interestRate = keyboardInput.nextDouble(); //Call the calculateMonthlyInterset method monthlyInterest = calculateMonthlyInterest(principle, interestRate); System.out.println( "The monthly interest is " + monthlyInterest ); } //===== end method main(String[]) ===== public static double calculateMonthlyInterest( int principle, double interestRate); { double monthlyInterest = (principle*interestRate)/12; return monthlyInterest; } //end method calculateInterest() } //======= end class StaticProblem2 =======