Anda di halaman 1dari 97

MACHINE PROBLEMS | CSCI0209 LABORATORY Submitted by: Joe Marie Boco Earl Joshua Crisostomo Adrianne Eumague Marco

Paulo Soledad Submitted to: Mr. Christian Escoto

1. Write a program that will read two numbers from the keyboard and then print EQUAL if they are equal and NOT EQUAL if they are not. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package equality; import java.util.Scanner; public class Equality { public static void main(String[] args) { Scanner x = new Scanner (System.in); double a, b; System.out.println("Enter the first number:"); a = x.nextDouble(); System.out.println("Enter the second number:"); b = x.nextDouble(); if (a == b) { System.out.println("The two numbers you've entered are both equal."); } else System.out.println("The two numbers you've entered are both not equal to each other."); } }

Print screen output:

2. Write a program that determines if the input number is ODD or EVEN number. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package againsttheodds; import java.util.*; import java.io.*; public class AgainstTheOdds { public static void main(String[] args) throws IOException{ try{ int n; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter desired number:"); n = Integer.parseInt(in.readLine()); if (n % 2 == 0) { System.out.println("Given number is Even."); } else { System.out.println("Given number is Odd."); } } catch(NumberFormatException e){ System.out.println(e.getMessage() + " is not a numeric value."); System.exit(0); } } }

Print screen output:

3. Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package positiveornegative; import java.util.Scanner; public class PositiveorNegative { public static void main(String[] args) { Scanner x = new Scanner (System.in); int no; System.out.println("Enter desired number:"); no = x.nextInt(); if(no>0) { System.out.println("The given number" + no + "is positive."); } else if(no<0) { System.out.println("The given number" + no + "is negative."); } else { System.out.println("The given number" + no + "is a zero number."); } } }

Print screen output:

4. Write a program that will accept any two distinct numbers from the keyboard and print them in increasing order.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package distinctnumbers; import java.util.*; public class DistinctNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num=0; int d=0; int[] arrayz; int i=0; System.out.println("How many numbers do you like to ascend?"); num=scanner.nextInt(); arrayz = new int[num]; while (i<num) { System.out.println("Please enter the numbers to ascend according to your input number:"); d=scanner.nextInt(); arrayz[i]=d; i=i+1; } i=1; while (i<num) { int j=i; int B=arrayz[i]; i=i+1; while ((j>0)&& (arrayz[j-1] > B)) { arrayz[j] = arrayz[j-1]; j--; arrayz[j] = B; } } i=0; System.out.println("The numbers you'd type's arrangement is"); while (i<num) { System.out.print(arrayz[i]+ " "); i=i+1; } } }

Print screen output:

5. Write a program that will read any three distinct numbers and print them in increasing order. /* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package distinctnumbers; import java.util.*; public class DistinctNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num=0; int d=0; int[] arrayz; int i=0; System.out.println("How many numbers do you like to ascend?"); num=scanner.nextInt(); arrayz = new int[num]; while (i<num) { System.out.println("Please enter the numbers to ascend according to your input number:"); d=scanner.nextInt(); arrayz[i]=d; i=i+1; } i=1; while (i<num) { int j=i; int B=arrayz[i]; i=i+1; while ((j>0)&& (arrayz[j-1] > B)) { arrayz[j] = arrayz[j-1]; j--; arrayz[j] = B; } } i=0; System.out.println("The numbers you'd type's arrangement is"); while (i<num) { System.out.print(arrayz[i]+ " "); i=i+1; } } }

Print screen output:

6. Create a program that will accept two numbers and display on the screen the highest number. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package highestnumber; import java.io.*; import java.util.*; import java.math.*;

public class HighestNumber { public static void main(String args[])throws IOException{ Scanner z = new Scanner (System.in); int keyboard; System.out.println("Enter desired first number:"); keyboard = z.nextInt(); System.out.println("Enter desired second number:"); keyboard = z.nextInt(); if (keyboard > 0) { System.out.println("The highest number is" + keyboard); } else System.out.println("The highest number is" + keyboard); } }

Print screen output:

7. Create a program that accepts two numbers and checks if they are equal or not equal. If found equal, a message says the two numbers are equal will appear on the screen. Otherwise, a message that

indicates whether the first number is greater or less than the second number will appear. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package greaterorlessthan; import java.util.Scanner; public class GreaterorLessThan { public static void main(String[] args) { Scanner x = new Scanner (System.in); double c, d; System.out.println("Enter the first number:"); c = x.nextDouble(); System.out.println("Enter the second number:"); d = x.nextDouble(); if (c == d) { System.out.println("The number you've entered are both equal."); } else System.out.println("Either one of the numbers you've entered were greater or less than."); } }

Print screen output:

8. You need a program that will read a character and a number. Depending on what is read, certain information will be displayed. The

character should be S or a T. If an S is read and the number is, say 100.50, the program will display Send money! I need 100.50$. If a T is read instead of S, the program will display The temperature last night is 100.50 degrees. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package st; import java.util.*; public class ST { public static void main(String[] args) { char option; Scanner in = new Scanner(System.in); System.out.println("Enter option (S/T):"); option = in.next().charAt(0); if(option<=90) { if(option>=65) System.out.println("Send money! I need extra budget to have my need."); } else if(option<='t') { if('t'<=option) { System.out.println("The temperature last night wasn't in normal level."); } else if(option<='t') { if('s'<=option) { System.out.println("Send money! I need extra budget to have my need."); } } else { System.out.println("Invalid input."); } Print screen output:

9. Create an application that will ask a user to supply only two values among density, mass, and volume and will compute and display the value for the missing items. For example, if mass and volume are supplied, compute for the density. If density and mass are supplied, compute for the volume. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package density; import java.util.Scanner; public class Density { public static void main(String[] args) { double density, mass, volume; Scanner scan = new Scanner (System.in); System.out.print("what is the mass? "); mass = scan.nextDouble(); System.out.println("What is the volume"); volume = scan.nextDouble(); System.out.println("What is the density?"); density = scan.nextDouble(); density = mass / volume; mass = density*volume; volume = mass / density; System.out.println("the density is: " + density); System.out.println("the mass is:" + mass); System.out.println("the volume is:" + volume);

} }

Print screen output:

10. /*

Create a program that will ask a person if s/he is hungry or not.

* To change this template, choose Tools | Templates * and open the template in the editor. */ package yesorno; import java.util.*; public class YesorNo { public static void main(String args[]) { char option; Scanner in = new Scanner(System.in); System.out.println("Are you hungry?"); option = in.next().charAt(0); if(option<=90) { if(option>=65) System.out.println("Okay! Let's have our dinner now."); } else if(option<='y') { if('y'<=option) { System.out.println("Okay! Let's have our dinner now."); } else if(option<='n') { if('n'<=option) { System.out.println("Fine. Let's have our dinner later."); } } else { System.out.println("Invalid input."); } }

Print screen output:

11. Write a program that will determine if the year supplied is a leap year. Leap year is divisible by four unless its divisible by 100. But if it is divisible by 100 and 400, it becomes a leap year. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package leapyear; import java.util.Scanner; import java.io.*; public class LeapYear { public static void main(String[] args) { Scanner y = new Scanner (System.in); int theYear; System.out.print("Enter the year: "); theYear = y.nextInt(); if (theYear < 100) { if (theYear > 40) { theYear = theYear + 1900; } else { theYear = theYear + 2000; } } if (theYear % 4 == 0) { if (theYear % 100 != 0) { System.out.println(theYear + " is a leap year."); } else if (theYear % 400 == 0) { System.out.println(theYear + " is a leap year."); } else { System.out.println(theYear + " is not a leap year."); }

} else { System.out.println(theYear + " is not a leap year."); } } } Print screen output:

12. Create a program that will accept a number that ranges from 1 to 50 and display on the screen if it is a composite or prime number. A number is said to be composite when it is divisible by factorable by

another number aside from itself and 1. On the other hand, a prime number does not have any other factors except itself and 1. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package primeorcomposite; import java.util.*; public class PrimeOrComposite { public static void main(String[] args) { Scanner x = new Scanner (System.in); int number; System.out.println("Enter desired number:"); number = x.nextInt(); if(number%2==0) { System.out.println("The number entered is composite."); } else { System.out.println("The number entered is prime."); } } }

Print screen output:

13. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of other two sides. Write a program that prompts user to enter the length of the three sides of a

triangle and then outputs a message indicating whether the triangle is a right triangle. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pythagoreantheorem; import java.util.Scanner; import java.lang.*; import java.io.*; public class PythagoreanTheorem { public static void main(String args[]) throws Exception { boolean test=false; int s1,s2,s3; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the first side:"); s1=Integer.parseInt(br.readLine()); System.out.println("Enter the second side:"); s2=Integer.parseInt(br.readLine()); System.out.println("Enter the third side:"); s3=Integer.parseInt(br.readLine()); if((s1*s1)==(s2*s2)+(s3*s3)) { test=true; } else if((s2*s2)==(s1*s1)+(s3*s3)) { test=true; } else if((s3*s3)==(s1*s1)+(s2*s2)) { test=true; } if(test=true) System.out.println("The values you've entered forms a right triangle."); else System.out.println("The values you've entered doesn't form a right triangle. Maybe it's another type of the same shape."); } }

Print screen output:

14. You are working the library and frequently receive telephone calls requesting population information. You decide that a simple application would be helpful when answering these questions. It should be generic enough to accept and display city, state, or country names. The application will calculate the difference between the

population at the beginning of the year and at the end of the year. It will also display a message stating an increase or decrease in population. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package populationinformation; import java.util.*; public class PopulationInformation { public static void main (String [] args) { Scanner i = new Scanner (System.in); double country; double year; double growthrate; double fertilityrate; double deathrate; double population; double continent; System.out.println("Welcome to Nathan's Chronicle Center!"); System.out.println("============================ ====="); System.out.println("Here are the choices:"); System.out.println(" 01 - North America"); System.out.println(" 02 - Latin America"); System.out.println(" 03 - Europe"); System.out.println(" 04 - Africa"); System.out.println(" 05 - Asia"); System.out.println(" 06 - Carribean"); System.out.println(" 07 - Pacific"); System.out.println("Enter the continent's assigned number:"); continent = i.nextDouble(); System.out.println("============================ =====");

System.out.println("These are the existing countries in the world with population."); System.out.println("Here are the choices:");

System.out.println(" 1 - Afghanistan"); System.out.println(" 2 - Albania"); System.out.println(" 3 - Algeria"); System.out.println(" 4 - American Samoa"); System.out.println(" 5 - Andorra"); System.out.println(" 6 - Angola"); System.out.println(" 7 - Anguilla"); System.out.println(" 8 - Antigua and Barbuda"); System.out.println(" 9 - Argentina"); System.out.println(" 10 - Armenia"); System.out.println(" 11 - Aruba"); System.out.println(" 12 - Australia"); System.out.println(" 13 - Austria"); System.out.println(" 14 - Azerbaijan"); System.out.println(" 15 - Bahamas"); System.out.println(" 16 - Bahrain"); System.out.println(" 17 - Bangladesh"); System.out.println(" 18 - Barbados"); System.out.println(" 19 - Belarus"); System.out.println(" 20 - Belgium"); System.out.println(" 21 - Belize"); System.out.println(" 22 - Benin"); System.out.println(" 23 - Bermuda"); System.out.println(" 24 - Bhutan"); System.out.println(" 25 - Bolivia"); System.out.println(" 26 - Bosnia"); System.out.println(" 27 - Botswana"); System.out.println(" 28 - Bougainville"); System.out.println(" 29 - Brazil"); System.out.println(" 30 - Brunei"); System.out.println(" 31 - Bulgaria"); System.out.println(" 32 - Burkina Faso"); System.out.println(" 33 - Burundi"); System.out.println(" 34 - Cambodia"); System.out.println(" 35 - Cameroon"); System.out.println(" 36 - Canada"); System.out.println(" 37 - Cape Verde Islands"); System.out.println(" 38 - Cayman Islands"); System.out.println(" 39 - Central African Republic");

System.out.println(" 40 - Chad"); System.out.println(" 41 - Chile"); System.out.println(" 42 - China, Hong Kong"); System.out.println(" 43 - China, Macau"); System.out.println(" 44 - China, Peoples Republic"); System.out.println(" 45 - China, Taiwan"); System.out.println(" 46 - Colombia"); System.out.println(" 47 - Comoros"); System.out.println(" 48 - Congo, Democratic Republic of"); System.out.println(" 49 - Congo, Republic of"); System.out.println(" 50 - Cook Islands"); System.out.println(" 51 - Costa Rica"); System.out.println(" 52 - Cote dIvoire"); System.out.println(" 53 - Croatia"); System.out.println(" 54 - Cuba"); System.out.println(" 55 - Cyprus"); System.out.println(" 56 - Czech Republic"); System.out.println(" 57 - Denmark"); System.out.println(" 58 - Djibouti"); System.out.println(" 59 - Dominica"); System.out.println(" 60 - Dominican Republic"); System.out.println(" 61 - Ecuador"); System.out.println(" 62 - Egypt"); System.out.println(" 63 - El Salvador"); System.out.println(" 64 - Equatorial Guinea"); System.out.println(" 65 - Eritrea"); System.out.println(" 66 - Estonia"); System.out.println(" 67 - Ethiopia"); System.out.println(" 68 - Faeroe Islands"); System.out.println(" 69 - Falkland Islands"); System.out.println(" 70 - Federated States of Micronesia"); System.out.println(" 71 - Fiji"); System.out.println(" 72 - Finland"); System.out.println(" 73 - France"); System.out.println(" 74 - French Guiana"); System.out.println(" 75 - French Polynesia"); System.out.println(" 76 - Gabon"); System.out.println(" 77 - Gambia, The"); System.out.println(" 78 - Georgia"); System.out.println(" 79 - Germany"); System.out.println(" 80 - Ghana"); System.out.println(" 81 - Gibraltar"); System.out.println(" 82 - Greece"); System.out.println(" 83 - Greenland"); System.out.println(" 84 - Grenada"); System.out.println(" 85 - Guadeloupe");

System.out.println(" 86 - Guam"); System.out.println(" 87 - Guatemala"); System.out.println(" 88 - Guinea"); System.out.println(" 89 - Guinea-Bissau"); System.out.println(" 90 - Guyana"); System.out.println(" 91 - Haiti"); System.out.println(" 92 - Honduras"); System.out.println(" 93 - Hungary"); System.out.println(" 94 - Iceland"); System.out.println(" 95 - India"); System.out.println(" 96 - Indonesia"); System.out.println(" 97 - Iran"); System.out.println(" 98 - Iraq"); System.out.println(" 99 - Ireland"); System.out.println(" 100 - Israel"); System.out.println(" 101 - Italy"); System.out.println(" 102 - Jamaica"); System.out.println(" 103 - Japan"); System.out.println(" 104 - Jordan"); System.out.println(" 105 - Kazakhstan"); System.out.println(" 106 - Kenya"); System.out.println(" 107 - Kiribati"); System.out.println(" 108 - Korea, Democratic Peoples Rep"); System.out.println(" 109 - Korea, Republic of"); System.out.println(" 110 - Kosovo"); System.out.println(" 111 - Kuwait"); System.out.println(" 112 - Kyrgyzstan"); System.out.println(" 113 - Laos"); System.out.println(" 114 - Latvia"); System.out.println(" 115 - Lebanon"); System.out.println(" 116 - Lesotho"); System.out.println(" 117 - Liberia"); System.out.println(" 118 - Libya"); System.out.println(" 119 - Liechtenstein"); System.out.println(" 120 - Lithuania"); System.out.println(" 121 - Luxembourg"); System.out.println(" 122 - Macedonia"); System.out.println(" 123 - Madagascar"); System.out.println(" 124 - Malawi"); System.out.println(" 125 - Malaysia"); System.out.println(" 126 - Maldives"); System.out.println(" 127 - Mali"); System.out.println(" 128 - Malta"); System.out.println(" 129 - Martinique"); System.out.println(" 130 - Mauritania"); System.out.println(" 131 - Mauritius");

System.out.println(" 132 System.out.println(" 133 System.out.println(" 134 System.out.println(" 135 System.out.println(" 136 System.out.println(" 137 System.out.println(" 138 System.out.println(" 139 System.out.println(" 140 System.out.println(" 141 System.out.println(" 142 System.out.println(" 143 System.out.println(" 144 System.out.println(" 145 System.out.println(" 146 System.out.println(" 147 System.out.println(" 148 System.out.println(" 149 System.out.println(" 150 System.out.println(" 151 System.out.println(" 152 System.out.println(" 153 System.out.println(" 154 System.out.println(" 155 System.out.println(" 156 System.out.println(" 157 System.out.println(" 158 System.out.println(" 159 System.out.println(" 160 System.out.println(" 161 System.out.println(" 162 System.out.println(" 163 System.out.println(" 164 System.out.println(" 165 System.out.println(" 166 System.out.println(" 167 System.out.println(" 168 System.out.println(" 169 System.out.println(" 170 System.out.println(" 171 System.out.println(" 172 System.out.println(" 173 System.out.println(" 174 System.out.println(" 175 System.out.println(" 176 System.out.println(" 177 -

Mayotte"); Mexico"); Moldova"); Monaco"); Mongolia"); Montenegro"); Montserrat"); Morocco"); Mozambique"); Myanmar"); Namibia"); Nauru"); Nepal"); Netherlands"); Netherlands Antilles"); New Caledonia"); New Zealand"); Nicaragua"); Niger"); Nigeria"); Norway"); Oman"); Pakistan"); Palestine"); Panama"); Papua New Guinea"); Paraguay"); Peru"); Philippines"); Poland"); Portugal"); Puerto Rico"); Qatar"); Runion"); Romania"); Russia"); Rwanda"); Saint Barthelemy"); Saint Helena"); Saint Kitts & Nevis"); Saint Lucia"); Saint Martin"); Saint Pierre & Miquelon"); Saint Vincent"); Samoa"); San Marino");

System.out.println(" 178 System.out.println(" 179 System.out.println(" 180 System.out.println(" 181 System.out.println(" 182 System.out.println(" 183 System.out.println(" 184 System.out.println(" 185 System.out.println(" 186 System.out.println(" 187 System.out.println(" 188 System.out.println(" 189 System.out.println(" 190 System.out.println(" 191 System.out.println(" 192 System.out.println(" 193 System.out.println(" 194 System.out.println(" 195 System.out.println(" 196 System.out.println(" 197 System.out.println(" 198 System.out.println(" 199 System.out.println(" 200 System.out.println(" 201 System.out.println(" 202 System.out.println(" 203 System.out.println(" 204 System.out.println(" 205 System.out.println(" 206 System.out.println(" 207 System.out.println(" 208 System.out.println(" 209 System.out.println(" 210 System.out.println(" 211 System.out.println(" 212 System.out.println(" 213 System.out.println(" 214 System.out.println(" 215 System.out.println(" 216 System.out.println(" 217 System.out.println(" 218 System.out.println(" 219 System.out.println(" 220 System.out.println(" 221 System.out.println(" 222 System.out.println(" 223 -

Sao Tom & Principe"); Saudi Arabia"); Senegal"); Serbia"); Seychelles"); Sierra Leone"); Singapore"); Slovakia"); Slovenia"); Solomon Islands"); Somalia"); South Africa"); Spain"); Sri Lanka"); Sudan"); Suriname"); Swaziland"); Sweden"); Switzerland"); Syria"); Tajikistan"); Tanzania"); Thailand"); Timor Leste"); Togo"); Tokelau Islands"); Tonga"); Trinidad & Tobago"); Tunisia"); Turkey"); Turkmenistan"); Turks & Caicos Islands"); Tuvalu"); Uganda"); Ukraine"); United Arab Emirates"); United Kingdom of GB & NI"); United States of America"); Uruguay"); US Virgin Islands"); Uzbekistan"); Vanuatu"); Venezuela"); Vietnam"); Wallis & Futuna Islands"); Yemen");

System.out.println(" 224 - Zambia"); System.out.println(" 225 - Zimbabwe"); System.out.println("============================ =========="); System.out.println("Enter country number:"); country = i.nextDouble(); System.out.println("Enter the year:"); year = i.nextDouble(); System.out.println("Enter growth rate:"); growthrate = i.nextDouble(); System.out.println("Enter fertility rate:"); fertilityrate = i.nextDouble(); System.out.println("Enter death rate:"); deathrate = i.nextDouble();

System.out.println("============================ ========");

growthrate = fertilityrate - deathrate; System.out.println("The country's growth rate is" + growthrate + " during the year."); population = fertilityrate + deathrate + growthrate; System.out.println("The country's total population is" + population + "."); if (population > 1000000) { System.out.println("There is an increase in population in country selected."); } else {

System.out.println("There is an decrease in population in country selected."); } } }

Print screen output:

15. Write a program that prompts the user to enter the number of minutes call lasted and outputs the amount due. /* * To change this template, choose Tools | Templates * and open the template in the editor. */

package callmemaybe; import java.io.*; public class CallMeMaybe { public static void main (String [] args) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); String accountNumber; char serviceCode = ' '; int numDayMin = 0; int numNightMin = 0; double amountDue = 0; System.out.print ("Enter account number: "); accountNumber = br.readLine (); while ((serviceCode != 'R') & (serviceCode != 'P')) { System.out.print ("Enter service code: "); String tempCode = br.readLine ().toUpperCase (); serviceCode = tempCode.charAt (0); } if (serviceCode == 'R') { amountDue = 1.00; System.out.print ("Enter number of minutes used: "); numDayMin = Integer.parseInt (br.readLine ()); double tempNumDayMin = numDayMin; tempNumDayMin -= 50; if (tempNumDayMin > 0) { amountDue += (tempNumDayMin * 0.20); } } if (serviceCode == 'P') { amountDue = 2.50; System.out.print ("Enter number of night minutes used: ");

numNightMin = Integer.parseInt (br.readLine ()); double tempnumNightMin = 0; if (numNightMin > 75) { tempnumNightMin = 75; } amountDue += (tempnumNightMin * 0.1); System.out.print ("Enter number of day minutes used: "); numDayMin = Integer.parseInt (br.readLine ()); double tempNumDayMin = numDayMin; tempNumDayMin -= 100; if (tempNumDayMin > 0) { amountDue += (tempNumDayMin * 0.05); } } System.out.println ("Account number: " + accountNumber); System.out.println ("Service type: " + serviceCode); if (serviceCode == 'R') { System.out.println ("Number of minutes used: " + numDayMin); } else { System.out.println ("Number of night minutes used: " + numNightMin); System.out.println ("Number of day minutes used: " + numDayMin); } System.out.println ("Amount due: R" + amountDue); } } Print screen output:

16. Write a program that will calculate and print the parking charges for the customer who parks in this garage. /* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package parking; import java.util.Scanner; public class Parking { public static void main(String[]args){

Scanner keyboard = new Scanner(System.in); int hours = 0; String detail = ""; int total = 0;

System.out.println("Welcome to the parking garage!"); System.out.print("How many hours will you be parking? "); hours = keyboard.nextInt(); System.out.println("Okay. We'll charge you for " + hours + " hours."); System.out.print("Would you like you car detailed (y or n)? "); detail = keyboard.next();

if(4%hours != 0) { hours = (hours%4) + hours; } total = 10 + (hours-4);

if(detail.equals("y")) { System.out.println("That was a very good choice!"); total = total + 5; } else { System.out.println("\nYour loss."); }

System.out.println("\nParking will cost you $" + total + "."); } } Print screen output:

17. Write a program that will determine an employees pay given the number of hours s/he works.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

package hourspay; import java.util.*; import java.text.*; public class HoursPay { public static void main(String[] args) { double taxRate=0.15; double hourlyRate=12; DecimalFormat df=new DecimalFormat("$##.00"); Scanner input=new Scanner(System.in); System.out.print("Enter Number of Hours Worked: "); double hrs=input.nextDouble(); double gp=hrs*hourlyRate; double tax=gp*taxRate; double netpay=gp-tax; System.out.println("Net Pay is: "+df.format(netpay)); } }

Print screen output:

18. Write a program to accept the weight of a package and calculate and output the total cost to ship this package using this service.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package shipping; import java.util.*; public class Shipping { public static void main(String [] args) { Scanner v = new Scanner (System.in); double volume; double weight; double length; double width; double height; double cost = 0.100; double shipmentfee; int item; System.out.println("Enter length:"); length = v.nextDouble(); System.out.println("Enter width:"); width = v.nextDouble(); System.out.println("Enter height:"); height = v.nextDouble(); System.out.println("Enter weight:"); weight = v.nextDouble(); volume = length * width * height; System.out.println("The volume of the item is" + volume + ".") shipmentfee = volume - weight; System.out.println("The shipment fee of your package is" + shipmentfee + "."); } } Print screen output:

19. Wire-Gram has hired you as a consultant to build an application that will calculate the cost of telegram. The application should include a way to enter the message and compute the cost based on $4.20 for the first 10 characters and $0.02 for each letter over 10.

The total number of letters and the total cost should be display for the person entering the telegram. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication100; import java.util.*; public class JavaApplication100 { public static void main(String[] args) { Scanner q = new Scanner (System.in); double message; int messagetype1; int messagetype2; double message10 = 4.20; double message11 = 0.20; double messagetotal; System.out.println("Welcome to Nathan's Letter Computing Application."); System.out.println("These are the messages that are allowed to be sent to your loved ones. Please select the message via number:"); System.out.println("1 - I love you."); System.out.println("2 - I heart you."); System.out.println("3 - I hate you."); System.out.println("4 - You are the most adorable person in this world."); System.out.println("5 - You are still beautiful in my eyes."); System.out.println("6 - You must study about that topic."); System.out.println("7 - You must be decent all of the time."); System.out.println("8 - I cannot text you, so I went with Nathan to send this one to you."); System.out.println("9 - I'm sorry. Please forgive me."); System.out.println("10 - Just had new haircut."); System.out.println("11 - You must come here at 6:00pm."); System.out.println("12 - You make me feel like I."); System.out.println("13 - Can't get lost inside your eyes."); System.out.println("14 - I feel closer to the sky."); System.out.println("15 - When you saved the day with just a smile."); System.out.println("16 - 143. I love you.");

System.out.println("Enter the preferred message by number:"); message = q.nextDouble(); System.out.println("Enter the number of first ten (10) characters:"); messagetype1 = q.nextInt(); System.out.println("Enter the number of the rest of the characters:"); messagetype2 = q.nextInt(); messagetotal (message11*messagetype2); = (message10*messagetype1)+

System.out.println("The message sent costs" + messagetotal + ". Thanks for using!"); } } Print screen output:

20. Write a simple application that will allow them to enter the actual speed limit, the speed at which the offender was traveling, and the number that represents how many times the person has received a traffic ticket.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package trafficviolationsystem; import java.util.*; public class TrafficViolationSystem { public static void main(String[] args) { double totalCost; double speed; double mphOver; double courtCost; double speedLimit; int restart = 1; int offenseNumber; final double CHARGE = 20; final double COURT_START_CHARGE = 74.80; Scanner scan = new Scanner (System.in); while(restart==1){ System.out.println("Enter speed limit: "); speedLimit = scan.nextDouble(); System.out.println("Enter speed: ");

speed = scan.nextDouble(); System.out.println("Enter offense number: "); offenseNumber = scan.nextInt(); mphOver = speed - speedLimit; if (offenseNumber == 1) offenseNumber=0; if (offenseNumber > 3) offenseNumber = 3; totalCost = COURT_START_CHARGE (offenseNumber*25); if (totalCost < 0) totalCost=0; System.out.println("Your total cost is: " + totalCost); System.out.println("Restart? (1/0)"); restart = scan.nextInt(); System.out.println(""); } for (int i = 0; i < 0; i++){ System.out.println("Please enter a number"); } } } Print screen output: + (mphOver*CHARGE) +

21. Write a program that prompts the user to input a numeric value higher than 8 and less than 10,000 (maximum of 4 digits only). The program should then output the number and a message stating whether the number is divisible by 9 or not.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package divisibleby9; import java.io.*; public class DivisibleBy9 { public static void main(String[] args) throws IOException{ String answer; do { BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter end number:"); int j = Integer.parseInt(input.readLine()); for (j= 9; j<=9; j++){ System.out.println(); System.out.print(j+ " is divisible by "); int d=1; while (d<=j){ if (j%d == 0) System.out.print(d+ " "); d++; } } System.out.println("\nEnter another number or 'no' to exit the program:"); answer = input.readLine(); } while (!answer.equals ("no")); } } }

Print screen output:

22. Write a program that will print the cost given the number to be purchased. /* * To change this template, choose Tools | Templates * and open the template in the editor. */

package totalamountofpurchases; import java.util.*; public class TotalAmountofPurchases { public static void main(String[] args) { Scanner m = new Scanner (System.in); int footballNumber; System.out.println("Enter football price's choice (numerical values only):"); footballNumber = m.nextInt(); System.out.println("You entered" + footballNumber + ". See below the summary of your choice."); switch (footballNumber) { case 1: System.out.println("$30 each for at least three were purchased."); break; case 2: System.out.println("$25 each for at least three but less than ten were purchased."); break; case 3: System.out.println("$18 each for at least ten are purchased."); break; default: System.out.println("Sorry sir/ma'am, we don't sell jackstone stuffs. Thanks for dropping us online!"); break; }

} } Print screen output:

23. Write a program that inputs the number purchased, and prints out the total cost. /* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package netbeans23; import java.util.*; public class Netbeans23 { public static void main(String[] args) { Scanner o = new Scanner (System.in); double quantity; double cost; double total; System.out.println("Enter desired quantity/ies of items you want:"); quantity = o.nextDouble(); System.out.println("Here are the summation of your choices. Please feel free to choose:"); System.out.println("$2 each for less than ten items were purchased."); System.out.println("$1.50 each for at least ten items were purchased."); System.out.println("Enter your desired cost:"); cost = o.nextDouble(); if (cost > 100) { System.out.println("$2 each for less than ten items."); } else { System.out.println("$1.50 each for at least ten or more items."); } total = quantity * cost; System.out.println("The total of your purchase is" + total + ". Thanks for shopping!"); } } Print screen output:

24. Write a program to accept total amounts of purchases. Output the total net cost after discounting.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package netcost; import java.util.*; public class NetCost { public static void main(String[] args) { Scanner p = new Scanner (System.in); double price; double percent; double grandtotal; System.out.println("Enter total number of purchases:"); price = p.nextDouble(); System.out.println("Here are the discounts given according to your total purchases:"); System.out.println("20% for $3000 and up"); System.out.println("15% for $2000-$3000"); System.out.println("10% for $1500-$2000"); System.out.println("Enter the desired percentage:"); percent = p.nextDouble(); grandtotal = price + percent; System.out.println("The grand total of your choice is" + grandtotal + ". Thanks for using!"); } }

Print screen output:

25. Create a program that will accept a students grade in Math, English, Filipino, Christian Living, Social Science, and Science subject. Compute his average and display its equivalent grade, given that Science is a two-unit subject. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication72; import java.util.*; public class JavaApplication72 { public static void main(String[] args) { int score1 ,score2,score3,score4,score5; String input; Scanner keyboard = new Scanner(System.in); do { System.out.println("Enter score for Math: "); input = keyboard.nextLine(); score1 = Integer.parseInt(input); }while (score1 < 0 || score1 > 100); // Get the score for Test 2. do { System.out.print("Enter score for English: "); input = keyboard.nextLine(); score2 = Integer.parseInt(input); }while (score2 < 0 || score2 > 100); // Get the score for Test 3. do { System.out.print("Enter score for Filipino: "); input = keyboard.nextLine(); score3 = Integer.parseInt(input); }while (score3 < 0 || score3 > 100); // Get the score for Test 4. do { System.out.print("Enter score for Social Science: ");

input = keyboard.nextLine(); score4 = Integer.parseInt(input); }while (score4 < 0 || score4 > 100); // Get the score for Test 5. do { System.out.print("Enter score for Science: "); input = keyboard.nextLine(); score5 = Integer.parseInt(input); }while (score5 < 0 || score5 > 100); // Get the score for Test 5.

// Display the average of all 5 test and it's letter grade. System.out.println("Here are the grades and the average test score:" ); System.out.println("=============================== ================" ); // Assign a letter grade to the input score. System.out.println("Math: "+determineGrade(score1)); System.out.println("English: "+determineGrade(score2)); System.out.println("Filipino: "+determineGrade(score3)); System.out.println("Social Science: "+determineGrade(score4)); System.out.println("Science: "+determineGrade(score5)); // Assign the average of all 5 test to calcAverage. System.out.println("Average: " + " " + calcAverage( score1, score2, score3, score4, score5)); // Assign the letter grade of the average to determineGrade. System.out.println("Average letter grade: " +determineGrade((score1+score2+score3+score4+score5)/5)); } /** The determineGrade method accepts an argument and then displays the value of the parameter. @param scoreValue The score is given a letter grade. */ public static char determineGrade(double scoreValue) { char grade; // Determine grade based on score. if (scoreValue >=0 && scoreValue< 60) grade = 'F'; else if (scoreValue >=60 && scoreValue < 70)

grade = 'D'; else if (scoreValue >=70 &&scoreValue < 80) grade = 'C'; else if (scoreValue >=80 &&scoreValue< 90) grade = 'B'; else if (scoreValue >=90 &&scoreValue <= 100) grade = 'A'; else grade='X'; return grade; } /** The calcAverage method returns the average of its parameters divided by . @param score1 input value of first score. @param score2 input value of second score. @param score3 input value of third score. @param score4 input value of fourth score. @param score5 input value of fifth score. @return The average of all 5 tests. */ public static double calcAverage(double score1, double score2,double score3,double score4,double score5) { // calculate the average testscore double average = 0.0; // Display the value in number. average = (score1+score2+score3+score4+score5)/5.0; return average;

} }

Print screen output:

26. Write a program to input a customers usage figure for a month from the terminal and then calculate and print the customers charges for the month. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package electricitycharges; import java.text.*; import java.util.*; public class ElectricityCharges { public static void main(String[] args) { DecimalFormat num=new DecimalFormat("$,###.00"); double amountDue; double chargeRate = 10.00; double oldMeter; double newMeter; double kwhUsed=10000; int accountNum; String str; char repeat; System.out.println("This program calculates the "+"customer elecitricity usage "+"and the amount due "+"of Peco electric company."); Scanner input = new Scanner(System.in); do { System.out.print("Enter the Customer name: "); str = input.nextLine(); System.out.print("Enter the customer account number: "); accountNum = input.nextInt(); System.out.print("Enter the new meter reading: "); newMeter = input.nextDouble(); System.out.print("Enter the old meter reading: "); oldMeter = input.nextDouble(); if(kwhUsed <= 300) { chargeRate=5.00;

} else if(kwhUsed<= 1000) { chargeRate= 5.00+(0.03*(kwhUsed-300)); } else if(kwhUsed>= 1001) { chargeRate= 35.00+(0.02*(kwhUsed-1000)); } kwhUsed= (newMeter- oldMeter); amountDue= (kwhUsed*chargeRate); System.out.println(str+", "+"account number "+accountNum+". Last meter reading "+oldMeter+", current meter reading "+newMeter+". The total usage of "+kwhUsed+" kwh used"+"will be charge "+num.format(amountDue)+" for this period."); System.out.println(); System.out.println("Would you like to prepare another bill "+"for the next customer ?"); System.out.print("Enter Y for Yes or N for No: "); str=input.next(); repeat=str.charAt(0); } while (repeat=='Y' || repeat=='y'); System.out.println("Good-Bye!"); } }

} }

Print screen output:

27. Write a program that will read the number of minutes that an employee came in late. Besides the base fine of P50, additive is charged according to the conditions. Output the total charge. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package lateinwork; import java.util.*; public class LateinWork { public static void main(String[] args) { Scanner l = new Scanner (System.in); int hour = 0; double pay = 0; double salary = 0; int late = 0; int additive = 0; System.out.println("Please input the number of minutes late:"); hour = l.nextInt(); if (hour > 5) { System.out.println("The } else if (hour > 10) { System.out.println("The } else if (hour > 15) { System.out.println("The } else { System.out.println("The }

additive is 100.");

additive is 150.");

additive is 200.");

additive is 300.");

System.out.println("Please input his/er salary per month.:"); pay = l.nextDouble(); salary = pay - late - additive;

System.out.println("The total salary of his/er account is" + salary + "pesos.");

} } Print screen output:

28. Write a program to input the speed limit and your speed in miles per hour from the terminal and then calculate and print the fine for exceeding speed. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package speedlimit; import javax.swing.*; public class SpeedLimit { public static void main(String[] args) { int speed = 0 ; String speed1; speed1 =JOptionPane.showInputDialog("Enter your car's speed"); speed=Integer.parseInt(speed1); if (speed <= 80){ JOptionPane.showMessageDialog(null,"There is no fine to be paid" ,"Result" ,JOptionPane.PLAIN_MESSAGE );} else if (speed >= 81 && speed <= 100){ speed = (speed-80 )* 10; JOptionPane.showMessageDialog(null,"The fine for exceeding speed limit is" + speed ,"Result" ,JOptionPane.PLAIN_MESSAGE );} else if( speed >= 101 && speed<=120){ speed =(speed- 100)* 15 + 200; JOptionPane.showMessageDialog(null,"The fine for exceeding speed limit is" + speed ,"Result" ,JOptionPane.PLAIN_MESSAGE );} else { speed = (speed-120)* 20 +500; JOptionPane.showMessageDialog(null,"The fine for exceeding speed limit is" + speed ,"Result" ,JOptionPane.PLAIN_MESSAGE );} JOptionPane.showMessageDialog(null,"Vehicle user, thank you for using the Speed Limit Application.", "Finish",JOptionPane.PLAIN_MESSAGE); } }

Print screen output:

29. Prepare a program which computes the water bill. Input the customers name, past reading, and present reading. If the value of the present reading is negative, the program stops processing. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package waterbillreading; import java.util.*; public class WaterBillReading { public static void main(String[] args) { int[] anArray; anArray = new int[5]; double Charges = 0; double water_usage = 0; double current_meter; double past_meter; double c_meter; double p_meter; for (int i = 1; i<= 5; i ++){ System.out.println(); System.out.println("Maybulak Billing System >o<"); System.out.println("==============="); System.out.println(); System.out.println("Menu"); System.out.println(); System.out.println("Select user type by letter:"); System.out.println(); System.out.println("R - Residential type"); System.out.println("I - Industrial type\n"); Scanner scanner = new Scanner(System.in); char character = scanner.next().charAt(0); if (character == 'r' || character == 'R'){ System.out.println ("\nResidential type"); System.out.println("\n Enter past reading:\n"); past_meter = scanner.nextDouble (); System.out.println ("Your past reading: \t" + past_meter +"\n");

System.out.println("\n Enter current reading: \n"); current_meter = scanner.nextDouble (); System.out.println ("Your current reading:\t" + current_meter +"\n"); water_usage = current_meter - past_meter;{ if ((water_usage > 0)&&(water_usage <= 15)) Charges = (water_usage * 0.82 )+5.00; else if ((water_usage > 15)&&(water_usage <= 40)) Charges = (water_usage * 0.65 )+5.00; else if (water_usage > 40) Charges = (water_usage * 0.42 )+5.00; else if (water_usage <= 0) Charges = 5.00; System.out.println("DISPLAY"); System.out.println("===================="); System.out.println ("----------------------------------------------------------------------"); System.out.println (" User Type | CURRENT READING| PASS READING | USAGES | Charges(RM) "); System.out.println ("-----------------------------------------------------------------------"); System.out.println(" "+character +" " +current_meter +"m3 " +past_meter +"m3 m3"+water_usage +" rm " +Charges); System.out.println ("-----------------------------------------------------------------------"); }} else if (character == 'i'|| character == 'I'){ System.out.println ("\nIndustrial type"); System.out.println("\nEnter past reading:\n"); p_meter = scanner.nextDouble (); System.out.println ("Your past reading:\t" + p_meter +"\n"); System.out.println("\nEnter current reading:\n"); c_meter = scanner.nextDouble (); System.out.println ("Your current reading\t" + c_meter +"\n"); water_usage = c_meter - p_meter;{ if (water_usage > 0) Charges = (water_usage * 1.47+15.00 ); else Charges = 15.00; System.out.println("Maybulak Billing System >o<"); System.out.println("====================");

System.out.println ("----------------------------------------------------------------------"); System.out.println (" User Type | CURRENT READING| PASS READING | USAGES | Charges(RM)"); System.out.println(" "+character +" " +c_meter +" " +p_meter +" "+water_usage +" " +Charges); System.out.println ("----------------------------------------------------------------------"); }} else { System.out.println(); System.out.println("INVALID ENTRY\n"); System.out.println("SELECT USER TYPE"); System.out.println(); System.out.println("R - RESIDENTAL"); System.out.println("I - INDUSTRIAL\n"); } }

} }

Print screen output:

30. The National Earthquake Information Center has the following criteria to determine the earthquakes damage. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package earthquake; import java.util.*; import java.io.*; public class Earthquake { public static void main(String[] args) { Scanner q = new Scanner (System.in); double N = 0; System.out.println("Enter Ritcher Scale reading here:"); N = q.nextDouble(); if (N <= 5.0) { System.out.println("Little or no damage."); } else if (N > 5.5) { System.out.println("Some damage."); } else if (N > 6.5) { System.err.println("Serious damage."); } else if (N > 7.5) { System.out.println("Disaster."); } else System.out.println("Catastrophe."); } } Print screen output:

31. Write a program to input the amount of sales and output of the salesmans commission.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package salescommission; import javax.swing.*; public class SalesCommission { public static void main(String[] args) { String s1, commission; int sales; s1 = JOptionPane.showInputDialog("Enter your sales and it will show the commission:"); sales = Integer.parseInt(s1); switch (sales) { case 500: commission = "2% commission on $0.00 to $500.00."; break; case 501: commission = "3% commission on $501.00 to $5000.00."; break; case 5001: commission = "5% commission on $5001.00 and above."; break; default: commission = "Invalid sales input."; } JOptionPane.showMessageDialog(null, commission, "Program", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }

} Print screen output:

32. Write a program that will accepts the total sales and commission code then outputs the total cost to the customer. /*

* To change this template, choose Tools | Templates * and open the template in the editor. */ package salescommissiontotalcost; import java.util.*; public class SalesCommissionTotalCost { public static void main(String[] args) { int fixedSalary = 74000; System.out.println(fixedSalary + " is the yearly gross pay of a sales person."); System.out.println("A sales person will also receive an additional 8% of all sales made for the year."); System.out.println("The total of a sales person's earning's for the year is $" + fixedSalary + ", plus an 8 percent commission on all sales for that year."); Scanner keyboard = new Scanner(System.in); double salesAmount; System.out.print("What was your total sales amount? "); salesAmount = keyboard.nextDouble(); double saleIn; int spResponse = 10000; saleIn = (spResponse * .08); System.out.println("The total incentive is $" + saleIn); int totalAnualComp = 800 + 74000; System.out.println("The total annual totalAnualComp ); } } Print screen output: compensation is $" +

33. Compute for the total amount and display the customers bill, given the number of each item bought.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package discountedonworth; import java.text.*; import java.util.*; import javax.swing.*; public class DiscountedOnWorth {

public static double getDiscountPercent(double subtotal) { double discountPercent = 0; if (subtotal < 100) discountPercent = 0; else if (subtotal >= 100 && subtotal < 150) discountPercent = .1; else if (subtotal >= 150 && subtotal < 200) discountPercent = .15; else discountPercent = .20; return discountPercent; } public static void main(String[] args) { String choice = "y"; while (!choice.equalsIgnoreCase("n")) { String result = JOptionPane.showInputDialog("Enter subtotal:"); if(result != null) { double subtotal = Double.parseDouble(result);

double discountPercent = getDiscountPercent(subtotal); double discountAmount = subtotal * discountPercent;

double total = subtotal - discountAmount; NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); JOptionPane.showMessageDialog(null, "Discount percent: " + percent.format(discountPercent) + "\n" + "Discount amount: " + currency.format(discountAmount) + "\n" + "Total: " + currency.format(total) + "\n"); } else choice = "n"; } } }

Print screen output:

34. A RTW shop give its employee a 2% commission rate as an incentive for selling clothes worth P250.00 and below otherwise, 5& if

higher. Given a basic salary of P7500.00, determine the employees new salary. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package newsalary; import java.util.*; import java.text.*; public class NewSalary { public static void main(String[] args) {

double currentSalary; double raise = 0.2; double newSalary; String rating; Scanner scan = new Scanner(System.in); System.out.print ("Enter the current salary: "); currentSalary = scan.nextDouble(); newSalary = currentSalary + raise; NumberFormat money = NumberFormat.getCurrencyInstance(); System.out.println(); System.out.println("Current Salary: " + money.format(currentSalary)); System.out.println("Amount of your raise: " + money.format(raise)); System.out.println("Your new salary: " + money.format(newSalary)); System.out.println(); } }

Print screen output:

35. Generate a program that will display the amount to be paid by the customer if s/he is given a 3% discount rate for buying an item that costs more than P100.00, or else only 1%. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package netbeans35; import java.util.*; public class Netbeans35 { public static void main(String[] args) { Scanner k = new Scanner (System.in); double double double double double discount; choice1; choice2; choice3; choice4;

System.out.println("Welcome to the Discount Identifier!"); System.out.println("Please enter the amount you have received to determine your discount!"); discount = k.nextDouble(); choice1= choice2= choice3= choice4= discount discount discount discount *.01; - choice1; *.03; - choice3;

if(discount<=100) { System.out.println("Your Total Amount to pay is:" + choice2 ); } else { System.out.println("Your Total Amount to pay is:" + choice4); }

} } Print screen output:

36. Create a program that will determine how much a specific type of item costs. /*

* To change this template, choose Tools | Templates * and open the template in the editor. */ package specificcost; import javax.swing.*; public class SpecificCost { public static void main(String[] args) { String s1, breed; int dog; s1 = JOptionPane.showInputDialog("Enter the number of the dog you want:"); dog = Integer.parseInt(s1); switch (dog) { case 1: breed = "Beagle, Php 9500."; break; case 2: breed = "Dalmatian, Php 10,000."; break; case 3: breed = "German Shepherd, Php 8000."; break; case 4: breed = "Labrador, Php 14,400."; break; case 5: breed = "Retriever, Php 17,000."; break; case 6: breed = "Shitzu, Php 15,000."; break; case 7: breed = "Terrier, Php 5000."; break;

default: breed = "We don't sell cats. Thanks for dropping by!"; } JOptionPane.showMessageDialog(null, "Program", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } breed,

Print screen output:

37. Write a program that will compute an items new price after applying its corresponding discount rate. /*

* To change this template, choose Tools | Templates * and open the template in the editor. */ package discountandprice; import java.util.*; import javax.swing.*; public class DiscountAndPrice { public static void main(String[] args) {

final double DISCOUNT_ONE = .2; final double DISCOUNT_TWO = .5; final double DISCOUNT_THREE = .7; final double DISCOUNT_FOUR = .10; final double DISCOUNT_FIVE = .15; double price; String priceString; int quantity; String quantityString; priceString = JOptionPane.showInputDialog("Enter price of item: "); price = Double.parseDouble(priceString); quantityString = JOptionPane.showInputDialog("Enter quantity ordered: "); quantity = Integer.parseInt(quantityString); calculatePrice(price, quantity); if (price < 5.00); { price = (price * } if (price < 10.00); { price = (price * } if (price > 10.00); { price = (price * } if (price > 10.00); { price = (price *

DISCOUNT_ONE);

DISCOUNT_TWO);

DISCOUNT_THREE);

DISCOUNT_THREE);

} if (price > 10.00); { price = (price * DISCOUNT_THREE); } System.exit(0); } public static double calculatePrice(double price, int quantity) { double total; double discountPercent; discountPercent = (price / 100); total = (price * quantity); System.out.println("Original Price:" + price); System.out.println("Discount Percent:" + discountPercent); System.out.println("Quantity:" + quantity); System.out.println("Total price:" + total); return price; } }

Print screen output:

38. Write a program that reads a customers account number, account type, minimum balance, and current balance. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package checkingaccount; import java.io.*; import java.lang.*; import java.util.*; public class CheckingAccount { public static void main(String[]args)throws IOException { char [] newType = new char [20]; double [] newTransaction = new double [20]; double [] newBalance = new double [20]; int o = 0; int s = 0; int t = 0; BufferedReader console = new BufferedReader ( new InputStreamReader(System.in)); System.out.println("Hello, please enter your account name:"); String name = console.readLine(); System.out.println("Hello " + name); System.out.println("Please enter your account number:"); String account = console.readLine(); System.out.println("Please enter your original balance:"); String Bal = console.readLine(); double initialBalance = Double.parseDouble(Bal); double balance = initialBalance; System.out.println("Please enter C for check; D for deposit; and P for printing the summary:"); char continueAnswer = console.readLine().charAt(0); boolean answer = true; newType [o] = continueAnswer; if (continueAnswer == 'p')answer = false; double Fee;

double OverdraftTotal = 0; double checks = 0; double deposit = 0; double TotalBalance = 0; while (answer == true) { System.out.println("Please enter the amount:"); String input = console.readLine(); double transaction = Double.parseDouble(input); newTransaction [o] = transaction; if (continueAnswer == 'c') checks = checks + transaction; { checks = checks + 0; if (transaction > balance) { if (transaction > 250) Fee = transaction * .10; else Fee = 25.00; balance = (balance + transaction) - Fee; newBalance [t] = TotalBalance; OverdraftTotal = OverdraftTotal + Fee; o = o + 0; t = t + 0; newType [o] = 'f'; newTransaction [o] = Fee; } else balance = balance - transaction; newBalance [t] = balance; } if (continueAnswer == 'd') deposit = deposit + transaction; balance = deposit + transaction; newBalance [t] = balance; o = o + 0; t = t + 1;

System.out.println("Please enter C for check; D for deposit; and P for printing the summary:"); continueAnswer = console.readLine().charAt(0); newType [o] = continueAnswer; if (continueAnswer == 'p')answer = false; } if (balance <= 0) System.out.println("Your account is insufficient, You should enter $" + balance + " to bring account current"); System.out.println("Name: " + name + ", Account Number: " + account); System.out.println("Account Statement"); System.out.println("Your balance is:" + balance); System.out.println("Amount of checks: " + checks); System.out.println("Overdraft total fees: Php" + OverdraftTotal); System.out.println("Total Checks: Php" + checks); System.out.println("Total Deposits: Php" + deposit); while (s < o) { System.out.println(newType[s] + " " + newTransaction [s] + " " + newBalance[s]); s = s + 1; System.out.println(""); } } }

Print screen output:

39.

Write a program that reads a customers federal tax.

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication103; import java.util.*; public class JavaApplication103 { public static void main(String[] args) { Scanner o = new Scanner (System.in); double taxableincome; double taxrate; double pensionplan; double gross; double standardexemption; int status; double children; double taxincome; double personalexemption; double federaltaxtotal; System.out.println("Here are two choices of your civil statuses:"); System.out.println("1 - Single"); System.out.println("2 - Married"); System.out.println("Enter the civil status by number:"); status = o.nextInt(); System.out.println("If married, how many children do you have? For single, please enter zero (0):"); children = o.nextDouble(); System.out.println("For the summation of your federal tax, please enter the fields given."); System.out.println("Standard exemption:"); standardexemption = o.nextDouble(); System.out.println("Gross:"); gross = o.nextDouble(); System.out.println("Tax income:"); taxincome = o.nextDouble(); System.out.println("Taxable income:");

taxableincome = o.nextDouble(); System.out.println("Personal exemption:"); personalexemption = o.nextDouble(); federaltaxtotal = standardexemption - personalexemption taxableincome - taxincome - gross; System.out.println("The federal tax of yours is " + federaltaxtotal + "."); } } Print screen output:

Anda mungkin juga menyukai