Lab Max-Min
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class labmaxmin {
public labmaxmin() {
}
public static void main(String[] args) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a list of nonegative scores:");
double next, sum = 0,max = 0,min = 100;
int count = 0;
String nextstr = keyboard.readLine();
next = Double.parseDouble(nextstr);
while (next >= 0)
{
count++ ;
if (max <= next) max = next; else if (min >= next)
min = next;
nextstr = keyboard.readLine();
next = Double.parseDouble(nextstr);
}
if (count == 0 )
System.out.println("No score enteres");
else
{
System.out.println(count + " Scores read.");
System.out.println("Max is " + max );
System.out.println("Min is " + min );
}
}
}
Lab If-Else (2)
import javax.swing.JOptionPane;
public class LabIfElse2 {
public LabIfElse2() {
}
public static void main(String[] args) {
double net,fivePercentTax, tenPercentTax;
String tax;
String netIcome = JOptionPane.showInputDialog("Enter a number :");
net = Double.parseDouble(netIcome);
if (net <= 0)
tax = "n < 0";
else if ((net >= 0) && (net <= 100))
tax = "0 <= n <100";
else
{
tax = "n >= 100";
}
JOptionPane.showMessageDialog(null,"Ans: "+ tax);
System.out.println( tax );
System.exit(0);
}
}
Project 2.03 (1st ed.)
Project 2.03 (1st ed.)import javax.swing.JOptionPane;public class Project203{public static void main(String arg[]){String p_str = JOptionPane.showInputDialog("Enter the purchase: ");double Pri = Double.parseDouble(p_str);
String s_str =JOptionPane.showInputDialog("Enter the salvage: ");double Val = Double.parseDouble(s_str);
String y_str = JOptionPane.showInputDialog("Enter the number of years the item is used: ");double Year = Double.parseDouble(y_str);
double D;D = (Pri - Val) / Year;System.out.println("The yearly depreciation for the item is"+ D);JOptionPane.showMessageDialog(null, "The yearly depreciation for the item is"+ D);System.exit(0);}}
Project 2.05 (1st ed.)
Project 2.05 (1st ed.)import javax.swing.JOptionPane;public class Project205{ public static void main(String[] args){String p_str = JOptionPane.showInputDialog("Enter price of item\n" + "(from 25 cents to a dollar, in 5-cent increments):");int Pri = Integer.parseInt(p_str);
System.out.println("You bought an item for " + Pri +" cents and gave me a dollar,\n" + "so your change is ");int C = 100 - Pri;int quarter = 0, dime = 0, nickel = 0;int change;if(C >= 25){quarter = C / 25;change = C - 25*quarter;}
if(C >=10 && C <25){dime = C / 10;C = C - 10*dime;}
if(C >=5 && C <10){nickel = C / 5;C = C - 5*nickel;}
System.out.println(quarter+" quarters");System.out.println(dime+" dimes and");System.out.println(nickel+" nickels");System.exit(0);}}