Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ***************ASSIGNMENT 1
- /*
- This is Question #1 for Assignment #1, Circuit Board Profit Assignment
- Mary Arienne Nabong, 62:160
- Wednesday Lab
- */
- import java.util.*; //import Scanner class for input
- public class CircuitBoardProfit
- {
- public static void main(String[] args)
- {
- double price;//entered price of circuit board
- //Create Scanner object to read input
- Scanner keyboard = new Scanner(System.in);
- //Get price of circuit board
- System.out.print("Enter price of circuit board. $");
- price = keyboard.nextInt();
- //Calculate profit
- double profit = (price * 0.4);
- //Display proft
- System.out.println("The profit from this circuit board is $" + (profit));
- }
- }
- ***************ASSIGNMENT 2
- /* This is Question #2 from Assignment #1, String Manipulator
- Mary Arienne Nabong, 62:160
- Wednesday Lab
- */
- import java.util.*; //import Scanner class for input
- public class StringManipulator
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- String cityName;
- //Get city name
- System.out.print("Enter your favorite city: ");
- cityName = keyboard.nextLine();
- //Manipulations
- //Number of characters in city name
- int numberChars = cityName.length();
- //City name in all capitals
- String allCaps = cityName.toUpperCase();
- //City name in all lowercase
- String allLower = cityName.toLowerCase();
- //First letter in city name
- char firstLetter = cityName.charAt(0);
- //Display manipulations
- System.out.println((numberChars) + "\n"
- + (allCaps) + "\n"
- + (allLower) + "\n"
- + (firstLetter));
- }
- }
- ***************ASSIGNMENT 3
- /* This is Question #3 from Assignment #1, Converter
- Mary Arienne Nabong, 62:160
- Wednesday Lab
- */
- import java.util.*; //import Scanner class for input
- public class Converter
- {
- public static void main(String[] args)
- {
- double amount; //entered amount of money
- //Create Scanner object to read input
- Scanner keyboard = new Scanner(System.in);
- //Get entered money
- System.out.print("Enter dollar amount. $");
- amount = keyboard.nextDouble();
- //multiply by 100 to receive number without decimal
- double amountTimesHundred = (amount * 100);
- //divide amount 100 to find amount of dollars // -,
- double dollars = Math.floor((amountTimesHundred) / 100); // -' DOLLARS
- //mod amount times hundred for cents
- double cents = amountTimesHundred % 100;
- //find floor of cents to find tens place of cents
- double tensOfCents = Math.floor(cents);
- //divide tensOfCents by 25 to find amount of quarters // -,
- double quarters = Math.floor((tensOfCents) / 25); // |
- //to find cents remaining after quarters // |
- double centsPostQuarters = (tensOfCents) - (quarters * 25); // -' QUARTERS
- //to find amount of dimes // -,
- double dimes = Math.floor((centsPostQuarters) / 10); // |
- //to find amount remaining after dimes // |
- double centsPostDimes = (centsPostQuarters) - (dimes * 10); // -' DIMES
- //to find amount of nickels // -,
- double nickels = Math.floor((centsPostDimes) / 5); // -' NICKELS
- //to find amount of pennies // -,
- double pennies = Math.floor(centsPostQuarters % 5); // -' PENNIES
- //cast to integers for smoother reading
- int intDollars = (int) dollars;
- int intQuarters = (int) quarters;
- int intDimes = (int) dimes;
- int intNickels = (int) nickels;
- int intPennies = (int) pennies;
- //incase the amounts of each coin didn't need to be an integer
- /*System.out.println("$" + (amount) + " is equivalent to " + (dollars)
- + " dollars, "
- + (quarters) + " quarters, "
- + (dimes) + " dimes, "
- + (nickels) + " nickels, and "
- + (pennies) + " pennies." + (I)); */
- System.out.println("$" + (amount) + " is equivalent to " + (intDollars)
- + " dollars, "
- + (intQuarters) + " quarters, "
- + (intDimes) + " dimes, "
- + (intNickels) + " nickels, and "
- + (intPennies) + " pennies.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement