Related questions
How do I fix the errors?
Code:
import java.util.Scanner;
public class ReceiptMaker {
public static final String SENTINEL = "checkout";
public final int MAX_NUM_ITEMS;
public final double TAX_RATE;
private String[] itemNames;
private double[] itemPrices;
private int numItemsPurchased;
public ReceiptMaker() {
MAX_NUM_ITEMS = 10;
TAX_RATE = 0.0875;
itemNames = new String[MAX_NUM_ITEMS];
itemPrices = new double[MAX_NUM_ITEMS];
numItemsPurchased = 0;
}
public ReceiptMaker(int maxNumItems, double taxRate) {
MAX_NUM_ITEMS = maxNumItems;
TAX_RATE = taxRate;
itemNames = new String[MAX_NUM_ITEMS];
itemPrices = new double[MAX_NUM_ITEMS];
numItemsPurchased = 0;
}
public void greetUser() {
System.out.println("Welcome to the " + MAX_NUM_ITEMS + " items or less checkout line");
}
public void promptUserForProductEntry() {
System.out.println("Enter item #" + (numItemsPurchased + 1) + "'s name and price separated by a space, or enter \"checkout\" to end transaction early");
}
public void addNextPurchaseItemFromUser(String itemName, double itemPrice) {
itemNames[numItemsPurchased] = itemName;
itemPrices[numItemsPurchased] = itemPrice;
numItemsPurchased++;
}
public double getSubtotal() {
double subTotal = 0;
for (int i = 0; i < numItemsPurchased; i++) {
subTotal += itemPrices[i];
}
return subTotal;
}
public double getMinPrice() {
double minPrice = itemPrices[0];
for (int i = 1; i < numItemsPurchased; i++) {
if (itemPrices[i] < minPrice) {
minPrice = itemPrices[i];
}
}
return minPrice;
}
public int getIndexOfMinPrice() {
int indexOfMin = 0;
for (int i = 1; i < numItemsPurchased; i++) {
if (itemPrices[i] < itemPrices[indexOfMin]) {
indexOfMin = i;
}
}
return indexOfMin;
}
public double getMaxPrice() {
double maxPrice = (numItemsPurchased > 0) ? Integer.MIN_VALUE : 0;
for (int i = 0; i < numItemsPurchased; i++) {
if (itemPrices[i] > maxPrice) {
maxPrice = itemPrices[i];
}
}
return maxPrice;
}
public int getIndexOfMaxPrice() {
int indexOfMax = 0;
for (int i = 1; i < numItemsPurchased; i++) {
if (itemPrices[i] > itemPrices[indexOfMax]) {
indexOfMax = i;
}
}
return indexOfMax;
}
public double getMeanPrice() {
if (numItemsPurchased > 0) {
return getSubtotal() / numItemsPurchased;
}
return 0;
}
public double getTaxOnSubtotal() {
return getSubtotal() * TAX_RATE;
}
public double getTotal() {
return getSubtotal() + getTaxOnSubtotal();
}
public void displayReceipt() {
System.out.println("-------------------------------------------------");
System.out.printf("Subtotal: $ %04.2f | # of Items %02d\n", getSubtotal(), numItemsPurchased);
System.out.printf(" Tax: $ %05.2f \n", getTaxOnSubtotal());
System.out.printf(" Total: $ %04.2f \n", getTotal());
System.out.println("--------------------THANK YOU--------------------");
}
public void displayReceiptStats() {
System.out.println("\n-----------------RECEIPT STATS-----------------");
System.out.printf("Min Item Name: %10s | Price: $ %04.2f\n", itemNames[getIndexOfMinPrice()], getMinPrice());
System.out.printf("Max Item Name: %10s | Price: $ %04.2f\n", itemNames[getIndexOfMaxPrice()], getMaxPrice());
System.out.printf("Mean price of %02d items purchased: $ %04.2f\n\n", numItemsPurchased, getMeanPrice());
}
public void displayAllItemsWithPrices() {
System.out.println("\n---------------RECEIPT BREAKDOWN---------------");
for (int i = 0; i < numItemsPurchased; i++) {
System.out.printf("Item #%02d Name: %10s | Price: $ %04.2f\n", (i + 1), itemNames[i], itemPrices[i]);
}
}
private double getItemPriceFromUser(Scanner scanner) {
double price = -1;
while ((price = scanner.nextDouble()) < 0) {
System.out.println("Price \"" + price + "\" cannot be negative.\nReenter price");
}
return price;
}
public void scanCartItems(Scanner scanner) {
while (numItemsPurchased < MAX_NUM_ITEMS) {
promptUserForProductEntry();
String token1;
double token2 = -1;
if (!(token1 = scanner.next()).equalsIgnoreCase(SENTINEL)) {
token2 = getItemPriceFromUser(scanner);
addNextPurchaseItemFromUser(token1, token2);
} else {
break;
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ReceiptMaker rm = new ReceiptMaker();
rm.greetUser();
rm.scanCartItems(scanner);
rm.displayReceipt();
rm.displayReceiptStats();
rm.displayAllItemsWithPrices();
scanner.close();
}
}
Errors:
-java:17: error: cannot access Movie Movie m = null;
-java:15: error: cannot access Movie Movie m = null;
-java:29: error: cannot access Movie Movie m1 = null;
-java:26: error: cannot access Movie Movie m1 = null;
-java:16: error: cannot access Movie field = Movie.class.getDeclaredField(str);
- java:13: error: cannot access Movie constructor = Movie.class.getConstructor();
-java:13: error: cannot access Movie constructor = Movie.class.getConstructor(String.class, int.class, boolean.class,
String[].class);
- java:12: error: cannot access Movie Method methodGetNumMinutes = Movie.class.getMethod("getNumMinutes");
-java:12: error: cannot access Movie Method methodSetNumMinutes = Movie.class.getMethod("setNumMinutes", int.class);
- java:12: error: cannot access Movie Method replaceCastMember = Movie.class.getMethod("replaceCastMember", int.class, String.class);
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images
- import java.util.Scanner;/** This program computes the time required to double an investment with an annual contribution.*/public class DoubleInvestment{ public static void main(String[] args) { final double RATE = 5; final double INITIAL_BALANCE = 10000; final double TARGET = 2 * INITIAL_BALANCE; Scanner in = new Scanner(System.in); System.out.print("Annual contribution: "); double contribution = in.nextDouble(); double balance = INITIAL_BALANCE; int year = 0; // TODO: Add annual contribution, but not in year 0 do { year++; double interest = balance*(RATE/100); balance = (balance+contribution+interest); } while(balance< TARGET); System.out.println("Year: " + year); System.out.printf("Balance: %.2f%n", balance); }}arrow_forwardSee ERROR in Java file 2: Java file 1: import java.util.Random;import java.util.Scanner; public class Account {// Declare the variablesprivate String customerName;private String accountNumber;private double balance;private int type;private static int numObjects;// constructorpublic Account(String customerName, double balance, int type) { this.customerName = customerName;this.balance = balance;this.type = type;setaccountNumber(); // set account number functionnumObjects += 1;}private void setaccountNumber() // definition of set account number{Random rand = new Random();accountNumber = customerName.substring(0, 3).toUpperCase();accountNumber += type;accountNumber += "#";accountNumber += (rand.nextInt(100) + 100);}// function to makedepositvoid makeDeposit(double amount){if (amount > 0){balance += amount;}}// function for withdrawboolean makeWithdrawal(double amount) {if (amount < balance)balance -= amount;elsereturn false;return true;}public String toString(){return accountNumber +...arrow_forwardFix all logic and syntax errors. Results Circle statistics area is 498.75924968391547 diameter is 25.2 // Some circle statistics public class DebugFour2 { public static void main(String args[]) { double radius = 12.6; System.out.println("Circle statistics"); double area = java.Math.PI * radius * radius; System.out.println("area is " + area); double diameter = 2 - radius; System.out.println("diameter is + diameter); } }arrow_forward
- Fix all the errors and send the code please // Application looks up home price // for different floor plans // allows upper or lowercase data entry import java.util.*; public class DebugEight3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String entry; char[] floorPlans = {'A','B','C','a','b','c'} int[] pricesInThousands = {145, 190, 235}; char plan; int x, fp = 99; String prompt = "Please select a floor plan\n" + "Our floorPlanss are:\n" + "A - Augusta, a ranch\n" + "B - Brittany, a split level\n" + "C - Colonial, a two-story\n" + "Enter floorPlans letter"; System.out.println(prompt); entry = input.next(); plan = entry.charAt(1); for(x = 0; x < floorPlans.length; ++x) if(plan == floorPlans[x]) x = fp; if(fp = 99) System.out.println("Invalid floor plan code entered")); else { if(fp...arrow_forwardJAVA CODE: check outputarrow_forwardimport java.util.*; class Money { private int dollar; private int cent; final static int MIN_CENT_VALUE = 0; final static int MAX_CENT_VALUE = 99; public Money() { this.dollar = 0; this.cent = 0; } public Money(int dollar, int cent) { this.dollar = dollar; if (cent > MIN_CENT_VALUE && cent <= MAX_CENT_VALUE) { this.cent = cent; } else { cent = 0; } } public int getDollar() { return this.dollar; } public void setDollar(int dol) { this.dollar = dol; } public int getCent() { return this.cent; } public void setCent(int c) { if (c >= MIN_CENT_VALUE && c <= MAX_CENT_VALUE) { this.cent = c; } } public Money add(Money otherMoney) { Money m = new Money(); m.dollar = this.dollar + otherMoney.dollar; m.cent = this.cent + otherMoney.cent; if (m.cent >= 100) {...arrow_forward
- public class Side Plot { * public static String PLOT_CHAR = "*"; public static void main(String[] args) { plotxSquared (-6,6); * plotNegXSquaredPlus20 (-5,5); plotAbsXplus1 (-4,4); plotSinWave (-9,9); public static void plotXSquared (int minX, int maxx) { System.out.println("Sideways Plot"); System.out.println("y = x*x where + minX + "= minX; row--) { for (int col = 0; col row * row; col++) { System.out.print (PLOT_CHAR); if (row== 0){ } System.out.print(" "); } for(int i = 0; i <= maxx* maxX; i++) { System.out.print("-"); } System.out.println(); Sideways PHOT y = x*x where -6<=x<=6 Sideways Plot y = x*x where -6<=x<=6 How do I fix my code to get a plot like 3rd picture?arrow_forwardcorrect the codearrow_forwardusing System;public static class Lab3_2{public static void Main(){// declare the variables and constantsconst double FLAT = 1.25;double weight;double cost, pricePerKg = 0;// Input the weightConsole.Write("Enter a positive weight of the package => ");weight = Convert.ToDouble(Console.ReadLine());// Determine the cost per kilogramif (weight <= 0)Console.WriteLine("*** Invalid weight");else if (weight < 1)pricePerKg = 0.25;else if (weight <= 3.5)pricePerKg = 0.5;else (weight > 3.5)pricePerKg = 1.0;// Compute the cost to send the packageif (weight > 0)cost = weight * pricePerKg + FLAT;elsecost = 0;// Output the resultsConsole.WriteLine("The cost to send the package is {0:C}",cost);Console.ReadLine();}} Remove the error from the given program and run it for input weight 2.5.arrow_forward
- Find the error(s) in the following class definition: public class Circle private double radius; public double setRadius(double a) { radius = a; public void getRadius() { return radius;arrow_forwardpublic class Animal { public static int population; private int age; } public Animal (int age) { this.age = age; population++; } + msg); public void say (String msg) { System.out.print("Saying: " System.out.print(" for "); System.out.print(getHuman Years()); System.out.println(" years."); } public int getHuman Years() { return age; } public class Mammal extends Animal { private String species; public Mammal(String species, int age) { super (age); this. species species; } } } = public int getHuman Years() { if (species.equals("dog")) 1 else return super.getHumanYears() * 7; return super.getHumanYears(); €arrow_forwardFind the error(s) in the following code snippet and explain how to correct it (them): 1 class Example { 2 public: Example(int y = 3 10) : data (y) {} 4 int getIncrementedData() const { return ++data; 7 } 8. 9 private: 10 int data; 11 };arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education