Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:54:16+00:00 2026-06-03T01:54:16+00:00

I am writing a photo program that accepts the users internet speed and width

  • 0

I am writing a photo program that accepts the users internet speed and width and height of a photo. The program then displays the cost, storage size, and time to transfer. I split the program into two parts, one which sets the values and a class that has all the methods.

The main problem I am having with my program is adding up all the values of all the photos entered and showing the price, storage, and time at the end.

So far, I have a addTotal() method that adds the time, price, and storage to the values I have set. What keeps happening though is that the values for the last photo entered keeps displaying instead of the total for all photos.

For example:
If the internet speed is set to 150,000, and there are two photos with sizes 4,5 and 4.5,4.5, what is suppose to display at the end is:

Total cost = $4.83

4.14 Mbytes of storage

3 minutes, 40 seconds to transfer

Any help is appreciated.

Here is the main program:

import javax.swing.JOptionPane;
{
public static void main(String args[])
{
double speed;
double height;
double width;
double compression = 3.5;
double resolution = 600;

System.out.println("Welcome to the Scans-R-Us Digital Photo Shop!");
String userInput = JOptionPane.showInputDialog("Do you have a photo you would like us to scan(Yes or No)?");

while((!userInput.equals("Yes") && (!userInput.equals("YES")) && (!userInput.equals("yes"))))   
    {
    System.out.println("test");
    System.exit(0);
    }
    do  
    {
    String internetString = JOptionPane.showInputDialog("What is your internet speed in bits/second?");
    speed = Double.parseDouble(internetString);
    }
    while(speed < 0);

while((userInput.compareTo("No") != 0) && (userInput.compareTo("NO") != 0) && (userInput.compareTo("no") != 0))
    {
    DigitalPhoto one = new DigitalPhoto();

    do
    {
    String heightString = JOptionPane.showInputDialog("What is the height of the photo?");
    height = Double.parseDouble(heightString);
    }
    while(height >=8);

    do
    {
    String widthString = JOptionPane.showInputDialog("What is the width of the photo?");
    width = Double.parseDouble(widthString);
    }
    while(width >= 8);

    one.setWidth(width);
    one.setHeight(height);
    one.setSpeed(speed);
    one.setCompression(compression);
    one.setResolution(resolution);
    one.setPrice();
    one.setStorage();
    one.setTime();
    one.showValues();
    one.addTotal(); 

    userInput = JOptionPane.showInputDialog("Do you have a photo you would like us to scan(Yes or No)?");

    while((!userInput.equals("Yes") && (!userInput.equals("YES")) && (!userInput.equals("yes"))))
    {
    one.endValues();
    System.out.println("\nThanks, have a nice day!");
    System.exit(0);
    }
 }  
}
}

And here is the class I am using to run the program:

import javax.swing.JOptionPane;
{   
double total;
double width;
double height;
double speed;
double compression;
double resolution; 
double price;
double time;
double totalPrice;
double totalStorage;
double totalTime;
double pricePerInch = .12;
int bytes = 8;
int megaSize = 1000000;

DigitalPhoto()
{
width = 0.0;
height = 0.0; 
speed = 0.0;
compression = 0.0;
resolution = 0.0;
total = 0.0;
price = 0.0;
time = 0.0;
}

public void setWidth(double thisWidth)
{
width = thisWidth;
}

public void setHeight(double thisHeight)
{
height = thisHeight;
}

public void setSpeed(double thisSpeed)
{
speed = thisSpeed;
}

public void setCompression(double thisCompression)
{
compression = thisCompression;
}

public void setResolution(double thisResolution)
{
resolution = thisResolution;
}

public double getWidth()
{
return width;
}

public double getHeight()
{
return height;
}

public double getSpeed()
{
return speed;
}

public double getCompression()
{
return compression;
}

public double getResolution()
{
return resolution;
}

public double setStorage()
{
width = width * resolution;
height = height * resolution;
total = width * height;
total = total / compression;
total = total / megaSize;
return total;
}

public double setPrice()
{
price = height * width;
price = price * pricePerInch;
return price;
}

public double setTime()
{
total = total * megaSize;
time = total * bytes;
time = time / speed;
total = total / megaSize;
return time;
}

public void showValues()
{
System.out.println("\nScanned photo details: ");
System.out.println("Resolution: " + resolution);
System.out.println("Compression ratio: " + compression);
System.out.println("The customer photos require " + total + " Mbytes of storage.");
System.out.println("The customer photos cost $" + price);
System.out.println("It will take " + (int)time / 60 + " minutes and " + (int)time % 60 + " seconds");
}

public void addTotal()
{
totalTime = totalTime + time;
totalPrice = totalPrice + price;
totalStorage = totalStorage + total;
}

public void endValues()
{
System.out.println("\nThe  photos require " + totalStorage + " Mbytes of storage.");
System.out.println("The  photos cost $" + totalPrice);
System.out.println("It will take " + (int)totalTime / 60 + " minutes and " + (int)totalTime % 60 + " seconds");
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:54:17+00:00Added an answer on June 3, 2026 at 1:54 am

    You are creating a new object every time you enter the loop, so you only keep the last one. You need to create the object before the loop:

    DigitalPhoto one = new DigitalPhoto();
    while((userInput.compareTo("No") != 0) && (userInput.compareTo("NO") != 0) &&
       (userInput.compareTo("no") != 0)) {
      //...
      one.setPrice();
      //...
      one.addTotal();
    }
    

    Then query the result after the loop ends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an app that involves taking a photo, and then saving the URI
I'm writing a program for iPhone that will first let the user take a
I'm writing a program that uses FileSystemWatcher to monitor changes to a given directory,
I am writing an application where users are required to show their photo, however
Writing a simple program that will find exact duplicate files on my computer, but
I am writing a program that has to copy a sizeable, but not huge
I'm writing an application that uses UIImagePickerController. I'd like to give users choice of
In the iOS app I'm writing, we have an add photo button that's pretty
I'm writing an application that uploads a photo to facebook. I'm not supplying an
I am writing an application that displays a thumbnail from a server in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.