Hi, I've just started a Java course, which is giving me trouble because I've had so much unscheduled overtime. I have three programs due that have small problems that I can't fix no matter how many changes I've made. They are really basic, but I've only been one week into this. I've marked each instance. There isn't many. Any help will be appreciated. Thanks, Joe
Number 1:
import java.util.Scanner; //needed for scanner class
public class DiscussionOne
{
public static void main(String[] args)
{
// Added by Michael Jenkins
// Constructor for all non-static methods in this class file.
// dissOne can be called for any other methods added to this class.
// No need to add another constructor.
// Page 139 discusses constructors
DiscussionOne dissOne = new DiscussionOne();
// Example call to method displaying a personal greeting
dissOne.displayWelcomeMessage();};
// End of code by Michael Jenkins
/**
* Added by Michael Jenkins
* This method asks user for input (name)
* Then displays a personalized welcome
* message to the user.
*/
public void displayWelcomeMessage() {
// Scanner class used to get input from user.
// Pages 86-89
Scanner userInput = new Scanner(System.in);
// print and println are used to send output to the screen.
// Pages 37-42
System.out.print("Please type your full name: ");
String name = userInput.nextLine();
System.out.print("Welcome, " + name);
System.out.println(", to the first Discussion Question.");
}
//added by Joe Jaunich
// using Constructors starting fron page 139
double percentmarkedup; // Product's markeup from regular price
double originalprice; // Product's original price
double salestaxrate; // Product's sales tax rate
// these parameters were adapted from the sales illustration on p.52
// Joe added line to get keyboard input p. 86
Scanner keyboard = new Scanner(System.in); //used to get input from keyboard
// Get the starting Price.
System.out.print("What is your product's " //this is one problem
+ "starting price? "); //according to Eclipse
originalprice = keyboard.nextDouble();
// Get the monthly markup rate.
System.out.print("What is your purchase markup rate? ");
percentmarkedup = keyboard.nextDouble();
// Get the amount of pay for the month.
System.out.print("How much were you paid this month? ");
salestaxrate = keyboard.nextDouble();
// used the following to calculate and display the final sale price
//combination of pp.60-65, and the layout of code listing 2-10 on p. 51
double storeSalPrice = originalprice*percentmarkedup/100; // figures markup
double tempSalPrice = originalprice+storeSalPrice; // adjusts for markup
double tempTaxPrice = tempSalPrice*salestaxrate/100; // figures sales tax
double taxSalPrice = tempSalPrice+salestaxrate; // adds sales tax
double finalPrice = tempSalPrice+salestaxrate; // final price
System.out.println("The original price="+originalprice); // the following prints out
System.out.println("The markedup percentage="+percentmarkedup); //findings
System.out.println("The store Selling price="+tempSalPrice);
System.out.println("The sales tax rate="+ salestaxrate);
System.out.println("The sales tax price="+ tempTaxPrice);
System.out.println("The final Price="+ finalPrice);
}
}
Number 2:
public class EmployeeClass {
/**
* First set the Employees fields
*/
public static void main(String[] args)
{
String Name = new String (employee); //holds employee name
String Place = new String (department); //holds employee department
String Job = new String (position); //holds employee position
int idnumber; //holds employee id number
/**
* The setemployee method is a mutator that accepts an argument
* an argument which is stored in the employee field.
*/
public void setEmployee;
{
employee = emp;
}
/**
* The setdepartment method is a mutator that accepts an argument
* an argument which is stored in the department field.
*/
public void setDepartment;
{
department = dep;
}
/**
* The setposition method is a mutator that accepts an argument
* an argument which is stored in the position field.
*/
public void setPosition;
{
position = pos;
}
/**
* The setidnumber method is a mutator that accepts an argument
* an argument which is stored in the idnumber field.
*/
public void setIdnumber;
{
idnumber = id;
}
/**
* The getemployee method is a accessor that
* returns the value stored in the employee field.
*/
public void getEmployee;
{
return employee;
}
/**
* The getdepartment method is a accessor that
* returns the value stored in the department field.
*/
public void getDepartment;
{
return department;
}
/**
* The getposition method is a accessor that
* returns the value stored in the position field.
*/
public void getPosition;
{
return position;
}
/**
* The getidnumber method is a accessor that
* returns the value stored in the idnumber field.
*/
public int getIdnumber(); //this is another problem
{
return idnumber;
}
}
}
Number 3:
import javax.swing.JOptionPane;
public class EmployeeDataOut {
/** Designed to use Employee Class methods: employee,
* department, position, and idnumber
*/
public static void main(String[] args) {
// Create three employee objects
String Name = "Susan Meyers"; //holds employee name
String Name = "Mark Jones"; //holds employee name
String Name = "Joy Rodgers"; //holds employee name
String name, // Our input's name
inputString; // Holds input
/**
* The individual Employees data
* is stored in the employee fields below.
*/
public void EmployeeData;("Susan Meyers"); //this is another problem
{
employee = "Susan Meyers";
department = Accounting;
position = "Vice President";
idnumber = 47899;
}
public void EmployeeData;("Mark Jones"); //this is another problem
{
employee = "Mark Jones";
department = IT;
position = Programmer;
idnumber = 39119;
}
public void EmployeeData;("Joy Rodgers"); //this is another problem
{
employee = "Joy Rodgers";
department = Manufacturing;
position = Engineer;
idnumber = 81774;
}
// Get the user's name.
name = JOptionPane.showInputDialog("What is your name?");
// After this line the results will be displayed.
JOptionPane.showMessageDialog(null, "Hello " + name +
". Your company data is ");
// I'd like to call up the object definition, but I don't know the command.
if (name = "Susan Meyers")
JOptionPane.showMessageDialog(null, +
"employee = Susan Meyers" +
"department = Accounting" +
"position = Vice President" +
"idnumber = 47899");
if (name = "Mark Jones")
JOptionPane.showMessageDialog(null, +
"employee = Mark Jones" +
"department = IT" +
"position = Programmer" +
"idnumber = 39119");
if (name = "Mark Jones")
JOptionPane.showMessageDialog(null, +
"employee = Joy Rodgers" +
"department = Manufacturing" +
"position = Engineer" +
"idnumber = 81774");
// End the program.
System.exit(0);
}
}