Archives from S:\ Drive
Good to keep around methinks
This commit is contained in:
1 parent
eadaf70b9e
commit
6dd63cc439
606 files changed
+50212
No files matched your search
@@ -0,0 +1,9 @@
|
||||
public class HelloWorld
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println("Hello World \nThis is my first Java Program.");
|
||||
System.out.println("The sum of 2 and 3 = " +5);
|
||||
System.out.println("7 + 8 = " + (7 + 8));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/******************************************************************************
|
||||
* Project: Midterm COM 107 *
|
||||
* Class Name: $12Days *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/06/2012 *
|
||||
* Hours: 1.25 Hours *
|
||||
* Purpose: Creating an application that exhibit adherence to best *
|
||||
* programming practices. Effective application documentation, *
|
||||
* Effective use of whitespace for ease in software maintenance, *
|
||||
* Selection of appropriate data types using meaningful, *
|
||||
* conventional identifiers, Appropriate use of error handling, *
|
||||
* Creating simple and complex Boolean expressions to evaluate *
|
||||
* primitives and strings, Developing a single and dual *
|
||||
* alternative selection structures and linear selection *
|
||||
* structures, Using test cases to validate application output. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class $12Days
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
// english words for possessive numbers.
|
||||
String sDay01 = "first", sDay02 = "second", sDay03 = "third",
|
||||
sDay04 = "fourth", sDay05 = "fifth", sDay06 = "sixth",
|
||||
sDay07 = "seventh", sDay08 = "eighth", sDay09 ="nineth",
|
||||
sDay10 = "tenth", sDay11 = "eleventh", sDay12 = "twelfth";
|
||||
|
||||
// actual verse.
|
||||
String sGift01 = "partridge in a pear tree",
|
||||
sGift02 = "turtle doves", sGift03 = "French hens",
|
||||
sGift04 = "calling birds", sGift05 = "golden rings",
|
||||
sGift06 = "geese a-laying", sGift07 = "swans a-swimming",
|
||||
sGift08 = "maids a-milking", sGift09 = "ladies dancing",
|
||||
sGift10 = "lords a-leaping", sGift11 = "pipers piping",
|
||||
sGift12 = "drummers drumming";
|
||||
|
||||
// first part of verse.
|
||||
String sNum01 = "And a ", sNum02 = "Two ", sNum03 = "Three ",
|
||||
sNum04 = "Four ", sNum05 = "Five ", sNum06 = "Six ",
|
||||
sNum07 = "Seven ", sNum08 = "Eight ", sNum09 = "Nine ",
|
||||
sNum10 = "Ten ", sNum11 = "Eleven ", sNum12 = "Twelve ";
|
||||
|
||||
//various strings that assisted with my switch structure below below.
|
||||
String sSoR01 = "On the ",
|
||||
sSor02 = " day of Christmas,\nmy true love sent to me\n",
|
||||
sFNum01 = "A ", // special case for the first instance of day 1
|
||||
sC = ",\n", // common line break
|
||||
sP = ".", // last line ending
|
||||
sE = "!"; // special case for *very* last line (day 12).
|
||||
|
||||
int iDay = 0; // start with an unsupported day, ensures validated input
|
||||
|
||||
Scanner console = new Scanner(System.in); // prompt user for input
|
||||
System.out.print("What day of Chistmas are we on?\n"
|
||||
+ "Please enter the day number.\n"
|
||||
+ ":");
|
||||
|
||||
String sInput = console.nextLine(); // Grab string input.
|
||||
System.out.println(" "); // just for visual appeal.
|
||||
try
|
||||
{
|
||||
iDay = Integer.parseInt(sInput); // see if we can parse an integer
|
||||
}
|
||||
catch (NumberFormatException ex) // bad input, not a number
|
||||
{
|
||||
System.out.println("We're sorry, \""+sInput+"\" was an invalid day.\n"
|
||||
+ "Please re-run the program.");
|
||||
System.exit(1); // error out here. bad input.
|
||||
}
|
||||
if (iDay <= 0 || iDay > 12) // not a number we support. only days 1-12;
|
||||
{
|
||||
System.out.println("We're sorry, \""+sInput+"\" was an invalid day.\n"
|
||||
+ "Please re-run the program.");
|
||||
System.exit(2); // error out here, bad input, unsupported number.
|
||||
}
|
||||
|
||||
|
||||
//this would be much easier if we knew iteration.
|
||||
String sOut = ""; // output buffer.
|
||||
switch (iDay)
|
||||
{
|
||||
case 1:
|
||||
sOut += sSoR01+sDay01+sSor02;
|
||||
sOut += sFNum01+sGift01+sP;
|
||||
break;
|
||||
case 2:
|
||||
sOut += sSoR01+sDay02+sSor02;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 3:
|
||||
sOut += sSoR01+sDay03+sSor02;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 4:
|
||||
sOut += sSoR01+sDay04+sSor02;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 5:
|
||||
sOut += sSoR01+sDay05+sSor02;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 6:
|
||||
sOut += sSoR01+sDay06+sSor02;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 7:
|
||||
sOut += sSoR01+sDay07+sSor02;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 8:
|
||||
sOut += sSoR01+sDay08+sSor02;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 9:
|
||||
sOut += sSoR01+sDay09+sSor02;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 10:
|
||||
sOut += sSoR01+sDay10+sSor02;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 11:
|
||||
sOut += sSoR01+sDay11+sSor02;
|
||||
sOut += sNum11+sGift11+sC;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sP;
|
||||
break;
|
||||
case 12:
|
||||
sOut += sSoR01+sDay12+sSor02;
|
||||
sOut += sNum12+sGift12+sC;
|
||||
sOut += sNum11+sGift11+sC;
|
||||
sOut += sNum10+sGift10+sC;
|
||||
sOut += sNum09+sGift09+sC;
|
||||
sOut += sNum08+sGift08+sC;
|
||||
sOut += sNum07+sGift07+sC;
|
||||
sOut += sNum06+sGift06+sC;
|
||||
sOut += sNum05+sGift05+sC;
|
||||
sOut += sNum04+sGift04+sC;
|
||||
sOut += sNum03+sGift03+sC;
|
||||
sOut += sNum02+sGift02+sC;
|
||||
sOut += sNum01+sGift01+sE;
|
||||
break;
|
||||
}
|
||||
System.out.println(sOut); // print buffer.
|
||||
System.exit(0); // we're done.
|
||||
}
|
||||
}
|
||||
|
||||
/*Program Output:
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:11
|
||||
|
||||
On the eleventh day of Christmas,
|
||||
my true love sent to me
|
||||
Eleven pipers piping,
|
||||
Ten lords a-leaping,
|
||||
Nine ladies dancing,
|
||||
Eight maids a-milking,
|
||||
Seven swans a-swimming,
|
||||
Six geese a-laying,
|
||||
Five golden rings,
|
||||
Four calling birds,
|
||||
Three French hens,
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:2
|
||||
|
||||
On the second day of Christmas,
|
||||
my true love sent to me
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:invalid input
|
||||
|
||||
We're sorry, "invalid input" was an invalid day.
|
||||
Please re-run the program.
|
||||
|
||||
S:\programs\Mod1\Midterm>java $12Days
|
||||
What day of Chistmas are we on?
|
||||
Please enter the day number.
|
||||
:5
|
||||
|
||||
On the fifth day of Christmas,
|
||||
my true love sent to me
|
||||
Five golden rings,
|
||||
Four calling birds,
|
||||
Three French hens,
|
||||
Two turtle doves,
|
||||
And a partridge in a pear tree.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1b *
|
||||
* Class Name: Numbers *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To declare variables, constant variables, explore promotions *
|
||||
* explicit type casting, and display the results of these *
|
||||
* activities. *
|
||||
******************************************************************************/
|
||||
|
||||
public class Numbers // direction 1
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iNumberTwo = 765, iNumberThree = (int) 4.75, iNumberFour = 17, iNumberFive = -2; // direction a + b
|
||||
final int iNumberOne = 3; // as per directon a + c: iNumberOne must be constant
|
||||
double dRealOne = 54.3, dRealTwo = 85, dRealThree = 67.56, dRealFour = 2, dRealFive = 3.3; // direction d + e
|
||||
|
||||
System.out.println("NumberOne stores " + iNumberOne); //direction f
|
||||
System.out.println("NumberTwo stores " + iNumberTwo); //f
|
||||
System.out.println("NumberThree stores " + iNumberThree); //f
|
||||
System.out.println("NumberFour stores " + iNumberFour); //f
|
||||
System.out.println("NumberFive stores " + iNumberFive); //f
|
||||
System.out.println("RealOne stores " + dRealOne); //f
|
||||
System.out.println("RealTwo stores " + dRealTwo); //f
|
||||
System.out.println("RealThree stores " + dRealThree); //f
|
||||
System.out.println("RealFour stores " + dRealFour); //f
|
||||
System.out.println("RealFive stores " + dRealFive); //f
|
||||
System.out.println("** Number Three is type casted as an integer"); // direction g
|
||||
System.out.println("** Real Two is implicitly promoted as a double"); // direction h
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Numbers
|
||||
NumberOne stores 3
|
||||
NumberTwo stores 765
|
||||
NumberThree stores 4
|
||||
NumberFour stores 17
|
||||
NumberFive stores -2
|
||||
RealOne stores 54.3
|
||||
RealTwo stores 85.0
|
||||
RealThree stores 67.56
|
||||
RealFour stores 2.0
|
||||
RealFive stores 3.3
|
||||
** Number Three is type casted as an integer
|
||||
** Real Two is implicitly promoted as a double
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,63 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1c *
|
||||
* Class Name: Numbers *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/09/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To declare variables, constant variables, explore promotions *
|
||||
* explicit type casting, and display the results of these *
|
||||
* activities. *
|
||||
******************************************************************************/
|
||||
|
||||
public class Precedence // direction a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iAmFour = 4, iAmTwo = 2, iAmSeven = 7, iAmFourteen = 14, iAmEightteen = 18, iAmFive = 5, iAmOne = 1, iAmTwentyEight = 28, iAmTwenty = 20, iAmThree = 3; // direction a
|
||||
double iAmPointTwo = 0.2; // direction a
|
||||
System.out.println( iAmFour + " + " + iAmSeven + " * " + iAmFour + " = " + (iAmFour+iAmSeven*iAmFour) ); // comp 1
|
||||
System.out.println( iAmFour + " / " + iAmTwo + " * " + iAmFourteen + " = " + (iAmFour/iAmTwo*iAmFourteen) ); // comp 2
|
||||
System.out.println( iAmEightteen + " / " + iAmTwo + " + " + iAmFourteen + " / " + iAmTwo + " = " + (iAmEightteen/iAmTwo+iAmFourteen/iAmTwo) ); // comp 3
|
||||
System.out.println( iAmFour + " + " + iAmTwo + " / " + iAmFour + " - " + iAmTwo + " = " + (iAmFour+iAmTwo/iAmFour-iAmTwo) ); // comp 4
|
||||
System.out.println( iAmFive + " % " + iAmTwo + " * " + iAmFour + " / " + iAmOne + " + " + iAmFive + " = " + (iAmFive%iAmTwo*iAmFour/iAmOne+iAmFive) ); // comp 5
|
||||
System.out.println( iAmTwentyEight + " / " + iAmFive + " = " + (iAmTwentyEight/iAmFive) ); // comp 6
|
||||
System.out.println( iAmTwentyEight + " % " + iAmFive + " = " + (iAmTwentyEight%iAmFive) ); // comp 7
|
||||
System.out.println( iAmTwenty + " / ( " + iAmFour + " + " + iAmOne + " ) = " + (iAmTwenty/(iAmFour+iAmOne)) ); // comp 8
|
||||
System.out.println( "( " + iAmTwo + " + " + iAmThree + " ) * " + iAmFour + " = " + ((iAmTwo+iAmThree)*iAmFour) ); // comp 9
|
||||
System.out.println( "24 / " + iAmPointTwo + " = " + (24/iAmPointTwo) ); // comp 10
|
||||
System.out.println( "----------------------------------------------------------------------------------------" );
|
||||
System.out.println( "Order of Precedence:" ); // direction c
|
||||
System.out.println( "1) Parentheses." ); // c
|
||||
System.out.println( "2) Multiplication, Division, Modulo - Left to Right." ); // c
|
||||
System.out.println( "3) Addition, Subtraction - Left to Right." ); // c
|
||||
System.out.println( "4) Assignment - Right to Left." ); // c
|
||||
System.out.println( "Multiplicative Operators are assosciated from Left to Right" ); // direction d
|
||||
System.out.println( "Addative Operators are assosciated from Left to Right" ); // d
|
||||
System.out.println( "Assignment Operators are assosciated from Right to Left" ); // d
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Precedence
|
||||
4 + 7 * 4 = 32
|
||||
4 / 2 * 14 = 28
|
||||
18 / 2 + 14 / 2 = 16
|
||||
4 + 2 / 4 - 2 = 2
|
||||
5 % 2 * 4 / 1 + 5 = 9
|
||||
28 / 5 = 5
|
||||
28 % 5 = 3
|
||||
20 / ( 4 + 1 ) = 4
|
||||
( 2 + 3 ) * 4 = 20
|
||||
24 / 0.2 = 120.0
|
||||
----------------------------------------------------------------------------------------
|
||||
Order of Precedence:
|
||||
1) Parentheses.
|
||||
2) Multiplication, Division, Modulo - Left to Right.
|
||||
3) Addition, Subtraction - Left to Right.
|
||||
4) Assignment - Right to Left.
|
||||
Multiplicative Operators are assosciated from Left to Right
|
||||
Addative Operators are assosciated from Left to Right
|
||||
Assignment Operators are assosciated from Right to Left
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,75 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/07/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1a // direction I
|
||||
{
|
||||
public static void main(String[] args) // direction I
|
||||
{
|
||||
String star = "\t\t\t*\n\n\t\t * * *\n\n\t\t * * * * * *\n\n\t\t * * * * * \n"+
|
||||
"\n\t\t * * * * * *\n\n\t\t * * *\n\n\t\t\t*"; // direction A -> This is the star. It is centered.
|
||||
|
||||
String pine = "\t\t\t#\n\n\t\t # #\n\n\t\t # # #\n\n\t\t # # # #\n\n\t\t\t#"; // direction B -> Pine tree like figure. Centered as well
|
||||
|
||||
String init = "\t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP \n\t AA"+
|
||||
" AA SSSSS PPPPPP \n\t AAAAAAA SS PP \n\t AA AA SSSSS PP "; // direction c -> ASP. Centered.
|
||||
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another flush.
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Project1a
|
||||
*
|
||||
|
||||
* * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * * * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * *
|
||||
|
||||
*
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
|
||||
# #
|
||||
|
||||
# # #
|
||||
|
||||
# # # #
|
||||
|
||||
#
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
AAA SSSSS PPPPPP
|
||||
AAAAA SS PP PP
|
||||
AA AA SSSSS PPPPPP
|
||||
AAAAAAA SS PP
|
||||
AA AA SSSSS PP
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 1d *
|
||||
* Class Name: Strings *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/13/2012 *
|
||||
* Hours: 0.16 Hours *
|
||||
* Purpose: To declare variables, initalize, and display two strings *
|
||||
* Concarenate and display results *
|
||||
******************************************************************************/
|
||||
|
||||
public class Strings // direction 1
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sStr1 = "String1", sStr2 = "String2", sStr3 = ""; // direction 2
|
||||
System.out.println(sStr1 + "\n" + sStr2);
|
||||
char cH0 = 'H', cE0 = 'E', cL0 = 'L', cL1 = 'L', cO0 = 'O', cSpc = ' ', cW0 = 'W', cO2 = 'O', cR0 ='R', cL3 = 'L', cD0 = 'D', cExlm = '!'; // direction 3
|
||||
sStr3 = "" + cH0 + cE0 + cL0 + cL1 + cO0 + cSpc + cW0 + cO2 + cR0 + cL3 + cD0 + cExlm + "";
|
||||
System.out.println(sStr3); // direction 3
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project1>java Strings
|
||||
String1
|
||||
String2
|
||||
HELLO WORLD!
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.30 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1aDub
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String star = "\t\t\t*\t\t\t*\n\n\t\t * * *\t\t * * *\n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t"+
|
||||
" * * * * * \t\t * * * * * \n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t * * *\t\t "+
|
||||
" * * *\n\n\t\t\t*\t\t\t*"; // This is the star. It is centered.
|
||||
String pine = "\t\t\t#\t\t\t#\n\n\t\t # #\t\t # #\n\n\t\t # # #\t\t # # #\n\n\t\t # #"+
|
||||
" # #\t\t # # # #\n\n\t\t\t#\t\t\t#"; // Pine tree like figure. Centered as well
|
||||
String init = "\t AAA SSSSS PPPPPP \t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP "+
|
||||
"\t AAAAA SS PP PP \n\t AA AA SSSSS PPPPPP \t AA AA SSSSS PPPPPP "+
|
||||
"\n\t AAAAAAA SS PP \t AAAAAAA SS PP \n\t AA AA SSSSS PP \t "+
|
||||
" AA AA SSSSS PP "; // ASP. Centered.
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another line.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*********************************************
|
||||
* Program: Project 1a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/08/2012 *
|
||||
* Hours: 0.30 Hours *
|
||||
* Purpose: create an application that *
|
||||
* will display two of the folowing patterns *
|
||||
* ----------------------------------------- *
|
||||
* A) a 6 pointed star *
|
||||
* B) a pine tree shape composed of pound *
|
||||
* symbols *
|
||||
* C) your initals using each inital to *
|
||||
* create a large version of that letter *
|
||||
*********************************************/
|
||||
|
||||
public class Project1aDub
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String star = "\t\t\t*\t\t\t*\n\n\t\t * * *\t\t * * *\n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t"+
|
||||
" * * * * * \t\t * * * * * \n\n\t\t * * * * * *\t\t * * * * * *\n\n\t\t * * *\t\t "+
|
||||
" * * *\n\n\t\t\t*\t\t\t*"; // This is the star. It is centered.
|
||||
String pine = "\t\t\t#\t\t\t#\n\n\t\t # #\t\t # #\n\n\t\t # # #\t\t # # #\n\n\t\t # #"+
|
||||
" # #\t\t # # # #\n\n\t\t\t#\t\t\t#"; // Pine tree like figure. Centered as well
|
||||
String init = "\t AAA SSSSS PPPPPP \t AAA SSSSS PPPPPP \n\t AAAAA SS PP PP "+
|
||||
"\t AAAAA SS PP PP \n\t AA AA SSSSS PPPPPP \t AA AA SSSSS PPPPPP "+
|
||||
"\n\t AAAAAAA SS PP \t AAAAAAA SS PP \n\t AA AA SSSSS PP \t "+
|
||||
" AA AA SSSSS PP "; // ASP. Centered.
|
||||
String line = "\n\n--------------------------------------------------------------------------------\n\n"; // Flush.
|
||||
System.out.print(star); // Print the star
|
||||
System.out.print(line); // flush
|
||||
System.out.print(pine); // Print the pine
|
||||
System.out.print(line); // flush
|
||||
System.out.print(init); // initals
|
||||
System.out.print("\n\n"); // don't need another line.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
=================================================================================================================================
|
||||
|
||||
S:\programs\Mod1\Project1>java Project1aDub
|
||||
* *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* * * * * * * * * * * *
|
||||
|
||||
* * * * * * * * * *
|
||||
|
||||
* * * * * * * * * * * *
|
||||
|
||||
* * * * * *
|
||||
|
||||
* *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# #
|
||||
|
||||
# # # #
|
||||
|
||||
# # # # # #
|
||||
|
||||
# # # # # # # #
|
||||
|
||||
# #
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
AAA SSSSS PPPPPP AAA SSSSS PPPPPP
|
||||
AAAAA SS PP PP AAAAA SS PP PP
|
||||
AA AA SSSSS PPPPPP AA AA SSSSS PPPPPP
|
||||
AAAAAAA SS PP AAAAAAA SS PP
|
||||
AA AA SSSSS PP AA AA SSSSS PP
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 2a *
|
||||
* Class Name: Project2a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/15/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, use comments to document the software, *
|
||||
* use imported software components, instantiante objects, *
|
||||
* use methods associated with objects of prebuilt classes, *
|
||||
* use of user friendly prompts, echos, and error messages, *
|
||||
* use try and catch to prevent hard software crashes. *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Project2a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner(System.in); // direction 1
|
||||
/* begin direction 2 */
|
||||
int iWholeNum01 = 0;
|
||||
try
|
||||
{
|
||||
System.out.print("Please input a whole number: "); // user friendly prompt
|
||||
iWholeNum01 = console.nextInt(); // grab user input
|
||||
System.out.println("Your number was: " + iWholeNum01 +"\n"); // user friendly echo
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("\nWe're sorry, this was not a whole number.\n"+
|
||||
"Please re-run the program."); // (hopefully) user friendly error massage
|
||||
return; // end execution here. we want them to wisen up eh.
|
||||
}
|
||||
|
||||
/* begin direction 3 */
|
||||
double dRealNum01 = 0.0;
|
||||
try
|
||||
{
|
||||
System.out.print("Please input a decimal number: "); // user friendly prompt
|
||||
dRealNum01 = console.nextDouble(); // grab user input
|
||||
System.out.println("Your number was: " + dRealNum01 +"\n"); // user friendly echo
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("\nWe're sorry, this was not a real number.\n"+
|
||||
"Please re-run the program."); // (hopefully) user friendly error massage
|
||||
return; // end execution here. we want them to wisen up eh.
|
||||
}
|
||||
|
||||
/* begin direction 4 */
|
||||
String sFirstName = "";
|
||||
System.out.print("Please enter your First name: "); // user friendly prompt
|
||||
sFirstName = console.next(); // grab user input
|
||||
System.out.println("Your name is: " + sFirstName); // user friendly echo
|
||||
|
||||
// Done !
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project2>java Project2a
|
||||
Please input a whole number: 50
|
||||
Your number was: 50
|
||||
|
||||
Please input a decimal number: 25.0
|
||||
Your number was: 25.0
|
||||
|
||||
Please enter your First name: Amrit Panesar
|
||||
Your name is: Amrit
|
||||
|
||||
E:\programs\Mod1\Project2>java Project2a
|
||||
Please input a whole number: error
|
||||
|
||||
We're sorry, this was not a whole number.
|
||||
Please re-run the program.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,28 @@
|
||||
PROMPT for input of hours worked
|
||||
STORE hours worked
|
||||
CALCULATE gross pay
|
||||
grossPay = hours * rate
|
||||
CALCULATE tax
|
||||
Tax = gross * .14
|
||||
CALCULATE net pay
|
||||
netPay = gross – taxes
|
||||
CALCULATE clothing expense
|
||||
clothing = netPay * .10
|
||||
CALCULATE school supply expense
|
||||
supplies = netPay * .01
|
||||
CALCULATE remainder
|
||||
remainder = netPay – clothing – supplies
|
||||
CALCULATE student savings
|
||||
studentSavings = remainder * .25
|
||||
CALCULATE parental savings
|
||||
Parental savings = student Savings * .5
|
||||
DISPLAY pay rate
|
||||
DISPLAY hours
|
||||
DISPLAY gross pay
|
||||
DISPLAY taxes
|
||||
DISPLAY net pay
|
||||
DISPLAY clothing expense
|
||||
DISPLAY supply expense
|
||||
DISPLAY student savings
|
||||
DISPLAY parental savings
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 2b *
|
||||
* Class Name: SummerJob *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/23/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: To calculate the gross and net pay of a hypothetical summer *
|
||||
* job. The ability to deduct taxes is also demonstrated. *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SummerJob
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
final double HOURLY_WAGE = 15.50;// hourly wage
|
||||
final double PARENT_RATE = 0.50; // 50 cents per every *whole* dollar made.
|
||||
final double TAX_RATE = 0.14; // 14% taxes withheld
|
||||
final double CLOTHING_RATE = 0.10; // 10% for clothing
|
||||
final double SCHOOL_RATE = 0.01; // 01% for school supplies
|
||||
final double SAVINGS_RATE = 0.25; // 25% for savings bond purchase
|
||||
double dHoursWorked = 0.0;
|
||||
|
||||
//PROMPT for input of hours worked
|
||||
try
|
||||
{
|
||||
Scanner console = new Scanner(System.in);
|
||||
System.out.print("Please enter the ammount of hours worked: ");
|
||||
//STORE hours worked
|
||||
dHoursWorked = console.nextDouble();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("We're sorry, that was an invalid value.\n"
|
||||
+ "Please re-run the program.");
|
||||
return;
|
||||
}
|
||||
//CALCULATE gross pay
|
||||
//grossPay = hours * rate
|
||||
double dGrossPay = (dHoursWorked * HOURLY_WAGE);
|
||||
//CALCULATE tax
|
||||
//Tax = gross * .14
|
||||
double dTaxes = (dGrossPay * TAX_RATE);
|
||||
//CALCULATE net pay
|
||||
//netPay = gross – taxes
|
||||
double dNetPay = (dGrossPay - dTaxes);
|
||||
//CALCULATE clothing expense
|
||||
//clothing = netPay * .10
|
||||
double dCloExp = (dNetPay * CLOTHING_RATE);
|
||||
//CALCULATE school supply expense
|
||||
//supplies = netPay * .01
|
||||
double dSchExp = (dNetPay * SCHOOL_RATE);
|
||||
//CALCULATE remainder
|
||||
//remainder = netPay – clothing – supplies
|
||||
double dEODBal = (dNetPay - dCloExp - dSchExp);
|
||||
//CALCULATE student savings
|
||||
//studentSavings = remainder * .25
|
||||
double dSavBon = (int)(dEODBal * SAVINGS_RATE);
|
||||
//CALCULATE parental savings
|
||||
//Parental savings = student Savings * .5
|
||||
double dParSav = (dSavBon * PARENT_RATE);
|
||||
double dGTotal = (dEODBal + dSavBon + dParSav);
|
||||
|
||||
// System.out.format("%.2f", 10.499);
|
||||
//DISPLAY pay rate
|
||||
System.out.format("Your pay rate is: $%.2f per hour\n", dHourlyWage); // pay rate
|
||||
//DISPLAY hours
|
||||
System.out.format("You worked: %.2f hours\n", dHoursWorked); // hours
|
||||
//DISPLAY gross pay
|
||||
System.out.format("Your taxable income is: $%.2f\n", dGrossPay); // gross pay
|
||||
//DISPLAY taxes
|
||||
System.out.format("Taxes taken from your paycheck: $%.2f\n",dTaxes); // taxes
|
||||
//DISPLAY net pay
|
||||
System.out.format("Earning you a total of: $%.2f\n", dNetPay); // net pay
|
||||
System.out.format("------------------------------------------------------\n");
|
||||
//DISPLAY clothing expense
|
||||
System.out.format("Your withholdings for clothes expenses are: $%.2f\n", dCloExp);
|
||||
//DISPLAY supply expense
|
||||
System.out.format("Your withholdings for school supplies are: $%.2f\n", dSchExp);
|
||||
//DISPLAY student savings
|
||||
System.out.format("Your withholdings for a saving bond are: $%.2f\n", dSavBon);
|
||||
System.out.format("------------------------------------------------------\n");
|
||||
//DISPLAY parental savings
|
||||
System.out.format("Your parental contributions for this month are: $%.2f\n", dParSav);
|
||||
System.out.format("Giving you a grand total of: %.2f\n", dGTotal);
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 10
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 10.00 hours
|
||||
Your taxable income is: $155.00
|
||||
Taxes taken from your paycheck: $21.70
|
||||
Earning you a total of: $133.30
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $13.33
|
||||
Your withholdings for school supplies are: $1.33
|
||||
Your withholdings for a saving bond are: $29.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $14.50
|
||||
Giving you a grand total of: 162.14
|
||||
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 20
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 20.00 hours
|
||||
Your taxable income is: $310.00
|
||||
Taxes taken from your paycheck: $43.40
|
||||
Earning you a total of: $266.60
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $26.66
|
||||
Your withholdings for school supplies are: $2.67
|
||||
Your withholdings for a saving bond are: $59.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $29.50
|
||||
Giving you a grand total of: 325.77
|
||||
|
||||
E:\programs\Mod1\Project2>java SummerJob
|
||||
Please enter the ammount of hours worked: 40
|
||||
Your pay rate is: $15.50 per hour
|
||||
You worked: 40.00 hours
|
||||
Your taxable income is: $620.00
|
||||
Taxes taken from your paycheck: $86.80
|
||||
Earning you a total of: $533.20
|
||||
------------------------------------------------------
|
||||
Your withholdings for clothes expenses are: $53.32
|
||||
Your withholdings for school supplies are: $5.33
|
||||
Your withholdings for a saving bond are: $118.00
|
||||
------------------------------------------------------
|
||||
Your parental contributions for this month are: $59.00
|
||||
Giving you a grand total of: 651.55
|
||||
*/
|
||||
Binary file not shown.
Whitespace-only changes.
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3b *
|
||||
* Class Name: DecFormat *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class DecFormat
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
DecimalFormat df3Pos = new DecimalFormat("#####,00.000"); //2a
|
||||
DecimalFormat df5Pos = new DecimalFormat("#######,00.0000"); //2b
|
||||
|
||||
double dLarge01 = 0.1535012260547;
|
||||
|
||||
System.out.println("dLarge01 formatted to 3 places: "
|
||||
+ df3Pos.format(dLarge01)); //2c
|
||||
|
||||
System.out.println("dLarge01 formatted to 5 places: "
|
||||
+ df5Pos.format(dLarge01)); //2c
|
||||
}
|
||||
}
|
||||
/* output:
|
||||
E:\programs\Mod1\Project3>java DecFormat
|
||||
dLarge01 formatted to 3 places: 00.154
|
||||
dLarge01 formatted to 5 places: 00.1535
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3c *
|
||||
* Class Name: JOptPane *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 0.25 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*; //3
|
||||
|
||||
public class JOptPane //3
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String input = JOptionPane.showInputDialog("Please enter a whole number."); //3a
|
||||
int iInt01;
|
||||
try
|
||||
{
|
||||
iInt01 = Integer.parseInt(input); //3b
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
//3c
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Your number was: "+iInt01,
|
||||
"Success", JOptionPane.INFORMATION_MESSAGE);// 3d
|
||||
|
||||
/*--double time--*/
|
||||
input = JOptionPane.showInputDialog("Please enter a decimal number."); //3e
|
||||
double dReal01;
|
||||
try
|
||||
{
|
||||
dReal01 = Double.parseDouble(input); //3f
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
//3g
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Your number was: "+dReal01,
|
||||
"Success", JOptionPane.INFORMATION_MESSAGE);// 3d
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3a *
|
||||
* Class Name: Project3a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/20/2012 *
|
||||
* Hours: 1.00 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
public class Project3a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
int iNum01 = 1337; //1a
|
||||
int iNum02 = 42; //1a
|
||||
|
||||
double dPow = Math.pow(iNum01, iNum02); //1b1
|
||||
double dSqrt = Math.sqrt(iNum01); //1b2
|
||||
|
||||
System.out.println("The first number is: "+iNum01+".");
|
||||
System.out.println("The second number is: "+iNum02+".");
|
||||
System.out.println(""+iNum01+" raised to the power of "+iNum02+" is: "
|
||||
+ dPow+"."); //1b1
|
||||
System.out.println("The square root of "+iNum01+" is: "+dSqrt+".\n");//1b2
|
||||
|
||||
if (dPow >= dSqrt) //1b3
|
||||
{
|
||||
System.out.println("The first number ("+iNum01+") raised to the "
|
||||
+"second number ("+iNum02+") \nis greater than the square "
|
||||
+"root of ("+iNum01+")."); //1b3
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("The square root of "+iNum01+" is greater than"
|
||||
+ "the first number("+iNum01+") raised to the second number"
|
||||
+ "("+iNum02+")."); //1b3
|
||||
}
|
||||
System.out.println("\n---------------------------------------------\n");
|
||||
|
||||
double dRad = 7; //1b4
|
||||
double dDia = 7*2; //1b4
|
||||
double dArea = Math.PI*(Math.pow(dRad, 2)); //1b4
|
||||
|
||||
System.out.println("Circle's Radius: "+ dRad + "."); //1b4
|
||||
System.out.println("Circle's Diameter: " + dDia + "."); //1b4
|
||||
System.out.println("Circle's Area: "+ dArea + "."); //1b4
|
||||
|
||||
System.out.println("\n---------------------------------------------\n");
|
||||
|
||||
String sQuote= "Now is the time for all good men to come to the aid of "
|
||||
+ "their country."; //1c
|
||||
|
||||
System.out.println("The ammount of characters in the quote \n"
|
||||
+ "\""+sQuote+"\" \nis: "+sQuote.length()+".\n"); //1c1
|
||||
|
||||
System.out.println("The same quote in all caps is: \n"
|
||||
+ "\""+sQuote.toUpperCase()+"\"\n"); //1c2
|
||||
|
||||
System.out.println("The same quote in lower case is: \n"
|
||||
+ "\""+sQuote.toLowerCase()+"\"\n"); //1c3
|
||||
|
||||
System.out.println("The first index of the character 'o' is: "
|
||||
+ sQuote.indexOf('o')+"\n"); //1c4
|
||||
|
||||
System.out.println("The next index of the character 'o' is: "
|
||||
+ sQuote.indexOf('o',(sQuote.indexOf('o')+1))+"\n"); //1c5
|
||||
|
||||
System.out.println("The character present at index 17 is a(n) '"
|
||||
+ sQuote.charAt(17) + "'.\n"); //1c6
|
||||
|
||||
String sSubstr = sQuote.substring(sQuote.indexOf('t'),
|
||||
(sQuote.length()-1)); //1c7
|
||||
|
||||
System.out.println("The substring of the quote from the first instence "
|
||||
+ "of the character 't' \nto the last character, not including "
|
||||
+ "a period is: \n\""+sSubstr+"\""); //1c8
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
E:\programs\Mod1\Project3>java Project3a
|
||||
The first number is: 1337.
|
||||
The second number is: 42.
|
||||
1337 raised to the power of 42 is: 1.983896928320167E131.
|
||||
The square root of 1337 is: 36.565010597564445.
|
||||
|
||||
The first number (1337) raised to the second number (42)
|
||||
is greater than the square root of (1337).
|
||||
|
||||
---------------------------------------------
|
||||
|
||||
Circle's Radius: 7.0.
|
||||
Circle's Diameter: 14.0.
|
||||
Circle's Area: 153.93804002589985.
|
||||
|
||||
---------------------------------------------
|
||||
|
||||
The ammount of characters in the quote
|
||||
"Now is the time for all good men to come to the aid of their country."
|
||||
is: 69.
|
||||
|
||||
The same quote in all caps is:
|
||||
"NOW IS THE TIME FOR ALL GOOD MEN TO COME TO THE AID OF THEIR COUNTRY."
|
||||
|
||||
The same quote in lower case is:
|
||||
"now is the time for all good men to come to the aid of their country."
|
||||
|
||||
The first index of the character 'o' is: 1
|
||||
|
||||
The next index of the character 'o' is: 17
|
||||
|
||||
The character present at index 17 is a(n) 'o'.
|
||||
|
||||
The substring of the quote from the first instence of the character 't'
|
||||
to the last character, not including a period is:
|
||||
"the time for all good men to come to the aid of their country"
|
||||
*/
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 3d *
|
||||
* Class Name: TempCon *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 08/23/2012 *
|
||||
* Hours: 1.50 Hours *
|
||||
* Purpose: To demonstrate the ability to create a conventionally named *
|
||||
* java application, the parsing of numeric strings with *
|
||||
* exception handling, format numeric output using Decimal *
|
||||
* Format, write to and read from a simple text file, use Decimal*
|
||||
* Format to format output *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TempCon
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sCity = JOptionPane.showInputDialog("Please enter a city."); //4a
|
||||
sCity = sCity.toUpperCase();//4b
|
||||
|
||||
String sDate = JOptionPane.showInputDialog("Please enter a date, mm/dd/yyyy."); //4c
|
||||
|
||||
String sTemp = JOptionPane.showInputDialog("Please enter a temperature in Fahrenheit."); //4d
|
||||
double dTemp = 0;
|
||||
try
|
||||
{
|
||||
dTemp = Double.parseDouble(sTemp);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+dTemp+"\" was an invalid input"
|
||||
+"Please re-run the application.", "Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
double dTempc = (dTemp - 32) * (5.0/9.0);
|
||||
String sTempc = String.format("%.2f", dTempc);
|
||||
|
||||
PrintWriter outFile = null;
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
outFile = new PrintWriter("tempfile.dat");
|
||||
inFile = new Scanner(new FileReader("tempfile.dat"));
|
||||
String sOut = "Temperature for: "+sCity+"\non: "+sDate+"\n"
|
||||
+dTemp+"\u00B0 Fahrenheit\n"+sTempc+"\u00B0 Celsius.";
|
||||
String sIn = "";
|
||||
|
||||
outFile.append(sOut);
|
||||
outFile.flush();
|
||||
sIn = inFile.nextLine() + "\n" + inFile.nextLine() + "\n" +
|
||||
inFile.nextLine() + "\n" + inFile.nextLine();
|
||||
|
||||
JOptionPane.showMessageDialog(null,sIn, "Temperature for: "+sCity,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, please make a file named "
|
||||
+"Tempfile.dat", "Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, caught an I/o exception "
|
||||
,"Fatal Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
outFile.close();
|
||||
inFile.close();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
Temperature for: EL CAJON
|
||||
on: 01/10/1990
|
||||
-212.0° Fahrenheit
|
||||
-135.56° Celsius.
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4a *
|
||||
* Class Name: Project4a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
Scanner console = new Scanner(System.in);
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("Invalid input \""+cStatus+"\", please re-run the program");
|
||||
System.exit(0);
|
||||
}
|
||||
if (cStatus != 'm')
|
||||
System.out.println("You are filing as Single");
|
||||
else
|
||||
System.out.println("You are filing as Married");
|
||||
}
|
||||
}
|
||||
|
||||
/* Output:
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as Married
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
h
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project 4>java Project4a
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
4
|
||||
Invalid input "4", please re-run the program
|
||||
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4b *
|
||||
* Class Name: Project4b *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4b
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
System.out.println("Are you (M)arried (H)ead of Household (E)xempt "
|
||||
+ "or (S)ingle?");
|
||||
Scanner console = new Scanner(System.in);
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("You have elected for exempt status");
|
||||
System.exit(0);
|
||||
}
|
||||
if (cStatus == 'm')
|
||||
System.out.println("You are filing as Married");
|
||||
else if (cStatus == 's')
|
||||
System.out.println("You are filing as Single");
|
||||
else if (cStatus == 'h')
|
||||
System.out.println("You are filing as Head of Household");
|
||||
}
|
||||
|
||||
}
|
||||
/* output:
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
m
|
||||
You are filing as Married
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
head of household
|
||||
You are filing as Head of Household
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
s
|
||||
You are filing as Single
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4b
|
||||
Are you (M)arried (H)ead of Household (E)xempt or (S)ingle?
|
||||
4
|
||||
You have elected for exempt status
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4c *
|
||||
* Class Name: Project4c *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4c
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in);
|
||||
System.out.println("How many withholdings do you have?");
|
||||
int iWHold = 0;
|
||||
String input = console.next();
|
||||
try
|
||||
{
|
||||
iWHold = Integer.parseInt(input);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//input has been sanitized.
|
||||
int iHVal = 0;
|
||||
switch (iWHold)
|
||||
{
|
||||
case 1:
|
||||
iHVal = 42;
|
||||
break;
|
||||
case 2:
|
||||
iHVal = 83;
|
||||
break;
|
||||
case 3:
|
||||
iHVal = 125;
|
||||
break;
|
||||
case 4:
|
||||
iHVal = 167;
|
||||
break;
|
||||
case 5:
|
||||
iHVal = 208;
|
||||
break;
|
||||
case 6:
|
||||
iHVal = 250;
|
||||
break;
|
||||
case 7:
|
||||
iHVal = 292;
|
||||
break;
|
||||
case 8:
|
||||
iHVal = 333;
|
||||
break;
|
||||
case 9:
|
||||
iHVal = 375;
|
||||
break;
|
||||
case 10:
|
||||
iHVal = 417;
|
||||
break;
|
||||
default:
|
||||
iHVal = iWHold * 42;
|
||||
break;
|
||||
}
|
||||
System.out.println (iWHold + " withholding allowances provides an "
|
||||
+ "estimated deduction of: $" +iHVal);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*output:
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
1
|
||||
1 withholding allowances provides an estimated deduction of: $42
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
1024
|
||||
1024 withholding allowances provides an estimated deduction of: $43008
|
||||
|
||||
E:\programs\Mod1\Project4>java Project4c
|
||||
How many withholdings do you have?
|
||||
5
|
||||
5 withholding allowances provides an estimated deduction of: $208
|
||||
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4d *
|
||||
* Class Name: Project4d *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4d
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in);
|
||||
System.out.println("What is your gross pay?");
|
||||
double dGross = 0;
|
||||
String input = console.next();
|
||||
try
|
||||
{
|
||||
dGross = Double.parseDouble(input);k
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("How many withholdings do you have?");
|
||||
int iWHold = 0;
|
||||
input = console.next();
|
||||
try
|
||||
{
|
||||
iWHold = Integer.parseInt(input);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
if (iWHold < 0)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
String sInput = console.next();
|
||||
char cStatus = sInput.toLowerCase().charAt(0);
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's')
|
||||
{
|
||||
System.out.println("We're sorry, \""+cStatus+"\", was an invalid"
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
boolean bLowInc = false;
|
||||
if ((cStatus == 's' && dGross <= 522) ||
|
||||
(cStatus == 'm' && dGross <= 522 && iWHold <=1 ) ||
|
||||
(cStatus == 'm' && dGross <= 1044 && iWHold >=2 ) ||
|
||||
(cStatus == 'h' && dGross <= 1044))
|
||||
{
|
||||
bLowInc = true;
|
||||
}
|
||||
switch (cStatus)
|
||||
{
|
||||
case 's':
|
||||
System.out.println("You are filing as single.");
|
||||
break;
|
||||
case 'm':
|
||||
System.out.println("You are filing as married.");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("You are filing as head of household.");
|
||||
break;
|
||||
}
|
||||
if (bLowInc)
|
||||
System.out.println("You ARE classified as low income");
|
||||
else
|
||||
System.out.println("You are NOT classified as low income");
|
||||
}
|
||||
}
|
||||
/* Output
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1043
|
||||
How many withholdings do you have?
|
||||
1
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1043
|
||||
How many withholdings do you have?
|
||||
1
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1044
|
||||
How many withholdings do you have?
|
||||
2
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You ARE classified as low income
|
||||
|
||||
F:\programs\Mod1\Project4>java Project4d
|
||||
What is your gross pay?
|
||||
1045
|
||||
How many withholdings do you have?
|
||||
3
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as married.
|
||||
You are NOT classified as low income
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,214 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 4e *
|
||||
* Class Name: Project4e *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/10/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: Evaluate the input of a char representing the taxpayer's *
|
||||
* filing status and reporting weather the taxpayer will be *
|
||||
* taxed as a single or married person. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Project4e
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
System.out.println("What is your gross pay?");
|
||||
double dGross = 0;
|
||||
String input = console.next(); //grab a string
|
||||
try
|
||||
{
|
||||
dGross = Double.parseDouble(input); // parse it
|
||||
}
|
||||
catch (NumberFormatException nfe) // bomb if it doesn't validate
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
if (dGross < 0)
|
||||
{
|
||||
System.out.println("We're sorry, \""+input+"\" was an invalid "
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println("Are you (M)arried (H)ead of Household or "
|
||||
+ "(S)ingle?");
|
||||
String sInput = console.next(); // grab a string
|
||||
char cStatus = sInput.toLowerCase().charAt(0); // make it lowercase, grab the first character
|
||||
if (cStatus != 'm' && cStatus != 'h' && cStatus != 's') //only need to handle these
|
||||
{
|
||||
System.out.println("We're sorry, \""+cStatus+"\", was an invalid"
|
||||
+ "input. Please re-run the program.");
|
||||
System.exit(0);
|
||||
}
|
||||
double dBase = 0, dExcess = 0, dPercent = 0;
|
||||
if (cStatus == 's' || cStatus == 'h' ) {
|
||||
if (dGross <= 90)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.00;
|
||||
dExcess = 0.00;
|
||||
}
|
||||
else if (dGross > 90 && dGross <=452)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.10;
|
||||
dExcess = 90.00;
|
||||
}
|
||||
else if (dGross > 452 && dGross <= 1563)
|
||||
{
|
||||
dBase = 36.20;
|
||||
dPercent = 0.15;
|
||||
dExcess = 452.00;
|
||||
}
|
||||
else if (dGross > 1563 && dGross <= 3658)
|
||||
{
|
||||
dBase = 202.85;
|
||||
dPercent = 0.25;
|
||||
dExcess = 1563.00;
|
||||
}
|
||||
else if (dGross > 3658 && dGross <= 7533)
|
||||
{
|
||||
dBase = 276.60;
|
||||
dPercent = 0.28;
|
||||
dExcess = 3658.00;
|
||||
}
|
||||
else if (dGross > 7533 && dGross <= 16271)
|
||||
{
|
||||
dBase = 4695.14;
|
||||
dPercent = 0.33;
|
||||
dExcess = 7533.00;
|
||||
}
|
||||
else if (dGross > 16271)
|
||||
{
|
||||
dBase = 4695.14;
|
||||
dPercent = 0.35;
|
||||
dExcess = 16271.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
else if (cStatus == 'm')
|
||||
{
|
||||
if (dGross <= 338)
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.00;
|
||||
dExcess = 0.00;
|
||||
}
|
||||
else if (dGross > 338 && dGross <=1063 )
|
||||
{
|
||||
dBase = 0.00;
|
||||
dPercent = 0.10;
|
||||
dExcess = 338.00;
|
||||
}
|
||||
else if (dGross > 1063 && dGross <= 3283)
|
||||
{
|
||||
dBase = 72.50;
|
||||
dPercent = 0.15;
|
||||
dExcess = 1063.00;
|
||||
}
|
||||
else if (dGross > 3283 && dGross <= 6283)
|
||||
{
|
||||
dBase = 405.50;
|
||||
dPercent = 0.25;
|
||||
dExcess = 3283.00;
|
||||
}
|
||||
else if (dGross > 6283 && dGross <= 9398)
|
||||
{
|
||||
dBase = 1155.50;
|
||||
dPercent = 0.28;
|
||||
dExcess = 6283.00;
|
||||
}
|
||||
else if (dGross > 9398 && dGross <= 16519)
|
||||
{
|
||||
dBase = 2027.70;
|
||||
dPercent = 0.33;
|
||||
dExcess = 9398.00;
|
||||
}
|
||||
else if (dGross > 16519 )
|
||||
{
|
||||
dBase = 4377.63;
|
||||
dPercent = 0.35;
|
||||
dExcess = 16519.00;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Illogical.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
double dFed = dBase + ((dGross - dExcess) * dPercent);
|
||||
|
||||
switch (cStatus)
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("You are filing as: Married");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("You are filing as: Single");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("You are filing as: Head of Household");
|
||||
break;
|
||||
}
|
||||
System.out.printf("You gross income is: $%.2f\n", dGross);
|
||||
System.out.printf("Therefore, your base tax is: $%.2f\n", dBase);
|
||||
System.out.printf("Your tax surcharge percentage is: %%%.2f\n", (dPercent*100));
|
||||
// System.out.printf("%s + ((%s - %s) * (%s/100)\n", dBase, dGross, dExcess, (dPercent*100)); // debugging.
|
||||
System.out.printf("Your withholding tax is: $%.2f\n", dFed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
31415
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as: Single
|
||||
You gross income is: $31415.00
|
||||
Therefore, your base tax is: $4695.14
|
||||
Your tax surcharge percentage is: %35.00
|
||||
Your withholding tax is: $9995.54
|
||||
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
1231
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
s
|
||||
You are filing as: Single
|
||||
You gross income is: $1231.00
|
||||
Therefore, your base tax is: $36.20
|
||||
Your tax surcharge percentage is: %15.00
|
||||
Your withholding tax is: $153.05
|
||||
|
||||
S:\programs\Mod1\Project4>java Project4e
|
||||
What is your gross pay?
|
||||
555555
|
||||
Are you (M)arried (H)ead of Household or (S)ingle?
|
||||
m
|
||||
You are filing as: Married
|
||||
You gross income is: $555555.00
|
||||
Therefore, your base tax is: $4377.63
|
||||
Your tax surcharge percentage is: %35.00
|
||||
Your withholding tax is: $193040.23
|
||||
*/
|
||||
Binary file not shown.
@@ -0,0 +1,55 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5a *
|
||||
* Class Name: Project5a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5a
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
String sSent = "";
|
||||
Scanner inFile = null;
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
String temp = "";
|
||||
while (!sSent.equals("!q"))
|
||||
{
|
||||
System.out.println("Enter a name, type !q to quit");
|
||||
temp = console.nextLine();
|
||||
sSent = temp;
|
||||
System.out.println(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5a
|
||||
Enter a name, type !q to quit
|
||||
Blah
|
||||
Blah
|
||||
Enter a name, type !q to quit
|
||||
hjsdalkf
|
||||
hjsdalkf
|
||||
Enter a name, type !q to quit
|
||||
Neo Anderson
|
||||
Neo Anderson
|
||||
Enter a name, type !q to quit
|
||||
!q
|
||||
!q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,117 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5b *
|
||||
* Class Name: Project5b *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5b
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
inFile = new Scanner(new FileReader("payrollData.txt"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
for (int i=0;i<5;i++)
|
||||
{
|
||||
int iEmployee = inFile.nextInt();
|
||||
char cFiling = inFile.next().charAt(0);
|
||||
int iWHold = inFile.nextInt();
|
||||
char cClass = inFile.next().charAt(0);
|
||||
double dHours = inFile.nextDouble();
|
||||
double dPayR = inFile.nextDouble();
|
||||
double dSal = inFile.nextDouble();
|
||||
double dYTD = inFile.nextDouble();
|
||||
String sFOut = "";
|
||||
String sCout = "";
|
||||
|
||||
|
||||
if (cFiling == 's')
|
||||
{
|
||||
sFOut = "Single";
|
||||
}
|
||||
else if (cFiling == 'h' )
|
||||
{
|
||||
sFOut = "Head of Household";
|
||||
}
|
||||
else if (cFiling == 'm')
|
||||
{
|
||||
sFOut = "Married";
|
||||
}
|
||||
else
|
||||
{
|
||||
sFOut = "Illogical.";
|
||||
}
|
||||
|
||||
if (cClass == 'h')
|
||||
{
|
||||
sCout = "Hourly";
|
||||
}
|
||||
else if (cClass == 's')
|
||||
{
|
||||
sCout = "Salary";
|
||||
}
|
||||
else
|
||||
{
|
||||
sCout = "Illigocial.";
|
||||
}
|
||||
|
||||
String out = "Employee Number: "+ iEmployee + "\t" +
|
||||
"Filing as: "+ sFOut + "\t" +
|
||||
"Number of Withholdings: "+iWHold+ "\t"+
|
||||
"Pay Type: "+sCout + "\t";
|
||||
if (cClass == 'h')
|
||||
{
|
||||
out += "Hours Worked: "+ dHours +"\t"+
|
||||
"Pay Rate: " + dPayR + "\t";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out += "Salary: " + dSal + "\t";
|
||||
}
|
||||
out += "Year To Date: " + dYTD + "\t";
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5b
|
||||
Employee Number: 1001 Filing as: Single Number of Withholdings: 11
|
||||
Pay Type: Hourly Hours Worked: 40.0 Pay Rate: 15.35 Year To Date: 12
|
||||
28.0
|
||||
Employee Number: 1002 Filing as: Single Number of Withholdings: 10
|
||||
Pay Type: Hourly Hours Worked: 38.0 Pay Rate: 15.0 Year To Date: 57
|
||||
0.0
|
||||
Employee Number: 1003 Filing as: Single Number of Withholdings: 9
|
||||
Pay Type: Hourly Hours Worked: 26.45 Pay Rate: 20.0 Year To Date: 10
|
||||
58.0
|
||||
Employee Number: 1004 Filing as: Single Number of Withholdings: 8
|
||||
Pay Type: Hourly Hours Worked: 20.0 Pay Rate: 39.15 Year To Date: 23
|
||||
49.0
|
||||
Employee Number: 1005 Filing as: Single Number of Withholdings: 7
|
||||
Pay Type: Hourly Hours Worked: 37.15 Pay Rate: 20.0 Year To Date: 14
|
||||
86.0
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5c *
|
||||
* Class Name: Project5c *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5c
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner inFile = null;
|
||||
try
|
||||
{
|
||||
inFile = new Scanner(new FileReader("payrollData.txt"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
while(inFile.hasNext())
|
||||
{
|
||||
int iEmployee = inFile.nextInt();
|
||||
char cFiling = inFile.next().charAt(0);
|
||||
int iWHold = inFile.nextInt();
|
||||
char cClass = inFile.next().charAt(0);
|
||||
double dHours = inFile.nextDouble();
|
||||
double dPayR = inFile.nextDouble();
|
||||
double dSal = inFile.nextDouble();
|
||||
double dYTD = inFile.nextDouble();
|
||||
String sFOut = "";
|
||||
String sCout = "";
|
||||
|
||||
|
||||
if (cFiling == 's')
|
||||
{
|
||||
sFOut = "Single";
|
||||
}
|
||||
else if (cFiling == 'h' )
|
||||
{
|
||||
sFOut = "Head of Household";
|
||||
}
|
||||
else if (cFiling == 'm')
|
||||
{
|
||||
sFOut = "Married";
|
||||
}
|
||||
else
|
||||
{
|
||||
sFOut = "Illogical.";
|
||||
}
|
||||
|
||||
if (cClass == 'h')
|
||||
{
|
||||
sCout = "Hourly";
|
||||
}
|
||||
else if (cClass == 's')
|
||||
{
|
||||
sCout = "Salary";
|
||||
}
|
||||
else
|
||||
{
|
||||
sCout = "Illigocial.";
|
||||
}
|
||||
|
||||
String out = "Employee Number: "+ iEmployee + "\t" +
|
||||
"Filing as: "+ sFOut + "\t" +
|
||||
"Number of Withholdings: "+iWHold+ "\t"+
|
||||
"Pay Type: "+sCout + "\t";
|
||||
if (cClass == 'h')
|
||||
{
|
||||
out += "Hours Worked: "+ dHours +"\t"+
|
||||
"Pay Rate: " + dPayR + "\t";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out += "Salary: " + dSal + "\t";
|
||||
}
|
||||
out += "Year To Date: " + dYTD + "\t";
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5c
|
||||
Employee Number: 1001 Filing as: Single Number of Withholdings: 11
|
||||
Pay Type: Hourly Hours Worked: 40.0 Pay Rate: 15.35 Year To Date: 12
|
||||
28.0
|
||||
Employee Number: 1002 Filing as: Single Number of Withholdings: 10
|
||||
Pay Type: Hourly Hours Worked: 38.0 Pay Rate: 15.0 Year To Date: 57
|
||||
0.0
|
||||
Employee Number: 1003 Filing as: Single Number of Withholdings: 9
|
||||
Pay Type: Hourly Hours Worked: 26.45 Pay Rate: 20.0 Year To Date: 10
|
||||
58.0
|
||||
Employee Number: 1004 Filing as: Single Number of Withholdings: 8
|
||||
Pay Type: Hourly Hours Worked: 20.0 Pay Rate: 39.15 Year To Date: 23
|
||||
49.0
|
||||
Employee Number: 1005 Filing as: Single Number of Withholdings: 7
|
||||
Pay Type: Hourly Hours Worked: 37.15 Pay Rate: 20.0 Year To Date: 14
|
||||
86.0
|
||||
Employee Number: 1006 Filing as: Single Number of Withholdings: 6
|
||||
Pay Type: Hourly Hours Worked: 55.35 Pay Rate: 20.0 Year To Date: 55
|
||||
35.0
|
||||
Employee Number: 1007 Filing as: Single Number of Withholdings: 5
|
||||
Pay Type: Hourly Hours Worked: 53.3 Pay Rate: 20.0 Year To Date: 10
|
||||
66.0
|
||||
Employee Number: 1008 Filing as: Single Number of Withholdings: 4
|
||||
Pay Type: Salary Salary: 1430.0 Year To Date: 14300.0
|
||||
Employee Number: 1009 Filing as: Single Number of Withholdings: 3
|
||||
Pay Type: Salary Salary: 1389.0 Year To Date: 13890.0
|
||||
Employee Number: 1010 Filing as: Single Number of Withholdings: 2
|
||||
Pay Type: Salary Salary: 1777.0 Year To Date: 15993.0
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,78 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5d *
|
||||
* Class Name: Project5d *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5d
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
boolean bSent = true;
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
while (bSent)
|
||||
{
|
||||
System.out.println("Please enter either 'M', 'H', 'S', or 'E' "
|
||||
+ "to find out more about that filing type, or enter"
|
||||
+ " any other character to quit.");
|
||||
System.out.print(":");
|
||||
switch (console.next().toLowerCase().charAt(0))
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("Married");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("Head of Household");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("Single");
|
||||
break;
|
||||
case 'e':
|
||||
System.out.println("Exempt");
|
||||
break;
|
||||
default:
|
||||
bSent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5d
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:m
|
||||
Married
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:h
|
||||
Head of Household
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:s
|
||||
Single
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:e
|
||||
Exempt
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,77 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 5e *
|
||||
* Class Name: Project5e *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 10/04/2012 *
|
||||
* Hours: 0.20 Hours *
|
||||
* Purpose: demonstrate proficiency in using Counted loops, proficiency in*
|
||||
* using Sentinel controlled loops, proficiency in using Flag *
|
||||
* controlled loops, proficiency in using EOF controlled loops, *
|
||||
* proficiency in using Forever loops, providing appropriate *
|
||||
* documentation for programs, the use of conventional *
|
||||
* identifiers for classes and variables, the ability to use *
|
||||
* simple program testing techniques to ensure the quality of *
|
||||
* their work product, the use of white space for ensuring *
|
||||
* readability of program code, correct formulation of boolean *
|
||||
* expressions to be used in the control of iterative structures *
|
||||
******************************************************************************/
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Project5e
|
||||
{
|
||||
public static void main(String[] args) // main
|
||||
{
|
||||
Scanner console = new Scanner (System.in); //console
|
||||
out:
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Please enter either 'M', 'H', 'S', or 'E' "
|
||||
+ "to find out more about that filing type, or enter"
|
||||
+ " any other character to quit.");
|
||||
System.out.print(":");
|
||||
switch (console.next().toLowerCase().charAt(0))
|
||||
{
|
||||
case 'm':
|
||||
System.out.println("Married");
|
||||
break;
|
||||
case 'h':
|
||||
System.out.println("Head of Household");
|
||||
break;
|
||||
case 's':
|
||||
System.out.println("Single");
|
||||
break;
|
||||
case 'e':
|
||||
System.out.println("Exempt");
|
||||
break;
|
||||
default:
|
||||
break out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*output:
|
||||
|
||||
E:\programs\Mod1\Project5>java Project5e
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:m
|
||||
Married
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:h
|
||||
Head of Household
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:s
|
||||
Single
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:e
|
||||
Exempt
|
||||
Please enter either 'M', 'H', 'S', or 'E' to find out more about that filing typ
|
||||
e, or enter any other character to quit.
|
||||
:q
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
1001 s 11 h 40 15.35 0 1228
|
||||
1002 s 10 h 38 15 0 570
|
||||
1003 s 9 h 26.45 20 0 1058
|
||||
1004 s 8 h 20 39.15 0 2349
|
||||
1005 s 7 h 37.15 20 0 1486
|
||||
1006 s 6 h 55.35 20 0 5535
|
||||
1007 s 5 h 53.3 20 0 1066
|
||||
1008 s 4 s 0 0 1430 14300
|
||||
1009 s 3 s 0 0 1389 13890
|
||||
1010 s 2 s 0 0 1777 15993
|
||||
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* Project: Project 6a *
|
||||
* Class Name: Project6a *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/17/2012 *
|
||||
* Hours: 1.00 Hours *
|
||||
* Purpose: To do things because Charlie tells us to d *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Project6a
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
double dNum1, dNum2;
|
||||
try
|
||||
{
|
||||
input = JOptionPane.showInputDialog("Please enter your first number.");
|
||||
dNum1 = Double.parseDouble(input);
|
||||
input = JOptionPane.showInputDialog("Please enter your second number.");
|
||||
dNum2 = Double.parseDouble(input);
|
||||
}
|
||||
add(dNum1,dNum2);
|
||||
|
||||
}
|
||||
public static void add(double n1, double n2)
|
||||
{
|
||||
double result = n1 + n2;
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Adding your two numbers together yields: "+result,
|
||||
"Results",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class DbL3c
|
||||
// Demonstrates modulus and printing
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
double a = 99, b = 8, result;
|
||||
int c = (long) 7777777777777;
|
||||
result = a % b;
|
||||
System.out.println("Divide " + a + " by " + b);
|
||||
System.out.println("remainder is " + result);
|
||||
System.out.print("c is a very large number:");
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class BufferFinalOne
|
||||
{
|
||||
public static int words, lines, pgraf, curWords, curLB, read;
|
||||
public static BufferedReader infile;
|
||||
public static PrintWriter outfile;
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
initalize();
|
||||
while (read != -1)
|
||||
{
|
||||
while(read != '\u2424')
|
||||
{
|
||||
if (read == -1)
|
||||
break;
|
||||
char c = (char)read;
|
||||
if (Character.isWhitespace(c))
|
||||
processBlank(c);
|
||||
else
|
||||
processText(c);
|
||||
System.out.print(c+" ("+read+")");
|
||||
read = infile.read();
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
printTotal();
|
||||
}
|
||||
public static void initalize() throws FileNotFoundException, IOException
|
||||
{
|
||||
words = 0; lines = 0; pgraf = 0; curWords = 0; curLB=0;
|
||||
infile = new BufferedReader(new FileReader("inspectFile.dat"));
|
||||
outfile = new PrintWriter("outfile.txt");
|
||||
read = infile.read();
|
||||
}
|
||||
public static void processText(char c)
|
||||
{
|
||||
if (curLB!=0)
|
||||
curLB = 0;
|
||||
outfile.append(c);
|
||||
}
|
||||
public static void processBlank(char c)
|
||||
{
|
||||
if (curLB!=0)
|
||||
curLB = 0;
|
||||
outfile.append(c);
|
||||
curWords++;
|
||||
}
|
||||
public static void updateCount()
|
||||
{
|
||||
if (curLB == 1)
|
||||
pgraf++;
|
||||
words += curWords;
|
||||
curWords = 0;
|
||||
lines++;
|
||||
}
|
||||
public static void printTotal() throws IOException
|
||||
{
|
||||
System.out.print("words: "+words+" number of lines: "+lines+" paragraphs: "+pgraf);
|
||||
infile.close();
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
This is the first line of the first paragraph \n
|
||||
Second line in the paragraph\n
|
||||
|
||||
This is the second paragraph \n
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
This is the first line of the first paragraph \n
|
||||
Second line in the paragraph\n
|
||||
|
||||
This is the second paragraph \n
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/******************************************************************************
|
||||
* Project: Point 1 *
|
||||
* Class Name: point1 *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/05/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: Blah. *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class point1
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String sMessage01 = "This application will accept the input of the "
|
||||
+ "lengths of the sides of a triangle and determine if it is a right triangle.\n"
|
||||
+ "A triangle is a polygon with 3 sides and three angles.\n"
|
||||
+ "A triangle is considered right if one of the angles is 90 degrees.";
|
||||
String sMessage02 = "This program will determine weather or not a triangle is right.";
|
||||
|
||||
JOptionPane.showMessageDialog(null, sMessage01, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, sMessage02, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
String input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide01 = 0;
|
||||
try
|
||||
{
|
||||
dSide01 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide01 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide02 = 0;
|
||||
try
|
||||
{
|
||||
dSide02 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide02 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
input = JOptionPane.showInputDialog("Please enter a side length.");
|
||||
double dSide03 = 0;
|
||||
try
|
||||
{
|
||||
dSide03 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide03 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative side length.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
// big ugly boolean.
|
||||
// IF (intFirstSide * intFirstSide == intSecondSide * intSecondSide + intThirdSide * intThirdSide) ||
|
||||
// (intSecondSide * intSecondSide == intFirstSide * intFirstSide + intThirdSide * intThirdSide)||
|
||||
// (intThirdSide * intThirdSide == intFirstSide * intFirstSide + intSecondSide * intSecondSide)
|
||||
|
||||
dSide01 = Math.pow(dSide01, 2);
|
||||
dSide02 = Math.pow(dSide02, 2);
|
||||
dSide03 = Math.pow(dSide03, 2);
|
||||
if ((dSide01 == (dSide02 + dSide03)) ||
|
||||
(dSide02 == (dSide01 + dSide03)) ||
|
||||
(dSide03 == (dSide01 + dSide02)))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "This is a right triangle.",
|
||||
"Thank You", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "This is NOT a right triangle.",
|
||||
"Thank You", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Project: Point 2 *
|
||||
* Class Name: point2 *
|
||||
* Author: Amrit Panesar -ASP ,o/ *
|
||||
* Last Edited: 09/05/2012 *
|
||||
* Hours: 0.50 Hours *
|
||||
* Purpose: Blah. *
|
||||
******************************************************************************/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class point2
|
||||
{
|
||||
public static void main(String[] args) //main
|
||||
{
|
||||
String sMessage01 = "This application will accept the input of the "
|
||||
+ "ammount of cookies the user has to organize into boxes and containers.\n"
|
||||
+ "A box contains 24 cookies.\n"
|
||||
+ "A container contains 75 boxes.";
|
||||
String sMessage02 = "This program will output the ammount of boxes, containers, and the underflow.";
|
||||
JOptionPane.showMessageDialog(null, sMessage01, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, sMessage02, "Welcome",
|
||||
JOptionPane.PLAIN_MESSAGE);
|
||||
String input = JOptionPane.showInputDialog("Please enter the ammount of cookies.");
|
||||
double dSide01 = 0;
|
||||
try
|
||||
{
|
||||
dSide01 = Double.parseDouble(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, \""+input+"\" was"
|
||||
+ " an incorrect input.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
if (dSide01 < 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "We're sorry, you cannot have a "
|
||||
+ "negative ammount of cookies.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
String sOutMessage = "";
|
||||
Double dBoxes = dSide01 %24;
|
||||
Double dContainers = dBoxes %75;
|
||||
|
||||
int iContainers = (int) Math.floor(dContainers);
|
||||
if (dContainers > iContainers)
|
||||
iContainers++;
|
||||
|
||||
int iBoxes = (int) Math.floor(dBoxes);
|
||||
if (dBoxes > iBoxes)
|
||||
iBoxes++;
|
||||
|
||||
int iFullContainer = (int) Math.floor(dContainers);
|
||||
int iFullBoxes = iFullContainer * 75;
|
||||
int iLeftOverBoxes = iBoxes - iFullBoxes;
|
||||
int iLeftOverCookies = iLeftOverBoxes * 24;
|
||||
boolean bUnderFlow = false;
|
||||
|
||||
sOutMessage += "You have a total of %d boxes with %d containers.\n";
|
||||
if (iContainers > dContainers)
|
||||
{
|
||||
sOutMessage += "The last container is not full.\n";
|
||||
bUnderFlow = true;
|
||||
}
|
||||
|
||||
if(bUnderFlow)
|
||||
{
|
||||
sOutMessage += "You have %d boxes in the last container, with %d cookies.";
|
||||
System.out.format(sOutMessage, iBoxes, iContainers, iLeftOverBoxes, iLeftOverCookies);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.format(sOutMessage, iBoxes, iContainers);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user