{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework 1 Code

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

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

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]

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

View Full Document
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]
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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern