Element17
09-08-2013, 10:46 PM
First off thanks for the help last time guys! I will post my assignment later tonight once I finish it! But I do have one question about something my teach asked...
"Two variables*, num and cost have been declared* and given* values*: num is an integer* and cost is a double*. Write a single statement* that outputs* num and cost to standard output*. Print both values* (num first, then cost), separated by a space on a single line that is terminated with a newline character*. Do not output* any thing else."
No idea what he is really asking for there....
import java.util.Scanner;
/*Andrew Varnick
9/7/2013
CSCI 1015
Programming Assignment 2
The purpose of this assignment/program is to calculate the number of cents in a specific number of dimes and nickels
*/
public class VarnickPass2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String name, input1, input2;
int nickle, dime, total;
//Get the user's name
name =
keyboard.nextLine();
//Get the number of nickles and dimes
input = keyboard.nextLine();
input2 = keyboard.nextLine();
//Convert the input to Int
nickle = Integer.parseInt(input);
dime = Integer.parseInt(input2);
//Gets total
System.out.println("Total is:" + ((nickle * 5) + (dime * 10)));
System.exit(0);
}
}
Assignment #2 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=2) !!!!!
Purpose
To learn how to create the main java method, explore declaring a variables, using
arithmetic operators, assignment statements, reading from the keyboard using the
Scanner class and outputting results using
System.out class, and adding comments.
Exercise
Write a program that will calculate the number of cents in a specific number of dimes
and nickels. The program will perform the following tasks:
•Ask the user to enter the number of dimes.
•Ask the user to enter the number of nickels.
•Calculate the total number of cents.
•Display to the monitor the number of cents.
"Two variables*, num and cost have been declared* and given* values*: num is an integer* and cost is a double*. Write a single statement* that outputs* num and cost to standard output*. Print both values* (num first, then cost), separated by a space on a single line that is terminated with a newline character*. Do not output* any thing else."
No idea what he is really asking for there....
import java.util.Scanner;
/*Andrew Varnick
9/7/2013
CSCI 1015
Programming Assignment 2
The purpose of this assignment/program is to calculate the number of cents in a specific number of dimes and nickels
*/
public class VarnickPass2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String name, input1, input2;
int nickle, dime, total;
//Get the user's name
name =
keyboard.nextLine();
//Get the number of nickles and dimes
input = keyboard.nextLine();
input2 = keyboard.nextLine();
//Convert the input to Int
nickle = Integer.parseInt(input);
dime = Integer.parseInt(input2);
//Gets total
System.out.println("Total is:" + ((nickle * 5) + (dime * 10)));
System.exit(0);
}
}
Assignment #2 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=2) !!!!!
Purpose
To learn how to create the main java method, explore declaring a variables, using
arithmetic operators, assignment statements, reading from the keyboard using the
Scanner class and outputting results using
System.out class, and adding comments.
Exercise
Write a program that will calculate the number of cents in a specific number of dimes
and nickels. The program will perform the following tasks:
•Ask the user to enter the number of dimes.
•Ask the user to enter the number of nickels.
•Calculate the total number of cents.
•Display to the monitor the number of cents.