code so they can't? put less than zero. I am sure it is simple and I am having a brain fart. How do I add " >=0" and tell them this is a no no! LOL!!!! Thank you soooo much!
public class ISP
{
private char pack;
private double hours;
public ISP()
{
pack='A';
hours=0;
}
public ISP(char p, double h)
{
pack=p;
hours=h;
}
public void setpackage(char p)
{
pack=p;
}
public char getpackage()
{
return pack;
}
public void sethour(double h)
{
hours=h;
}
public double gethour()
{
return hours;
}
public double calculateMonthlyBill()
{
double bill,h;
if(pack=='A')
{
h=hours-10;
bill=9.95+(2*(int)(h+.5)); //round hours up
}
else if(pack=='B')
{
h=hours-20;
bill=14.95+(int)(h+.5); //round hours up
}
else
bill=19.95; //round hours up
return bill;
}
}
import java.util.Scanner;
public class Assignment04
{
public static void main(String[] args)
{
CurrentDateTime now = new CurrentDateTime();
char choice;
String c;
double h;
System.out.println(now.getDateTime());
System.out.println("\nEnter the package:\n ");
Scanner in = new Scanner (System.in);
do
{
System.out.println("A. Package A\nB. Package B\nC. Package C");
c=in.next();
choice=c.charAt(0);
if(choice<'A'||choice>'C')
System.out.println("Invalid choice");
}
while(choice<'A'||choice>'C');
System.out.println("Enter hours used: ");
h=in.nextDouble();
ISP isp = new ISP(choice,h);
System.out.printf("Your bill is is $%.2f\n",isp.calculateMonthlyBill());
}
}
import java.text.*;
import java.util.*;
public class CurrentDateTime
{
public String getDateTime ()
{
String rv = "";
Date today = new Date();
SimpleDateFormat sdf_date = new SimpleDateFormat("E, MMMM d, y");
SimpleDateFormat sdf_time = new SimpleDateFormat("h:mm a");
rv = sdf_date.format(today) + " at " + sdf_time.format(today);
return rv;
}
}
public class ISP
{
private char pack;
private double hours;
public ISP()
{
pack='A';
hours=0;
}
public ISP(char p, double h)
{
pack=p;
hours=h;
}
public void setpackage(char p)
{
pack=p;
}
public char getpackage()
{
return pack;
}
public void sethour(double h)
{
hours=h;
}
public double gethour()
{
return hours;
}
public double calculateMonthlyBill()
{
double bill,h;
if(pack=='A')
{
h=hours-10;
bill=9.95+(2*(int)(h+.5)); //round hours up
}
else if(pack=='B')
{
h=hours-20;
bill=14.95+(int)(h+.5); //round hours up
}
else
bill=19.95; //round hours up
return bill;
}
}
import java.util.Scanner;
public class Assignment04
{
public static void main(String[] args)
{
CurrentDateTime now = new CurrentDateTime();
char choice;
String c;
double h;
System.out.println(now.getDateTime());
System.out.println("\nEnter the package:\n ");
Scanner in = new Scanner (System.in);
do
{
System.out.println("A. Package A\nB. Package B\nC. Package C");
c=in.next();
choice=c.charAt(0);
if(choice<'A'||choice>'C')
System.out.println("Invalid choice");
}
while(choice<'A'||choice>'C');
System.out.println("Enter hours used: ");
h=in.nextDouble();
ISP isp = new ISP(choice,h);
System.out.printf("Your bill is is $%.2f\n",isp.calculateMonthlyBill());
}
}
import java.text.*;
import java.util.*;
public class CurrentDateTime
{
public String getDateTime ()
{
String rv = "";
Date today = new Date();
SimpleDateFormat sdf_date = new SimpleDateFormat("E, MMMM d, y");
SimpleDateFormat sdf_time = new SimpleDateFormat("h:mm a");
rv = sdf_date.format(today) + " at " + sdf_time.format(today);
return rv;
}
}