I'm writing a program used to calculate the total sales of employees in a small business, and am trying to figure out how to restart the program based on a user input of y/n. I know that loops are what I need to use here, but need a push in the right direction.
Code:
import java.util.Scanner;
public class calcMain {
public static void main(String[]args){
double totalPay = 0, itemOne = 239.99, itemTwo = 129.75, itemThree = 99.95, itemFour = 350.89, commission;
int weeklyBonus = 200, numSold;
String employee1, employee2, employee3, employee4, yn;
Scanner kb = new Scanner(System.in);
System.out.println("Please enter the salesperson's name: ");
employee1 = kb.nextLine();
System.out.println("Please enter the number of Item 1 sold: ");
numSold = kb.nextInt();
totalPay += (itemOne * numSold);
System.out.println("Please enter the number of Item 2 sold: ");
numSold = kb.nextInt();
totalPay += (itemTwo * numSold);
System.out.println("Please enter the number of item 3 sold: ");
numSold = kb.nextInt();
totalPay += (itemThree * numSold);
System.out.println("Please enter the number of item 4 sold: ");
numSold = kb.nextInt();
totalPay += (itemFour * numSold);
System.out.println("The total weekly earnings for " +employee1+ " are: " +totalPay);
System.out.println("Would you like to input the sales of another employee? (y/n)");
yn = kb.next();
}
}
Put all the code inside a while loop that says while (yn.equalsIgnoreCase("y"))
Don't forget to initialize yn to y!
Second solution:
Modify the code so that it returns a string, and if the user inputs y, return y, or if the user inputs n, return n.
Put all that code inside a method (lets call it method x for now)
public static void main(String[] args) {
while(x().equalsIgnoreCase("y")){}
}
Using a do-while loop (while loop should have the same effect) and ask for (y/n) at the end.
Like this:
String yn;
do
{
// Your code here
// Ask for confirmation
}
while (yn.equals("y"));
Related
I am creating a program that takes in employee payroll information and then displays the average and total afterwards. Everything seems to be working correctly except for the fact I cannot get the program to end when I enter the sentinel value of -1 for the hours worked so that the program can display the total and average of the employees. Any help is greatly appreciated.
import java.util.Scanner;
public class PayrollDo
{
public static void main(String[] args)
{
int hoursWorked = 0;
int grossPay = 0;
int empCounter = 0;
int total = 0;
Scanner keyboard = new Scanner(System.in);
do {
total = total + grossPay; // add gross to total
empCounter = empCounter + 1; // incriment counter
System.out.print("Enter hours worked: ");
hoursWorked = keyboard.nextInt();
System.out.print("Enter hourly wage: ");
int hourlyWage = keyboard.nextInt();
//System.out.println("Grosspay is " + (hourlyWage * hoursWorked));
keyboard.nextLine();
System.out.println("Enter employee name ");
String name = keyboard.nextLine();
} while(hoursWorked != -1);
// if user entered at least one employee
if (empCounter != 0) {
// use number with decimal point to calculate average of employees
int average = (int) total / empCounter;
// display total and average (with two digits of precision)
System.out.printf("%nTotal of the %d employees entered is %d%n",
empCounter, total);
System.out.printf("Employee average is " + average);
}
else {
// no employees were entered, so output appropriate message
System.out.println("No employees were entered");
}
}
}
Test soon after entering the value whether it is -1 or not
System.out.print("Enter hours worked: ");
hoursWorked = keyboard.nextInt();
if (hoursWorked == -1) break;
edit
I think you will also have trouble with Integer division http://stackoverflow.com/questions/4685450/why-is-the-result-of-1-3-0
You could restructure your do loop to put the hoursWorked input last (otherwise you have to complete the entries) - and also, add a conditional to reject all entries that cycle, otherwise empCounter is off by one. And I think the total calculation needs reworking too:
do {
System.out.println("Enter employee name ");
String name = keyboard.nextLine();
System.out.print("Enter hourly wage: ");
int hourlyWage = keyboard.nextInt();
System.out.print("Enter hours worked: ");
hoursWorked = keyboard.nextInt();
keyboard.nextLine();
if (hoursWorked != -1) {
total = total + (hourlyWage * hoursWorked); //
empCounter = empCounter + 1; // incriment counter
}
} while(hoursWorked != -1);
In cases like this it can be simpler to have a question like "More Employees? (y/n)" that is used to terminate the loop, using a boolean flag as the while terminator.
I have a little issue with this program I am writing. When I run this with CMD it gives me a few errors such as the variable "totalFry" cant be defined even though it is a Global Variable. Any Help would be great, thank you very much!
(Note: this is my first time writing looping/ while code)
The idea is to give the user 3 choices, have the user input an option
(1-3) and have said options appear to prompt the user to input the
amount they want for said team.
Next, the program will ask the user
if they want to end the order, assuming they input "Yes" the program
will ask if the user wants to end the program if the user inputs
"yes" the program will go and total up the cost and display it.
End of program
Code:
import java.io.*;
import java.util.Scanner;
//Lab 4_5
public class Lab4_5 {
static Scanner keyboard = new Scanner(System.in);
// Declare local variables
static double totalBurger, totalFry, totalSoda;
static int option, burgerCount, fryCount, sodaCount;
// The main method
public static void main(String[] args) {
//Add a loop to run program again
String endProgram = "no";
while (endProgram.equals("no"))
//Add a loop to take in order
String endOrder = "no";
while (endOrder.equals("no"))
// Add statements to display the menu, get the user choice, and assign it to option
System.out.println("Enter 1 for Yum Yum Burger");
System.out.println("Enter 2 for Grease Yum Fires");
System.out.println("Enter 3 for Soda Yum");
//Add a Select Case statement based on the value of option
int option = 0;
option = keyboardnextInt();
//When option = 1
if (option == 1)
double totalBurger = 0;
int burgerCount = 0;
System.out.println("Enter the number of burgers you want ");
burgerCount = keyboard.nextDouble();
totalBurger = totalBurger + burgerCount * .99;
//When option = 2
if (option == 2)
double totalFry = 0;
int fryCount = 0;
System.out.println("Enter the number of fires you want ");
fryCount = keyboard.nextDouble();
totalFry = totalFry + fryCount * .79;
//When option = 3
if (option == 3)
double totalSoda = 0;
int sodaCount = 0;
System.out.println("Enter the number of sodas you want ");
sodaCount = keyboardnext.Double();
totalSoda = totalSoda + sodaCount * 1.09;
//Imput if user wants to end order
System.out.println("Do you want to end your order? (Enter no to add more items ) ");
endOrder = keyboard.next();
//Call
clacTotal();
printReceipt();
//Ask user if they want to end the program
System.out.println("Do you want to end the program? (Enter no to process a new order) ");
endProgram = keyboard.next();
}
//Calculate the total amount
public static void calcTotal() {
double total = 0;
double tax = 0;
double subtotal = 0;
//Add statements to calc total with tax and call printReceipt
calcTotal = totalBurger + totalFry + totalSoda * .06;
}
public static void printReceipt() {
//Add statements to display the total as shown above
System.out.println("Your total is $" + calcTotal);
}
}
Your code has many issues including the following:
missing curly braces on beginning and end of if's and loops
creating duplicate variables.
using keyboard.nextDouble() on ints
plus some spelling mistakes.
The following code should at least compile and work as you wanted.
import java.util.Scanner;
public class Lab4_5 {
static Scanner keyboard = new Scanner(System.in);
// Declare local variables
static double totalBurger, totalFry, totalSoda, calcTotal;
static int option, burgerCount, fryCount, sodaCount;
// The main method
public static void main(String[] args) {
//Add a loop to run program again
String endProgram = "no";
while (endProgram.equals("no")){
//Add a loop to take in order
String endOrder = "no";
while (endOrder.equals("no")){
// Add statements to display the menu, get the user choice, and assign it to option
System.out.println("Enter 1 for Yum Yum Burger");
System.out.println("Enter 2 for Grease Yum Fires");
System.out.println("Enter 3 for Soda Yum");
//Add a Select Case statement based on the value of option
int option = 0;
option = keyboard.nextInt();
//When option = 1
if (option == 1){
totalBurger = 0;
burgerCount = 0;
System.out.println("Enter the number of burgers you want ");
burgerCount = keyboard.nextInt();
totalBurger = totalBurger + burgerCount * .99;
}
//When option = 2
if (option == 2){
System.out.println("Enter the number of fires you want ");
fryCount = keyboard.nextInt();
totalFry = totalFry + fryCount * .79;
}
//When option = 3
if (option == 3){
System.out.println("Enter the number of sodas you want ");
sodaCount = keyboard.nextInt();
totalSoda = totalSoda + sodaCount * 1.09;
}
//Imput if user wants to end order
System.out.println("Do you want to end your order? (Enter no to add more items ) ");
endOrder = keyboard.next();
}
calcTotal();
printReceipt();
//Ask user if they want to end the program
System.out.println("Do you want to end the program? (Enter no to process a new order) ");
endProgram = keyboard.next();
}
}
//Calculate the total amount
public static void calcTotal() {
//Add statements to calc total with tax and call printReceipt
calcTotal = totalBurger + totalFry + totalSoda * .06;
}
public static void printReceipt() {
//Add statements to display the total as shown above
System.out.println("Your total is $" + calcTotal);
}
}
im using for loops to ask user to input item to buy and calculate the price...then it will ask whether the user will continue add another item...so its a loop again...then when the user stop the purchase...then it will calculate the totalprice...so im using:
totalprice+=total;
but when the outer for loops will repeat for the second customer...the value of totalprice is still the value of purchase from first customer so it will add up...is there anyway i can revert totalprice value to 0 everytime it loop for the second customer?
this is my code for that method
public static void makeOrder() {
for (index = 0; index < date.length; index++) {
double price = 0;
int order;
char addOrder;
String resume;
System.out.print("\nCustomer" + (index + 1));
System.out.print("\nEnter your name: ");
String name = input.nextLine();
System.out.print("Enter the date of reservation(DD/MM/YY): ");
date[index] = input.nextLine();
System.out.print("Enter your type of table(Couple/Family): ");
String table = input.nextLine();
do {
System.out.println("BERKAT RESTAURANT MENU:\n\n MEALS \n1-Beef Bolognese: RM17.00\n2-Chicken Marsala: RM 13.00\n3-Spaghetti Carbonara: RM 9.00\n4-Fillet Mignon: RM12.00");
System.out.println("\nDRINKS \n5-Strawberry Fruit Punch: RM6.00 \n6-Vanilla Smoothies: RM 7.00\n7-Sky Juice: RM 3.00");
System.out.print("\nEnter your choice of meals/drink: ");
order = input.nextInt();
System.out.print("Enter the quantity: ");
int quantity = input.nextInt();
System.out.print("Do you want to add order?(Y/N): ");
addOrder = input.next().charAt(0);
double total = calculatePrice(order, quantity);
subtotal += total;
} while (addOrder != 'N');
System.out.println("");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.printf("The total price you have to pay is: RM%6.2f ", subtotal);
System.out.println("");
System.out.println("Thank you for coming to our restaurant, Please come again!");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
}// makeOrder method
i want to revert the subtotal value back to 0.00 everytime the 'for' loops back
You want to make sure that you initialize subtotal to 0 at the start of your outside for loop. This way for each customer, it is always 0, regardless of the number of items added to the order.
public static void makeOrder() {
double subtotal = 0;
for(index = 0, index < date.length; index++) {
subtotal = 0;
/* your other code here */
}
}
You should initialize subtotal to 0 at the start of your for loop.
public static void makeOrder()
{
for(index=0;index<date.length;index++)
{
double subtotal=0;
double price=0;
int order;
char addOrder;
String resume;
System.out.print("\nCustomer"+(index+1));
System.out.print("\nEnter your name: ");
String name=input.nextLine();
System.out.print("Enter the date of reservation(DD/MM/YY): ");
date[index]=input.nextLine();
System.out.print("Enter your type of table(Couple/Family): ");
String table=input.nextLine();
do{
System.out.println("BERKAT RESTAURANT MENU:\n\n MEALS \n1-Beef Bolognese: RM17.00\n2-Chicken Marsala: RM 13.00\n3-Spaghetti Carbonara: RM 9.00\n4-Fillet Mignon: RM12.00");
System.out.println("\nDRINKS \n5-Strawberry Fruit Punch: RM6.00 \n6-Vanilla Smoothies: RM 7.00\n7-Sky Juice: RM 3.00");
System.out.print("\nEnter your choice of meals/drink: ");
order=input.nextInt();
System.out.print("Enter the quantity: ");
int quantity=input.nextInt();
System.out.print("Do you want to add order?(Y/N): ");
addOrder=input.next().charAt(0);
double total=calculatePrice(order,quantity);
subtotal+=total;
}while(addOrder!='N');
System.out.println("");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.printf("The total price you have to pay is: RM%6.2f ",subtotal);
System.out.println("");
System.out.println("Thank you for coming to our restaurant, Please come again!");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
}//makeOrder method
thank you guys for your help...so i declare subtotal=0.00 and it work like a charm
public static void makeOrder()
{
for(index=0;index<date.length;index++)
{
double price=0;
double subtotal=0.00;
int order;
char addOrder;
String resume;
System.out.print("\nCustomer"+(index+1));
System.out.print("\nEnter your name: ");
String name=input.nextLine();
System.out.print("Enter the date of reservation(DD/MM/YY): ");
date[index]=input.nextLine();
System.out.print("Enter your type of table(Couple/Family): ");
String table=input.nextLine();
do{
System.out.println("BERKAT RESTAURANT MENU:\n\n MEALS \n1-Beef Bolognese: RM17.00\n2-Chicken Marsala: RM 13.00\n3-Spaghetti Carbonara: RM 9.00\n4-Fillet Mignon: RM12.00");
System.out.println("\nDRINKS \n5-Strawberry Fruit Punch: RM6.00 \n6-Vanilla Smoothies: RM 7.00\n7-Sky Juice: RM 3.00");
System.out.print("\nEnter your choice of meals/drink: ");
order=input.nextInt();
System.out.print("Enter the quantity: ");
int quantity=input.nextInt();
System.out.print("Do you want to add order?(Y/N): ");
addOrder=input.next().charAt(0);
double total=calculatePrice(order,quantity);
subtotal+=total;
}while(addOrder!='N');
System.out.println("");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.printf("The total price you have to pay is: RM%6.2f ",subtotal);
System.out.println("");
System.out.println("Thank you for coming to our restaurant, Please come again!");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
}//makeOrder method
This question already exists:
Scanner issue when using nextLine after nextXXX [duplicate]
Closed 7 years ago.
How am I able to get rid of one scanner? If I do use just one scanner the after the weekly_pay is output is:
Employee Name
Enter the hours worked for the week.
The program skips right over asking for the employee name variable. With both scanners it does indeed loop asking for the employee name as it should.
//Week 3 Assignment
package weeklypay2;
import java.util.Scanner; // importing the Java utility class scanner
public class WeeklyPay2 // class WeeklyPay
{
//main method
public static void main(String[] args)
{
Scanner Scanner = new Scanner(System.in);
Scanner Scanner1 = new Scanner(System.in);
String employee_name = null; // variable for employee name
double hours_worked = 0, // variable for weekly hours worked
pay_rate = 0, // variable for pay rate per hour
weekly_pay = 0; // weekly pay = hours * pay_rate
while (employee_name!="stop")
{
System.out.println("");
System.out.println("Employee Name"); // prompt, employees name
employee_name = Scanner1.nextLine();
if (employee_name.equalsIgnoreCase("stop"))
{
System.out.print("Exiting Program");
break;
} // ends if statement
else
{
System.out.println("Enter the hours worked for the week");
//prompt, hours worked for the current week
pay_rate = Scanner.nextDouble();
while(pay_rate < 0.01)
{
System.out.print("ERROR!!, Input a postive number: \n");
pay_rate = Scanner.nextDouble();
}
System.out.println("Enter the employees hourly pay rate");
// prompt, the employees pay rate
hours_worked = Scanner.nextDouble();
while(hours_worked < 0.01)
{
System.out.print("ERROR!!, Input a postive number: \n");
hours_worked = Scanner.nextDouble();
}
weekly_pay = (double) hours_worked * (double) pay_rate; // setting the variable weekly_pay
System.out.println(employee_name + "'s weekly pay is $" + weekly_pay ); // output the employees name and weekly pay
}
}
Scanner.close();
Scanner1.close();
} //ends main method
} //ends class WeeklyPay
Well the first thing I would say is be careful naming your scanner. Don't start that with a capital. Now a big thing is you don't want to compare strings using !=, this is not intended for string variables. There is a fun method for comparing strings that would be .equals() or .equalsIgnoreCase() depending if you want it non-case sensitive. Now after changing those few things in your code it works just fine. Also just a heads up Java also includes a method for formatting currency. You're pay numbers were missing a decimal. If you look at the NumberFormat I added after the scanner and then look at the println at the end you can see its very simple to use.
import java.text.NumberFormat;
import java.util.Scanner; // importing the Java utility class scanner
public class WeeklyPay2 // class WeeklyPay
{
//main method
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
NumberFormat format = NumberFormat.getCurrencyInstance();
String employee_name = "";
double hours_worked = 0, // variable for weekly hours worked
pay_rate = 0, // variable for pay rate per hour
weekly_pay = 0; // weekly pay = hours * pay_rate
while (!employee_name.equalsIgnoreCase("stop"))
{
System.out.println();
System.out.print("Employee Name: ");
employee_name = scanner.nextLine();
if (employee_name.equalsIgnoreCase("stop"))
{
System.out.print("Exiting Program");
break;
} // ends if statement
else
{
System.out.print("Enter the hours worked for the week: ");
//prompt, hours worked for the current week
pay_rate = scanner.nextDouble();
while(pay_rate < 0.01)
{
System.out.print("ERROR!!, Input a postive number: ");
pay_rate = scanner.nextDouble();
}
System.out.print("Enter the employees hourly pay rate: ");
// prompt, the employees pay rate
hours_worked = scanner.nextDouble();
while(hours_worked < 0.01)
{
System.out.print("ERROR!!, Input a postive number: \n");
hours_worked = scanner.nextDouble();
}
weekly_pay = (double) hours_worked * (double) pay_rate; // setting the variable weekly_pay
System.out.println(employee_name + "'s weekly pay is: " + format.format(weekly_pay)); // output the employees name and weekly pay
scanner.nextLine();
}
}
scanner.close();
} //ends main method
} //ends class WeeklyPay
And this is the output we would see:
Oh, PS: Keep the program cleaner by prompting for the input on the same line, more intuitive and better to look at. By all means add a line break after the input but not before :)
use Scanner1.nextLine() after getting the value for hours worked.
Refer modified code below:
import java.util.Scanner; // importing the Java utility class scanner
public class WeeklyPay2 // class WeeklyPay
{
//main method
public static void main(String[] args) {
Scanner Scanner1 = new Scanner(System.in);
String employee_name = null; // variable for employee name
double hours_worked = 0, // variable for weekly hours worked
pay_rate = 0, // variable for pay rate per hour
weekly_pay = 0; // weekly pay = hours * pay_rate
//Scanner1.useDelimiter("//n");
while (true) {
System.out.println("");
System.out.println("Employee Name"); // prompt, employees name
employee_name = Scanner1.nextLine();
if (employee_name.equalsIgnoreCase("stop"))
{
System.out.print("Exiting Program");
break;
}// ends if statement
else {
System.out.println("Enter the hours worked for the week");
//prompt, hours worked for the current week
pay_rate = Scanner1.nextDouble();
while (pay_rate < 0.01) {
System.out.print("ERROR!!, Input a postive number: \n");
pay_rate = Scanner1.nextDouble();
}
System.out.println("Enter the employees hourly pay rate");
// prompt, the employees pay rate
hours_worked = Scanner1.nextDouble();
while (hours_worked < 0.01) {
System.out.print("ERROR!!, Input a postive number: \n");
hours_worked = Scanner1.nextDouble();
//Scanner1.
}
Scanner1.nextLine();
weekly_pay = (double) hours_worked * (double)
pay_rate; // setting the variable weekly_pay
System.out.println(employee_name + "'s weekly pay is $" + weekly_pay); // output the employees name and weekly pay
}
}
Scanner1.close();
} //ends main method
}//ends class WeeklyPay
I am doing excercises in a book called "Java, how to program". I have created a small program with 2 classes. The program is supposed to be used by a hardware store to represent an invoice for items sold. It is supposed to includ 4 pieces of information: A string value for the items number, a string value which describes the product, an int value for the quantity of items sold, and a double value for the items price. I have created 2 objects of the class in a class which contains the main method. I am supposed to use "set and get-methods" for each instance variables.
The problem is that when the programs prompts the user to write the values of the variables, it doesn´t read the first value for the variable "second items number" (Line 5 in the copy of the command window under). I really can´t read in the code why this happens. Can anyone please help me?
The code of the two classes are as follows:
public class aInvoice
{
private String number;
private String description;
private int quantity;
private double price;
public aInvoice(String pNumber, String pDescription, int pQuantity, double pPrice)
{
number = pNumber;
description = pDescription;
if (pQuantity < 0)
{quantity = 0;}
else
{quantity = pQuantity;}
if (pPrice < 0)
{price = 0;}
else
{price = pPrice;}
}
public String getNumber()
{
return number;
}
public String getDescription()
{
return description;
}
public int getQuantity()
{
return quantity;
}
public double getPrice()
{
return price;
}
double totalAmount;
public double getaInvoiceTotalAmount()
{
return quantity * price;
}
}
and:
import java.util.Scanner;
public class aInvoiceTest
{
public static void main(String[]args)
{
String partNumber1 = null;
String partDescription1 = null;
int partQuantity1 = 0;
double partPrice1 = 0.0;
String partNumber2 = null;
String partDescription2 = null;
int partQuantity2 = 0;
double partPrice2 = 0.0;
Scanner input = new Scanner (System.in);
System.out.print( "Enter first items number: ");
partNumber1 = input.nextLine();
System.out.print( "Enter description: ");
partDescription1 = input.nextLine();
System.out.print( "Enter quantity: ");
partQuantity1 = input.nextInt();
System.out.print( "Enter price: $");
partPrice1 = input.nextDouble();
System.out.print( "Enter second items number: ");
partNumber2 = input.nextLine();
System.out.print( "Enter description: ");
partDescription2 = input.nextLine();
System.out.print( "Enter quantity: ");
partQuantity2 = input.nextInt();
System.out.print( "Enter price: $");
partPrice2 = input.nextDouble();
aInvoice aInvoice1 = new aInvoice(partNumber1, partDescription1, partQuantity1, partPrice1);
aInvoice aInvoice2 = new aInvoice(partNumber2, partDescription2, partQuantity2, partPrice2);
System.out.printf( "\n\nPart 1´s item number: %s\nItem description: %s\nQuantity: %d\nPrice each: $ %.2f\n\n", aInvoice1.getNumber(), aInvoice1.getDescription(), aInvoice1.getQuantity(), aInvoice1.getPrice () );
System.out.printf( "\n\nPart 2´s item number: %s\nItem description: %s\nQuantity: %d\nPrice each: $ %.2f\n\n", aInvoice2.getNumber(), aInvoice2.getDescription(), aInvoice2.getQuantity(), aInvoice2.getPrice () );
System.out.printf( "Total amount: $ %.2f\n\n", (aInvoice1.getaInvoiceTotalAmount() + aInvoice2.getaInvoiceTotalAmount()));
}
}
THe reading in the command window is:
Enter first items number: 44
Enter description: pc
Enter quantity: 1
Enter price: $10
Enter second items number: Enter description: phone
Enter quantity: 1
Enter price: $100
Part 1´s item number: 44
Item description: pc
Quantity: 1
Price each: $ 10.00
Part 2´s item number:
Item description: phone
Quantity: 1
Price each: $ 100.00
Total amount: $ 110.00
This is because after you read input using input.nextInt() or input.nextDouble() you need to clear the buffer before trying to read in another string.
When the user types in 5.0 the 5.0 is taken from the input buffer but the carriage return is left. You can put a input.nextLine() and this will clear that carriage return for you.
so your code should look like
System.out.print( "Enter price: $");
partPrice1 = input.nextDouble();
input.nextLine();
System.out.print( "Enter second items number: ");
partNumber2 = input.nextLine();
System.out.print( "Enter description: ");
partDescription2 = input.nextLine();
System.out.print( "Enter quantity: ");
partQuantity2 = input.nextInt();
System.out.print( "Enter price: $");
partPrice2 = input.nextDouble();
Basically, the problem is that when you call nextInt/nextDouble, those functions only grab the number part of what is actually present in your input stream. They don't read the enter character that hitting the "enter" key put there. Just put a input.nextLine(); after every input.nextInt(), etc.
This appears to be the problem you are seeing: Using scanner.nextLine()