Homework 1 Code

Homework 1 Code - file:/X|/cs101/Lincoln.txt public class...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
file:///X|/cs101/Lincoln.txt public class Lincoln { //---------------------------------- // Prints a presidential quote. //---------------------------------- public static void main (String[] args) { System.out.println ("A quote by Abraham Lincoln:"); System.out.println ("Whatever you are, be a good one."); } } file:///X|/cs101/Lincoln.txt [4/29/2008 12:09:29 PM]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
file:///X|/cs101/Homework1_0.txt /* == Solve 2.5 from page 63 == Write a program that read the subtotal and the gratuity rate, and computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratutity rate, the program displays $1.5 as gratuity and $11.5 as total. */ import javax.swing.JOptionPane; public class Homework1_0 { public static void main (String[] args) { // get the subtotal. double subtotal = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the" +" subtotal:","Homework1_0 Input", JOptionPane.QUESTION_MESSAGE)); // get the gratuity. double gratuity = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the" +" gratuity:\n(ex: 0.15 for 15%)", "Homework1_0 Input", JOptionPane.QUESTION_MESSAGE)); // calculate the value of the gratuity and total cost. gratuity = (int)(gratuity * subtotal * 100) / 100.0; double total = gratuity + subtotal; // output the gratuity and total cost. JOptionPane.showMessageDialog(null, "The calculated gratuity is: $" + gratuity +"\nThe total cost is: $" + total); // no errors. System.exit(0); } } file:///X|/cs101/Homework1_0.txt [4/29/2008 12:09:29 PM]
Background image of page 2
file:///X|/cs101/Homework1_1.txt /* == Solve 2.6 from page 64 == Write a program that reads an integer from 0 to 1000 and adds all the digits in the integer. For example if an integer is 932, the sum of all the its digits is 14.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2008 for the course CS 101L taught by Professor Vineyard during the Winter '07 term at Kettering.

Page1 / 6

Homework 1 Code - file:/X|/cs101/Lincoln.txt public class...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online