The Artima Developer Community
Sponsored Link

Java Answers Forum
Help needed turning this program into 2-class and demo.. plz help

4 replies on 1 page. Most recent reply: Oct 15, 2009 11:08 AM by Nay B

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Nay B

Posts: 9
Nickname: blackrose
Registered: Oct, 2009

Help needed turning this program into 2-class and demo.. plz help Posted: Oct 15, 2009 7:12 AM
Reply to this message Reply
Advertisement
import java.util.Scanner;

public class StateA
{
public static void main (String[]args)
{
String input;

Scanner keyboard = new Scanner(System.in);

System.out.println("Please enter one of the following state abbreviations: ");
System.out.println("NC, SC, GA, FL, or AL");
input = keyboard.nextLine();

if (input.equalsIgnoreCase("NC"))
{
System.out.println("You've entered the abbreviation for North Carolina");
}
else if (input.equalsIgnoreCase("SC"))
{
System.out.println("You've entered the abbreviation for South Carolina");
}
else if (input.equalsIgnoreCase("GA"))
{
System.out.println("You've entered the abbreviation for Georgia");
}
else if (input.equalsIgnoreCase("FL"))
{
System.out.println("You've entered the abbreviation for Florida");
}
else if (input.equalsIgnoreCase("AL"))
{
System.out.println("You've entered the abbreviation for AlabamaA");
}
else
{
System.out.println("That's not a choice.");
}
}
}


Also, when you make a UML diagram, do you do it for the class or demo - or both?


Nay B

Posts: 9
Nickname: blackrose
Registered: Oct, 2009

Re: Help needed turning this program into 2-class and demo.. plz help Posted: Oct 15, 2009 10:34 AM
Reply to this message Reply
Okay, I have the DEMO, it works:

import java.util.Scanner;

public class StateAbbreviationsDemo
{
public static void main(String[]args)
{
String yourinput;

Scanner keyboard = new Scanner(System.in);

System.out.println("Please enter one of the following state abbreviations: ");
System.out.println("NC,SC, GA, FL, or AL");
yourinput = keyboard.nextLine();

StateAbbreviations states = new StateAbbreviations(yourinput);

System.out.println("You have entered the abbreviation for " + states.getSOMETHING);
}
}

Nay B

Posts: 9
Nickname: blackrose
Registered: Oct, 2009

Re: Help needed turning this program into 2-class and demo.. plz help Posted: Oct 15, 2009 10:46 AM
Reply to this message Reply
this is the other half i have so far:

public class StateAbbreviations
{
private String input;

public StateAbbreviations(String i);
{
input = i;
}

public String getInput()
{
if (input.equalsIgnoreCase("NC"))
{

}
}

Nay B

Posts: 9
Nickname: blackrose
Registered: Oct, 2009

Re: Help needed turning this program into 2-class and demo.. plz help Posted: Oct 15, 2009 10:48 AM
Reply to this message Reply
Trying to use these two programs as a guideline to write the StateAbbreviations programs:

SOFTWARE SALES:

public class SoftwareSales
{
private final double UNIT_PRICE = 99;
private int unitsSold;

public SoftwareSales(int u)
{
unitsSold = u;
}

public int getUnitsSold()
{
return unitsSold;
}

public double getDiscount()
{
double discountPercent;
double discount;


if (unitsSold >= 100)
{
discountPercent = 0.5;
}
else if(unitsSold < 100 && unitsSold >= 50)
{
discountPercent = 0.4;
}
else if(unitsSold < 50 && unitsSold >= 20)
{
discountPercent = 0.3;
}
else if(unitsSold < 20 && unitsSold >= 10)
{
discountPercent = 0.2;
}
else
{
discountPercent = 0;
}

discount = (unitsSold*UNIT_PRICE) * discountPercent;
return discount;
}

public double getCost()
{
double cost = (unitsSold*UNIT_PRICE) - getDiscount();
return cost;
}

}

---------------------------------------------------

SOFTWARE SALES DEMO

import java.util.Scanner;
import java.text.DecimalFormat;

public class SoftwareSalesDemo
{
public static void main(String[] args)
{

int units;


Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the units sold: ");
units = keyboard.nextInt();


SoftwareSales sales = new SoftwareSales(units);

DecimalFormat formatter = new DecimalFormat("#,##0.00");

System.out.println("Units sold: " + formatter.format(sales.getUnitsSold()));
System.out.println("Discount: " + formatter.format(sales.getDiscount()));
System.out.println("Cost: " + formatter.format(sales.getCost()));
}
}

Nay B

Posts: 9
Nickname: blackrose
Registered: Oct, 2009

Re: Help needed turning this program into 2-class and demo.. plz help Posted: Oct 15, 2009 11:08 AM
Reply to this message Reply
This is finished i guess, i can compile successfully but my office computer wont run -- ... so.. idk...

i can't run it
won't know if it's really done

here it is:

public class StateAbbreviations
{
private String input;

public StateAbbreviations(String i);
{
input = i;
}

public String getInput()
{
if (input.equalsIgnoreCase("NC"))
{
input = "North Carolina";
return input;
}

else if (input.equalsIgnoreCase("SC"))
{
input = "South Carolina";
return input;
}
else if (input.equalsIgnoreCase("GA"))
{
input = "Georgia";
return input;
}
else if (input.equalsIgnoreCase("FL"))
{
input = "Florida";
return input;
}
else if (input.equalsIgnoreCase("AL"))
{
input = "Alabama";
return input;
}
else
{
System.out.println("That's not a choice.");
}
}
}

Flat View: This topic has 4 replies on 1 page
Topic: Help with Code Previous Topic   Next Topic Topic: HELP!!! input = keyboard.nextLine();

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use